Fix the elusive missing posts bug (#3836)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
06f5acf42c
Коммит
388fefcc43
@@ -22,6 +22,7 @@ class PostStoreClass extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.selectedPostId = null;
|
this.selectedPostId = null;
|
||||||
this.postsInfo = {};
|
this.postsInfo = {};
|
||||||
|
this.latestPageTime = {};
|
||||||
this.currentFocusedPostId = null;
|
this.currentFocusedPostId = null;
|
||||||
}
|
}
|
||||||
emitChange() {
|
emitChange() {
|
||||||
@@ -131,6 +132,14 @@ class PostStoreClass extends EventEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLatestPostFromPageTime(id) {
|
||||||
|
if (this.latestPageTime.hasOwnProperty(id)) {
|
||||||
|
return this.latestPageTime[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
getVisiblePosts(id) {
|
getVisiblePosts(id) {
|
||||||
if (this.postsInfo.hasOwnProperty(id) && this.postsInfo[id].hasOwnProperty('postList')) {
|
if (this.postsInfo.hasOwnProperty(id) && this.postsInfo[id].hasOwnProperty('postList')) {
|
||||||
const postList = JSON.parse(JSON.stringify(this.postsInfo[id].postList));
|
const postList = JSON.parse(JSON.stringify(this.postsInfo[id].postList));
|
||||||
@@ -184,11 +193,19 @@ class PostStoreClass extends EventEmitter {
|
|||||||
return this.currentFocusedPostId;
|
return this.currentFocusedPostId;
|
||||||
}
|
}
|
||||||
|
|
||||||
storePosts(id, newPosts) {
|
storePosts(id, newPosts, checkLatest) {
|
||||||
if (isPostListNull(newPosts)) {
|
if (isPostListNull(newPosts)) {
|
||||||
return;
|
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));
|
const combinedPosts = makePostListNonNull(this.getAllPosts(id));
|
||||||
|
|
||||||
for (const pid in newPosts.posts) {
|
for (const pid in newPosts.posts) {
|
||||||
@@ -576,7 +593,7 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
|
|||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.RECEIVED_POSTS: {
|
case ActionTypes.RECEIVED_POSTS: {
|
||||||
const id = PostStore.currentFocusedPostId !== null && action.isPost ? PostStore.currentFocusedPostId : action.id;
|
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.checkBounds(id, action.numRequested, makePostListNonNull(action.post_list), action.before);
|
||||||
PostStore.emitChange();
|
PostStore.emitChange();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -581,6 +581,7 @@ export function getPostsPage(id, maxPosts) {
|
|||||||
id: channelId,
|
id: channelId,
|
||||||
before: true,
|
before: true,
|
||||||
numRequested: numPosts,
|
numRequested: numPosts,
|
||||||
|
checkLatest: true,
|
||||||
post_list: data
|
post_list: data
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -616,12 +617,7 @@ export function getPosts(id) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const latestPost = PostStore.getLatestPost(channelId);
|
const latestPostTime = PostStore.getLatestPostFromPageTime(id);
|
||||||
let latestPostTime = 0;
|
|
||||||
|
|
||||||
if (latestPost != null && latestPost.update_at != null) {
|
|
||||||
latestPostTime = latestPost.create_at;
|
|
||||||
}
|
|
||||||
|
|
||||||
callTracker['getPosts_' + channelId] = utils.getTimestamp();
|
callTracker['getPosts_' + channelId] = utils.getTimestamp();
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user