diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-05-02 09:58:27 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-02 09:58:27 -0400 |
commit | f1ddbc4e8bf6816e15248755d806b68e760edbf1 (patch) | |
tree | 6f36359a6a36adf7d7d751a91eb12a0251e662ee /webapp/stores/post_store.jsx | |
parent | a0ba70823de874e3067caea5ed336b92b234ce2f (diff) | |
download | chat-f1ddbc4e8bf6816e15248755d806b68e760edbf1.tar.gz chat-f1ddbc4e8bf6816e15248755d806b68e760edbf1.tar.bz2 chat-f1ddbc4e8bf6816e15248755d806b68e760edbf1.zip |
Fixed PostStore to not return deleted posts when attempting to edit (#2839)
Diffstat (limited to 'webapp/stores/post_store.jsx')
-rw-r--r-- | webapp/stores/post_store.jsx | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 3f2f75796..17529acb6 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -445,23 +445,30 @@ class PostStoreClass extends EventEmitter { getCurrentUsersLatestPost(channelId, rootId) { const userId = UserStore.getCurrentId(); - var postList = makePostListNonNull(this.getAllPosts(channelId)); - var i = 0; - var len = postList.order.length; - var lastPost = null; - for (i; i < len; i++) { + const postList = makePostListNonNull(this.getAllPosts(channelId)); + const len = postList.order.length; + + let lastPost = null; + + for (let i = 0; i < len; i++) { const post = postList.posts[postList.order[i]]; - if (post.user_id === userId && (post.props && !post.props.from_webhook || !post.props)) { - if (rootId) { - if (post.root_id === rootId || post.id === rootId) { - lastPost = post; - break; - } - } else { + + // don't edit webhook posts or deleted posts + if (post.user_id !== userId || + (post.props && post.props.from_webhook) || + post.state === Constants.POST_DELETED) { + continue; + } + + if (rootId) { + if (post.root_id === rootId || post.id === rootId) { lastPost = post; break; } + } else { + lastPost = post; + break; } } @@ -471,26 +478,33 @@ class PostStoreClass extends EventEmitter { getEmptyDraft() { return {message: '', uploadsInProgress: [], previews: []}; } + storeCurrentDraft(draft) { var channelId = ChannelStore.getCurrentId(); BrowserStore.setGlobalItem('draft_' + channelId, draft); } + getCurrentDraft() { var channelId = ChannelStore.getCurrentId(); return this.getDraft(channelId); } + storeDraft(channelId, draft) { BrowserStore.setGlobalItem('draft_' + channelId, draft); } + getDraft(channelId) { return BrowserStore.getGlobalItem('draft_' + channelId, this.getEmptyDraft()); } + storeCommentDraft(parentPostId, draft) { BrowserStore.setGlobalItem('comment_draft_' + parentPostId, draft); } + getCommentDraft(parentPostId) { return BrowserStore.getGlobalItem('comment_draft_' + parentPostId, this.getEmptyDraft()); } + clearDraftUploads() { BrowserStore.actionOnGlobalItemsWithPrefix('draft_', (key, value) => { if (value) { @@ -499,6 +513,7 @@ class PostStoreClass extends EventEmitter { } }); } + clearCommentDraftUploads() { BrowserStore.actionOnGlobalItemsWithPrefix('comment_draft_', (key, value) => { if (value) { @@ -507,6 +522,7 @@ class PostStoreClass extends EventEmitter { } }); } + getCommentCount(post) { const posts = this.getAllPosts(post.channel_id).posts; |