summaryrefslogtreecommitdiffstats
path: root/webapp/stores/post_store.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/stores/post_store.jsx')
-rw-r--r--webapp/stores/post_store.jsx57
1 files changed, 47 insertions, 10 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:
}
});