Fix lodaing missing messages after search bug (#5080)

This commit is contained in:
Joram Wilander
2017-01-16 18:32:08 -05:00
committed by Corey Hulen
parent c0fde5f7e5
commit 4257114a37
3 changed files with 20 additions and 18 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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;