summaryrefslogtreecommitdiffstats
path: root/webapp/stores
diff options
context:
space:
mode:
authorGabin Aureche <gabin.aureche@live.fr>2017-03-13 13:25:08 +0100
committerGeorge Goldberg <george@gberg.me>2017-03-13 12:25:08 +0000
commitfe38d6d5bb36e18ddefbe490cc21f48f4f4c8d81 (patch)
treeb96d457cde64b7397f91028106e93a7f92a179bd /webapp/stores
parent482a0fb5fc248b1ec61db35299dc3e6d963ad5ab (diff)
downloadchat-fe38d6d5bb36e18ddefbe490cc21f48f4f4c8d81.tar.gz
chat-fe38d6d5bb36e18ddefbe490cc21f48f4f4c8d81.tar.bz2
chat-fe38d6d5bb36e18ddefbe490cc21f48f4f4c8d81.zip
Add pinned posts (#4217)
Diffstat (limited to 'webapp/stores')
-rw-r--r--webapp/stores/post_store.jsx57
-rw-r--r--webapp/stores/search_store.jsx10
2 files changed, 55 insertions, 12 deletions
diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx
index 6e312f67a..6f81619c2 100644
--- a/webapp/stores/post_store.jsx
+++ b/webapp/stores/post_store.jsx
@@ -16,6 +16,7 @@ const FOCUSED_POST_CHANGE = 'focused_post_change';
const EDIT_POST_EVENT = 'edit_post';
const POSTS_VIEW_JUMP_EVENT = 'post_list_jump';
const SELECTED_POST_CHANGE_EVENT = 'selected_post_change';
+const POST_PINNED_CHANGE_EVENT = 'post_pinned_change';
class PostStoreClass extends EventEmitter {
constructor() {
@@ -259,22 +260,42 @@ class PostStoreClass extends EventEmitter {
this.postsInfo[id].postList = combinedPosts;
}
+ focusedPostListHasPost(id) {
+ const focusedPostId = this.getFocusedPostId();
+ if (focusedPostId == null) {
+ return false;
+ }
+
+ const focusedPostList = makePostListNonNull(this.getAllPosts(focusedPostId));
+ return focusedPostList.posts.hasOwnProperty(id);
+ }
+
storePost(post, isNewPost = false) {
- const postList = makePostListNonNull(this.getAllPosts(post.channel_id));
+ const ids = [
+ post.channel_id
+ ];
- if (post.pending_post_id !== '') {
- this.removePendingPost(post.channel_id, post.pending_post_id);
+ // update the post in the permalink view if it's there
+ if (!isNewPost && this.focusedPostListHasPost(post.id)) {
+ ids.push(this.getFocusedPostId());
}
- post.pending_post_id = '';
+ ids.forEach((id) => {
+ const postList = makePostListNonNull(this.getAllPosts(id));
+ if (post.pending_post_id !== '') {
+ this.removePendingPost(post.channel_id, post.pending_post_id);
+ }
- postList.posts[post.id] = post;
- if (isNewPost && postList.order.indexOf(post.id) === -1) {
- postList.order.unshift(post.id);
- }
+ post.pending_post_id = '';
+
+ postList.posts[post.id] = post;
+ if (isNewPost && postList.order.indexOf(post.id) === -1) {
+ postList.order.unshift(post.id);
+ }
- this.makePostsInfo(post.channel_id);
- this.postsInfo[post.channel_id].postList = postList;
+ this.makePostsInfo(post.channel_id);
+ this.postsInfo[id].postList = postList;
+ });
}
storeFocusedPost(postId, channelId, postList) {
@@ -500,6 +521,18 @@ class PostStoreClass extends EventEmitter {
this.removeListener(SELECTED_POST_CHANGE_EVENT, callback);
}
+ emitPostPinnedChange() {
+ this.emit(POST_PINNED_CHANGE_EVENT);
+ }
+
+ addPostPinnedChangeListener(callback) {
+ this.on(POST_PINNED_CHANGE_EVENT, callback);
+ }
+
+ removePostPinnedChangeListener(callback) {
+ this.removeListener(POST_PINNED_CHANGE_EVENT, callback);
+ }
+
getCurrentUsersLatestPost(channelId, rootId) {
const userId = UserStore.getCurrentId();
@@ -686,6 +719,10 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
PostStore.storeSelectedPostId(action.postId);
PostStore.emitSelectedPostChange(action.from_search, action.from_flagged_posts);
break;
+ case ActionTypes.RECEIVED_POST_PINNED:
+ case ActionTypes.RECEIVED_POST_UNPINNED:
+ PostStore.emitPostPinnedChange();
+ break;
default:
}
});
diff --git a/webapp/stores/search_store.jsx b/webapp/stores/search_store.jsx
index 46a086ddb..49f8b3c2f 100644
--- a/webapp/stores/search_store.jsx
+++ b/webapp/stores/search_store.jsx
@@ -19,6 +19,7 @@ class SearchStoreClass extends EventEmitter {
this.searchResults = null;
this.isMentionSearch = false;
this.isFlaggedPosts = false;
+ this.isPinnedPosts = false;
this.isVisible = false;
this.searchTerm = '';
}
@@ -83,6 +84,10 @@ class SearchStoreClass extends EventEmitter {
return this.isFlaggedPosts;
}
+ getIsPinnedPosts() {
+ return this.isPinnedPosts;
+ }
+
storeSearchTerm(term) {
this.searchTerm = term;
}
@@ -91,10 +96,11 @@ class SearchStoreClass extends EventEmitter {
return this.searchTerm;
}
- storeSearchResults(results, isMentionSearch, isFlaggedPosts) {
+ storeSearchResults(results, isMentionSearch, isFlaggedPosts, isPinnedPosts) {
this.searchResults = results;
this.isMentionSearch = isMentionSearch;
this.isFlaggedPosts = isFlaggedPosts;
+ this.isPinnedPosts = isPinnedPosts;
}
deletePost(post) {
@@ -120,7 +126,7 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
switch (action.type) {
case ActionTypes.RECEIVED_SEARCH:
- SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts);
+ SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts, action.is_pinned_posts);
SearchStore.emitSearchChange();
break;
case ActionTypes.RECEIVED_SEARCH_TERM: