[ICU-680] Fix Duplicate posts (#1430)
This commit is contained in:
parent
42af38944e
commit
b53f3988b8
4 changed files with 40 additions and 27 deletions
|
|
@ -149,13 +149,15 @@ export function loadPostsIfNecessaryWithRetry(channelId) {
|
|||
|
||||
const time = Date.now();
|
||||
|
||||
let loadMorePostsVisible;
|
||||
let loadMorePostsVisible = true;
|
||||
let received;
|
||||
if (!postsIds || postsIds.length < ViewTypes.POST_VISIBILITY_CHUNK_SIZE) {
|
||||
// Get the first page of posts if it appears we haven't gotten it yet, like the webapp
|
||||
received = await retryGetPostsAction(getPosts(channelId), dispatch, getState);
|
||||
|
||||
loadMorePostsVisible = received.order.length >= ViewTypes.POST_VISIBILITY_CHUNK_SIZE;
|
||||
if (received) {
|
||||
loadMorePostsVisible = received.order.length >= ViewTypes.POST_VISIBILITY_CHUNK_SIZE;
|
||||
}
|
||||
} else {
|
||||
const {lastConnectAt} = state.device.websocket;
|
||||
const lastGetPosts = state.views.channel.lastGetPosts[channelId];
|
||||
|
|
@ -173,7 +175,9 @@ export function loadPostsIfNecessaryWithRetry(channelId) {
|
|||
|
||||
received = await retryGetPostsAction(getPostsSince(channelId, since), dispatch, getState);
|
||||
|
||||
loadMorePostsVisible = postsIds.length + received.order.length >= ViewTypes.POST_VISIBILITY_CHUNK_SIZE;
|
||||
if (received) {
|
||||
loadMorePostsVisible = postsIds.length + received.order.length >= ViewTypes.POST_VISIBILITY_CHUNK_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
if (received) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import appReducer from 'app/reducers';
|
|||
import {throttle} from 'app/utils/general';
|
||||
import networkConnectionListener from 'app/utils/network';
|
||||
import {createSentryMiddleware} from 'app/utils/sentry/middleware';
|
||||
import {promiseTimeout} from 'app/utils/promise_timeout';
|
||||
|
||||
import mattermostBucket from 'app/mattermost_bucket';
|
||||
import Config from 'assets/config';
|
||||
|
|
@ -134,13 +133,6 @@ export default function configureAppStore(initialState) {
|
|||
throw new Error('Offline Action: commit action must be present.');
|
||||
}
|
||||
|
||||
if (action.meta.offline.canTimeout) {
|
||||
const defaultTimeout = 10000;
|
||||
const timeout = action.meta.offline.timeout || defaultTimeout;
|
||||
|
||||
return promiseTimeout(effect(), timeout);
|
||||
}
|
||||
|
||||
return effect();
|
||||
},
|
||||
detectNetwork: (callback) => networkConnectionListener(callback),
|
||||
|
|
|
|||
|
|
@ -277,6 +277,32 @@ function cleanupState(action, keepCurrent = false) {
|
|||
}
|
||||
});
|
||||
|
||||
// remove any pending posts that hasn't failed
|
||||
if (payload.entities.posts && payload.entities.posts.pendingPostIds.length) {
|
||||
const nextPendingPostIds = [...payload.entities.posts.pendingPostIds];
|
||||
payload.entities.posts.pendingPostIds.forEach((id) => {
|
||||
const posts = nextEntitites.posts.posts;
|
||||
const post = posts[id];
|
||||
|
||||
if (post) {
|
||||
const postsInChannel = [...nextEntitites.posts.postsInChannel[post.channel_id]] || [];
|
||||
if (!post.failed) {
|
||||
Reflect.deleteProperty(posts, id);
|
||||
const index = postsInChannel.indexOf(id);
|
||||
if (index !== -1) {
|
||||
postsInChannel.splice(index, 1);
|
||||
nextEntitites.posts.postsInChannel[post.channel_id] = postsInChannel;
|
||||
}
|
||||
removePendingPost(nextPendingPostIds, id);
|
||||
}
|
||||
} else {
|
||||
removePendingPost(nextPendingPostIds, id);
|
||||
}
|
||||
});
|
||||
|
||||
nextEntitites.posts.pendingPostIds = nextPendingPostIds;
|
||||
}
|
||||
|
||||
const nextState = {
|
||||
app: resetPayload.app,
|
||||
entities: {
|
||||
|
|
@ -324,3 +350,10 @@ export function shareExtensionData() {
|
|||
return nextAction;
|
||||
};
|
||||
}
|
||||
|
||||
function removePendingPost(pendingPostIds, id) {
|
||||
const pendingIndex = pendingPostIds.indexOf(id);
|
||||
if (pendingIndex !== -1) {
|
||||
pendingPostIds.splice(pendingIndex, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
export function promiseTimeout(promise, ms) {
|
||||
const timeout = new Promise((resolve, reject) => {
|
||||
const id = setTimeout(() => {
|
||||
clearTimeout(id);
|
||||
reject('Timed out in ' + ms + 'ms.');
|
||||
}, ms);
|
||||
});
|
||||
|
||||
return Promise.race([
|
||||
promise,
|
||||
timeout
|
||||
]);
|
||||
}
|
||||
Loading…
Reference in a new issue