summaryrefslogtreecommitdiffstats
path: root/webapp/stores/search_store.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/stores/search_store.jsx')
-rw-r--r--webapp/stores/search_store.jsx33
1 files changed, 32 insertions, 1 deletions
diff --git a/webapp/stores/search_store.jsx b/webapp/stores/search_store.jsx
index 49f8b3c2f..62cc5635b 100644
--- a/webapp/stores/search_store.jsx
+++ b/webapp/stores/search_store.jsx
@@ -1,10 +1,12 @@
-// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import EventEmitter from 'events';
import Constants from 'utils/constants.jsx';
+import ChannelStore from 'stores/channel_store.jsx';
+
var ActionTypes = Constants.ActionTypes;
var CHANGE_EVENT = 'change';
@@ -117,6 +119,20 @@ class SearchStoreClass extends EventEmitter {
});
}
}
+
+ togglePinPost(postId, isPinned) {
+ const results = this.getSearchResults();
+ if (results == null) {
+ return;
+ }
+
+ if (postId in results.posts) {
+ const post = results.posts[postId];
+ results.posts[postId] = Object.assign({}, post, {
+ is_pinned: isPinned
+ });
+ }
+ }
}
var SearchStore = new SearchStoreClass();
@@ -126,6 +142,13 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
switch (action.type) {
case ActionTypes.RECEIVED_SEARCH:
+ if (SearchStore.getIsPinnedPosts() === action.is_pinned_posts &&
+ action.is_pinned_posts === true &&
+ SearchStore.getSearchResults().posts &&
+ ChannelStore.getCurrentId() !== Object.values(SearchStore.getSearchResults().posts)[0].channel_id) {
+ // ignore pin posts update after switch to a new channel
+ return;
+ }
SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts, action.is_pinned_posts);
SearchStore.emitSearchChange();
break;
@@ -140,6 +163,14 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
SearchStore.deletePost(action.post);
SearchStore.emitSearchChange();
break;
+ case ActionTypes.RECEIVED_POST_PINNED:
+ SearchStore.togglePinPost(action.reaction, true);
+ SearchStore.emitSearchChange();
+ break;
+ case ActionTypes.RECEIVED_POST_UNPINNED:
+ SearchStore.togglePinPost(action.reaction, false);
+ SearchStore.emitSearchChange();
+ break;
default:
}
});