summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-01-16 18:32:08 -0500
committerCorey Hulen <corey@hulen.com>2017-01-16 18:32:08 -0500
commit4257114a372fbe2d55178ecef303e4a251288015 (patch)
tree1eca06d364c9fda59485128f957a2d92b257acf8 /webapp
parentc0fde5f7e55e083dd132f3e4e96e7f8144289507 (diff)
downloadchat-4257114a372fbe2d55178ecef303e4a251288015.tar.gz
chat-4257114a372fbe2d55178ecef303e4a251288015.tar.bz2
chat-4257114a372fbe2d55178ecef303e4a251288015.zip
Fix lodaing missing messages after search bug (#5080)
Diffstat (limited to 'webapp')
-rw-r--r--webapp/actions/global_actions.jsx2
-rw-r--r--webapp/actions/post_actions.jsx2
-rw-r--r--webapp/stores/post_store.jsx34
3 files changed, 20 insertions, 18 deletions
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx
index ea077d6eb..4cfcaa6cb 100644
--- a/webapp/actions/global_actions.jsx
+++ b/webapp/actions/global_actions.jsx
@@ -256,7 +256,7 @@ export function emitLoadMorePostsFocusedTopEvent() {
}
export function loadMorePostsTop(id, isFocusPost) {
- const earliestPostId = PostStore.getEarliestPost(id).id;
+ const earliestPostId = PostStore.getEarliestPostFromPage(id).id;
if (PostStore.requestVisibilityIncrease(id, Constants.POST_CHUNK_SIZE)) {
loadPostsBefore(earliestPostId, 0, Constants.POST_CHUNK_SIZE, isFocusPost);
}
diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index c7a8cf731..4d472db45 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -167,6 +167,7 @@ export function loadPostsPage(channelId = ChannelStore.getCurrentId(), max = Con
before: true,
numRequested: numPosts,
checkLatest: true,
+ checkEarliest: true,
post_list: data
});
@@ -195,6 +196,7 @@ export function loadPostsBefore(postId, offset, numPost, isPost) {
type: ActionTypes.RECEIVED_POSTS,
id: channelId,
before: true,
+ checkEarliest: true,
numRequested: numPost,
post_list: data,
isPost
diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx
index 023e74e35..411eaf724 100644
--- a/webapp/stores/post_store.jsx
+++ b/webapp/stores/post_store.jsx
@@ -23,6 +23,7 @@ class PostStoreClass extends EventEmitter {
this.selectedPostId = null;
this.postsInfo = {};
this.latestPageTime = {};
+ this.earliestPostFromPage = {};
this.currentFocusedPostId = null;
}
emitChange() {
@@ -116,20 +117,8 @@ class PostStoreClass extends EventEmitter {
return null;
}
- getEarliestPost(id) {
- if (this.postsInfo.hasOwnProperty(id)) {
- const postList = this.postsInfo[id].postList;
-
- for (let i = postList.order.length - 1; i >= 0; i--) {
- const postId = postList.order[i];
-
- if (postList.posts[postId].state !== Constants.POST_DELETED) {
- return postList.posts[postId];
- }
- }
- }
-
- return null;
+ getEarliestPostFromPage(id) {
+ return this.earliestPostFromPage[id];
}
getLatestPost(id) {
@@ -207,7 +196,7 @@ class PostStoreClass extends EventEmitter {
return this.currentFocusedPostId;
}
- storePosts(id, newPosts, checkLatest) {
+ storePosts(id, newPosts, checkLatest, checkEarliest) {
if (isPostListNull(newPosts)) {
return;
}
@@ -225,6 +214,17 @@ class PostStoreClass extends EventEmitter {
}
}
+ if (checkEarliest) {
+ const currentEarliest = this.earliestPostFromPage[id] || {create_at: Number.MAX_SAFE_INTEGER};
+ const orderLength = newPosts.order.length;
+ if (orderLength >= 1) {
+ const newEarliestPost = newPosts.posts[newPosts.order[orderLength - 1]];
+ if (newEarliestPost.create_at < currentEarliest.create_at) {
+ this.earliestPostFromPage[id] = newEarliestPost;
+ }
+ }
+ }
+
const combinedPosts = makePostListNonNull(this.getAllPosts(id));
for (const pid in newPosts.posts) {
@@ -638,10 +638,10 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
switch (action.type) {
case ActionTypes.RECEIVED_POSTS: {
if (PostStore.currentFocusedPostId !== null && action.isPost) {
- PostStore.storePosts(PostStore.currentFocusedPostId, makePostListNonNull(action.post_list), action.checkLatest);
+ PostStore.storePosts(PostStore.currentFocusedPostId, makePostListNonNull(action.post_list), action.checkLatest, action.checkEarliest);
PostStore.checkBounds(PostStore.currentFocusedPostId, action.numRequested, makePostListNonNull(action.post_list), action.before);
}
- PostStore.storePosts(action.id, makePostListNonNull(action.post_list), action.checkLatest);
+ PostStore.storePosts(action.id, makePostListNonNull(action.post_list), action.checkLatest, action.checkEarliest);
PostStore.checkBounds(action.id, action.numRequested, makePostListNonNull(action.post_list), action.before);
PostStore.emitChange();
break;