From ae5cdb56a3e0d91b5df4a775d6699c646f26b1ad Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Thu, 30 Apr 2020 10:21:30 +0200 Subject: [PATCH] Automated cherry pick of #4090 (#4248) * Fix post in channel batching order * Preserve preferences on reset cache Co-authored-by: Elias Nahum --- app/actions/views/post.js | 8 ++++---- app/store/utils.js | 11 ++--------- app/store/utils.test.js | 3 +-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/actions/views/post.js b/app/actions/views/post.js index b9b9f9895..cd83cae62 100644 --- a/app/actions/views/post.js +++ b/app/actions/views/post.js @@ -89,10 +89,6 @@ export function getPosts(channelId, page = 0, perPage = Posts.POST_CHUNK_SIZE) { const posts = Object.values(data.posts); const actions = []; - if (posts?.length || !postForChannel) { - actions.push(receivedPostsInChannel(data, channelId, page === 0, data.prev_post_id === '')); - } - if (posts?.length) { actions.push(receivedPosts(data)); const additional = await dispatch(getPostsAdditionalDataBatch(posts)); @@ -101,6 +97,10 @@ export function getPosts(channelId, page = 0, perPage = Posts.POST_CHUNK_SIZE) { } } + if (posts?.length || !postForChannel) { + actions.push(receivedPostsInChannel(data, channelId, page === 0, data.prev_post_id === '')); + } + dispatch(batchActions(actions, 'BATCH_GET_POSTS')); return {data}; diff --git a/app/store/utils.js b/app/store/utils.js index 375a0b986..b9ce94470 100644 --- a/app/store/utils.js +++ b/app/store/utils.js @@ -76,12 +76,7 @@ export function getStateForReset(initialState, currentState) { const {currentUserId} = currentState.entities.users; const currentUserProfile = currentState.entities.users.profiles[currentUserId]; const {currentTeamId} = currentState.entities.teams; - const myPreferences = {...currentState.entities.preferences.myPreferences}; - Object.keys(myPreferences).forEach((key) => { - if (!key.startsWith('theme--')) { - Reflect.deleteProperty(myPreferences, key); - } - }); + const preferences = currentState.entities.preferences; const resetState = merge(initialState, { app: { @@ -99,9 +94,7 @@ export function getStateForReset(initialState, currentState) { teams: { currentTeamId, }, - preferences: { - myPreferences, - }, + preferences, }, errors: currentState.errors, views: { diff --git a/app/store/utils.test.js b/app/store/utils.test.js index 64095970c..3b3bef167 100644 --- a/app/store/utils.test.js +++ b/app/store/utils.test.js @@ -85,8 +85,7 @@ describe('getStateForReset', () => { const {myPreferences} = resetState.entities.preferences; const preferenceKeys = Object.keys(myPreferences); const themeKeys = preferenceKeys.filter((key) => key.startsWith('theme--')); - expect(themeKeys.length).not.toEqual(0); - expect(themeKeys.length).toEqual(preferenceKeys.length); + expect(themeKeys.length).toEqual(2); }); it('should set previous version as current', () => {