Fix the elusive missing posts bug (#3836)

Этот коммит содержится в:
Joram Wilander
2016-08-19 12:09:08 -04:00
коммит произвёл GitHub
родитель 06f5acf42c
Коммит 388fefcc43
2 изменённых файлов: 21 добавлений и 8 удалений

Просмотреть файл

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

Просмотреть файл

@@ -581,6 +581,7 @@ export function getPostsPage(id, maxPosts) {
id: channelId,
before: true,
numRequested: numPosts,
checkLatest: true,
post_list: data
});
@@ -616,12 +617,7 @@ export function getPosts(id) {
return;
}
const latestPost = PostStore.getLatestPost(channelId);
let latestPostTime = 0;
if (latestPost != null && latestPost.update_at != null) {
latestPostTime = latestPost.create_at;
}
const latestPostTime = PostStore.getLatestPostFromPageTime(id);
callTracker['getPosts_' + channelId] = utils.getTimestamp();