diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-08-19 12:09:08 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-19 12:09:08 -0400 |
commit | 388fefcc4316e5e16b82134802b29c046f0a4950 (patch) | |
tree | 4014192d94e11e884bc4ea324a181bdff0d6b303 /webapp/stores/post_store.jsx | |
parent | 06f5acf42cbd61e474bfc451ce539812383868a2 (diff) | |
download | chat-388fefcc4316e5e16b82134802b29c046f0a4950.tar.gz chat-388fefcc4316e5e16b82134802b29c046f0a4950.tar.bz2 chat-388fefcc4316e5e16b82134802b29c046f0a4950.zip |
Fix the elusive missing posts bug (#3836)
Diffstat (limited to 'webapp/stores/post_store.jsx')
-rw-r--r-- | webapp/stores/post_store.jsx | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 0b2277255..7b3d337f3 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -22,6 +22,7 @@ class PostStoreClass extends EventEmitter { super(); this.selectedPostId = null; this.postsInfo = {}; + this.latestPageTime = {}; this.currentFocusedPostId = null; } emitChange() { @@ -131,6 +132,14 @@ class PostStoreClass extends EventEmitter { return null; } + getLatestPostFromPageTime(id) { + if (this.latestPageTime.hasOwnProperty(id)) { + return this.latestPageTime[id]; + } + + return 0; + } + getVisiblePosts(id) { if (this.postsInfo.hasOwnProperty(id) && this.postsInfo[id].hasOwnProperty('postList')) { const postList = JSON.parse(JSON.stringify(this.postsInfo[id].postList)); @@ -184,11 +193,19 @@ class PostStoreClass extends EventEmitter { return this.currentFocusedPostId; } - storePosts(id, newPosts) { + storePosts(id, newPosts, checkLatest) { if (isPostListNull(newPosts)) { return; } + if (checkLatest && newPosts.order.length >= 1) { + const currentLatest = this.latestPageTime[id] || 0; + const newLatest = newPosts.posts[newPosts.order[0]].create_at || 0; + if (newLatest > currentLatest) { + this.latestPageTime[id] = newLatest; + } + } + const combinedPosts = makePostListNonNull(this.getAllPosts(id)); for (const pid in newPosts.posts) { @@ -576,7 +593,7 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => { switch (action.type) { case ActionTypes.RECEIVED_POSTS: { const id = PostStore.currentFocusedPostId !== null && action.isPost ? PostStore.currentFocusedPostId : action.id; - PostStore.storePosts(id, makePostListNonNull(action.post_list)); + PostStore.storePosts(id, makePostListNonNull(action.post_list), action.checkLatest); PostStore.checkBounds(id, action.numRequested, makePostListNonNull(action.post_list), action.before); PostStore.emitChange(); break; |