diff options
Diffstat (limited to 'webapp/stores')
-rw-r--r-- | webapp/stores/browser_store.jsx | 10 | ||||
-rw-r--r-- | webapp/stores/error_store.jsx | 1 | ||||
-rw-r--r-- | webapp/stores/file_store.jsx | 4 | ||||
-rw-r--r-- | webapp/stores/integration_store.jsx | 134 | ||||
-rw-r--r-- | webapp/stores/notification_store.jsx (renamed from webapp/stores/notificaiton_store.jsx) | 2 | ||||
-rw-r--r-- | webapp/stores/post_store.jsx | 12 | ||||
-rw-r--r-- | webapp/stores/search_store.jsx | 2 |
7 files changed, 146 insertions, 19 deletions
diff --git a/webapp/stores/browser_store.jsx b/webapp/stores/browser_store.jsx index bba146e38..d605aac80 100644 --- a/webapp/stores/browser_store.jsx +++ b/webapp/stores/browser_store.jsx @@ -8,7 +8,7 @@ function getPrefix() { return global.window.mm_current_user_id + '_'; } - console.log('BrowserStore tried to operate without user present'); //eslint-disable-line no-console + console.warn('BrowserStore tried to operate without user present'); //eslint-disable-line no-console return 'unknown_'; } @@ -144,18 +144,14 @@ class BrowserStoreClass { * Signature for action is action(key, value) */ actionOnGlobalItemsWithPrefix(prefix, action) { - var globalPrefix = getPrefix(); - var globalPrefixiLen = globalPrefix.length; - var storage = sessionStorage; if (this.isLocalStorageSupported()) { storage = localStorage; } for (var key in storage) { - if (key.lastIndexOf(globalPrefix + prefix, 0) === 0) { - var userkey = key.substring(globalPrefixiLen); - action(userkey, this.getGlobalItem(key)); + if (key.lastIndexOf(prefix, 0) === 0) { + action(key, this.getGlobalItem(key)); } } } diff --git a/webapp/stores/error_store.jsx b/webapp/stores/error_store.jsx index 7c695a335..715029185 100644 --- a/webapp/stores/error_store.jsx +++ b/webapp/stores/error_store.jsx @@ -59,6 +59,7 @@ class ErrorStoreClass extends EventEmitter { clearLastError() { BrowserStore.removeGlobalItem('last_error'); BrowserStore.removeGlobalItem('last_error_conn'); + this.emitChange(); } } diff --git a/webapp/stores/file_store.jsx b/webapp/stores/file_store.jsx index 2628685cc..2692e6959 100644 --- a/webapp/stores/file_store.jsx +++ b/webapp/stores/file_store.jsx @@ -13,10 +13,6 @@ class FileStore extends EventEmitter { constructor() { super(); - this.addChangeListener = this.addChangeListener.bind(this); - this.removeChangeListener = this.removeChangeListener.bind(this); - this.emitChange = this.emitChange.bind(this); - this.handleEventPayload = this.handleEventPayload.bind(this); this.dispatchToken = AppDispatcher.register(this.handleEventPayload); diff --git a/webapp/stores/integration_store.jsx b/webapp/stores/integration_store.jsx new file mode 100644 index 000000000..abd7e3558 --- /dev/null +++ b/webapp/stores/integration_store.jsx @@ -0,0 +1,134 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; +import Constants from 'utils/constants.jsx'; +import EventEmitter from 'events'; + +const ActionTypes = Constants.ActionTypes; + +const CHANGE_EVENT = 'changed'; + +class IntegrationStore extends EventEmitter { + constructor() { + super(); + + this.dispatchToken = AppDispatcher.register(this.handleEventPayload.bind(this)); + + this.incomingWebhooks = []; + this.receivedIncomingWebhooks = false; + + this.outgoingWebhooks = []; + this.receivedOutgoingWebhooks = false; + } + + addChangeListener(callback) { + this.on(CHANGE_EVENT, callback); + } + + removeChangeListener(callback) { + this.removeListener(CHANGE_EVENT, callback); + } + + emitChange() { + this.emit(CHANGE_EVENT); + } + + hasReceivedIncomingWebhooks() { + return this.receivedIncomingWebhooks; + } + + getIncomingWebhooks() { + return this.incomingWebhooks; + } + + setIncomingWebhooks(incomingWebhooks) { + this.incomingWebhooks = incomingWebhooks; + this.receivedIncomingWebhooks = true; + } + + addIncomingWebhook(incomingWebhook) { + this.incomingWebhooks.push(incomingWebhook); + } + + removeIncomingWebhook(id) { + for (let i = 0; i < this.incomingWebhooks.length; i++) { + if (this.incomingWebhooks[i].id === id) { + this.incomingWebhooks.splice(i, 1); + break; + } + } + } + + hasReceivedOutgoingWebhooks() { + return this.receivedIncomingWebhooks; + } + + getOutgoingWebhooks() { + return this.outgoingWebhooks; + } + + setOutgoingWebhooks(outgoingWebhooks) { + this.outgoingWebhooks = outgoingWebhooks; + this.receivedOutgoingWebhooks = true; + } + + addOutgoingWebhook(outgoingWebhook) { + this.outgoingWebhooks.push(outgoingWebhook); + } + + updateOutgoingWebhook(outgoingWebhook) { + for (let i = 0; i < this.outgoingWebhooks.length; i++) { + if (this.outgoingWebhooks[i].id === outgoingWebhook.id) { + this.outgoingWebhooks[i] = outgoingWebhook; + break; + } + } + } + + removeOutgoingWebhook(id) { + for (let i = 0; i < this.outgoingWebhooks.length; i++) { + if (this.outgoingWebhooks[i].id === id) { + this.outgoingWebhooks.splice(i, 1); + break; + } + } + } + + handleEventPayload(payload) { + const action = payload.action; + + switch (action.type) { + case ActionTypes.RECEIVED_INCOMING_WEBHOOKS: + this.setIncomingWebhooks(action.incomingWebhooks); + this.emitChange(); + break; + case ActionTypes.RECEIVED_INCOMING_WEBHOOK: + this.addIncomingWebhook(action.incomingWebhook); + this.emitChange(); + break; + case ActionTypes.REMOVED_INCOMING_WEBHOOK: + this.removeIncomingWebhook(action.id); + this.emitChange(); + break; + case ActionTypes.RECEIVED_OUTGOING_WEBHOOKS: + this.setOutgoingWebhooks(action.outgoingWebhooks); + this.emitChange(); + break; + case ActionTypes.RECEIVED_OUTGOING_WEBHOOK: + this.addOutgoingWebhook(action.outgoingWebhook); + this.emitChange(); + break; + case ActionTypes.UPDATED_OUTGOING_WEBHOOK: + this.updateOutgoingWebhook(action.outgoingWebhook); + this.emitChange(); + break; + case ActionTypes.REMOVED_OUTGOING_WEBHOOK: + this.removeOutgoingWebhook(action.id); + this.emitChange(); + break; + } + } +} + +export default new IntegrationStore(); diff --git a/webapp/stores/notificaiton_store.jsx b/webapp/stores/notification_store.jsx index 70caffeb6..6722af281 100644 --- a/webapp/stores/notificaiton_store.jsx +++ b/webapp/stores/notification_store.jsx @@ -89,7 +89,7 @@ NotificationStore.dispatchToken = AppDispatcher.register((payload) => { switch (action.type) { case ActionTypes.RECEIVED_POST: - NotificationStore.handleRecievedPost(action.post, action.webspcketMessageProps); + NotificationStore.handleRecievedPost(action.post, action.websocketMessageProps); NotificationStore.emitChange(); break; } diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 903085760..3f2f75796 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -96,7 +96,7 @@ class PostStoreClass extends EventEmitter { let post = null; if (posts.posts.hasOwnProperty(postId)) { - post = Object.assign({}, posts.posts[postId]); + post = posts.posts[postId]; } return post; @@ -104,7 +104,7 @@ class PostStoreClass extends EventEmitter { getAllPosts(id) { if (this.postsInfo.hasOwnProperty(id)) { - return Object.assign({}, this.postsInfo[id].postList); + return this.postsInfo[id].postList; } return null; @@ -406,7 +406,7 @@ class PostStoreClass extends EventEmitter { let posts; let pendingPosts; for (const k in this.postsInfo) { - if (this.postsInfo[k].postList.posts.hasOwnProperty(this.selectedPostId)) { + if (this.postsInfo[k].postList && this.postsInfo[k].postList.posts.hasOwnProperty(this.selectedPostId)) { posts = this.postsInfo[k].postList.posts; if (this.postsInfo[k].pendingPosts != null) { pendingPosts = this.postsInfo[k].pendingPosts.posts; @@ -495,7 +495,7 @@ class PostStoreClass extends EventEmitter { BrowserStore.actionOnGlobalItemsWithPrefix('draft_', (key, value) => { if (value) { value.uploadsInProgress = []; - BrowserStore.setItem(key, value); + BrowserStore.setGlobalItem(key, value); } }); } @@ -503,7 +503,7 @@ class PostStoreClass extends EventEmitter { BrowserStore.actionOnGlobalItemsWithPrefix('comment_draft_', (key, value) => { if (value) { value.uploadsInProgress = []; - BrowserStore.setItem(key, value); + BrowserStore.setGlobalItem(key, value); } }); } @@ -531,8 +531,8 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => { switch (action.type) { case ActionTypes.RECEIVED_POSTS: { const id = PostStore.currentFocusedPostId == null ? action.id : PostStore.currentFocusedPostId; - PostStore.checkBounds(id, action.numRequested, makePostListNonNull(action.post_list), action.before); PostStore.storePosts(id, makePostListNonNull(action.post_list)); + PostStore.checkBounds(id, action.numRequested, makePostListNonNull(action.post_list), action.before); PostStore.emitChange(); break; } diff --git a/webapp/stores/search_store.jsx b/webapp/stores/search_store.jsx index acaa9e52f..dc08ca3a6 100644 --- a/webapp/stores/search_store.jsx +++ b/webapp/stores/search_store.jsx @@ -16,7 +16,7 @@ class SearchStoreClass extends EventEmitter { constructor() { super(); - this.searchResults = {}; + this.searchResults = null; this.isMentionSearch = false; this.searchTerm = ''; } |