From 0ee7b60e846f2550a90378959b66a0c612074b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Vay=C3=A1?= Date: Fri, 11 Dec 2020 04:49:44 +0100 Subject: [PATCH] [MM-30857] request postssince on reconnect (#5000) * [MM-30857] request postssince on reconnect * [MM-30857] add test * Address CR, add debounce in case of unstable connection * remove leftovers * Address review comments * remove previous changes * fix tests --- app/actions/websocket/index.ts | 8 ++++++-- app/actions/websocket/websocket.test.js | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/actions/websocket/index.ts b/app/actions/websocket/index.ts index 774778602..8de753ecf 100644 --- a/app/actions/websocket/index.ts +++ b/app/actions/websocket/index.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import {loadChannelsForTeam} from '@actions/views/channel'; -import {getPosts} from '@actions/views/post'; +import {getPostsSince} from '@actions/views/post'; import {loadMe} from '@actions/views/user'; import {WebsocketEvents} from '@constants'; import {ChannelTypes, GeneralTypes, PreferenceTypes, TeamTypes, UserTypes, RoleTypes} from '@mm-redux/action_types'; @@ -44,6 +44,8 @@ import {handleAddEmoji, handleReactionAddedEvent, handleReactionRemovedEvent} fr import {handleRoleAddedEvent, handleRoleRemovedEvent, handleRoleUpdatedEvent} from './roles'; import {handleLeaveTeamEvent, handleUpdateTeamEvent, handleTeamAddedEvent} from './teams'; import {handleStatusChangedEvent, handleUserAddedEvent, handleUserRemovedEvent, handleUserRoleUpdated, handleUserUpdatedEvent} from './users'; +import {getChannelSinceValue} from '@utils/channels'; +import {getPostIdsInChannel} from '@mm-redux/selectors/entities/posts'; export function init(additionalOptions: any = {}) { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { @@ -168,7 +170,9 @@ export function doReconnect(now: number) { if (!stillMemberOfCurrentChannel || !channelStillExists || (!viewArchivedChannels && channelStillExists.delete_at !== 0)) { EventEmitter.emit(General.SWITCH_TO_DEFAULT_CHANNEL, currentTeamId); } else { - dispatch(getPosts(currentChannelId)); + const postIds = getPostIdsInChannel(state, currentChannelId); + const since = getChannelSinceValue(state, currentChannelId, postIds); + dispatch(getPostsSince(currentChannelId, since)); } } diff --git a/app/actions/websocket/websocket.test.js b/app/actions/websocket/websocket.test.js index bd201d7e4..288d6d955 100644 --- a/app/actions/websocket/websocket.test.js +++ b/app/actions/websocket/websocket.test.js @@ -177,8 +177,9 @@ describe('Actions.Websocket doReconnect', () => { const timestamp = 1000; const expectedActions = [ GeneralTypes.WEBSOCKET_SUCCESS, + ]; + const expectedMissingActions = [ 'BATCH_WS_RECONNECT', - 'BATCH_GET_POSTS', ]; mockConfigRequest(); @@ -197,6 +198,7 @@ describe('Actions.Websocket doReconnect', () => { await TestHelper.wait(300); const actionTypes = testStore.getActions().map((a) => a.type); expect(actionTypes).toEqual(expectedActions); + expect(actionTypes).not.toEqual(expect.arrayContaining(expectedMissingActions)); }); it('handle doReconnect after the current channel was archived or the user left it', async () => { @@ -217,7 +219,7 @@ describe('Actions.Websocket doReconnect', () => { 'BATCH_WS_RECONNECT', ]; const expectedMissingActions = [ - 'BATCH_GET_POSTS', + 'BATCH_GET_POSTS_SINCE', ]; mockConfigRequest(); @@ -259,6 +261,8 @@ describe('Actions.Websocket doReconnect', () => { const timestamp = 1000; const expectedActions = [ GeneralTypes.WEBSOCKET_SUCCESS, + ]; + const expectedMissingActions = [ 'BATCH_WS_RECONNECT', ]; @@ -279,6 +283,7 @@ describe('Actions.Websocket doReconnect', () => { const actions = testStore.getActions().map((a) => a.type); expect(actions).toEqual(expect.arrayContaining(expectedActions)); + expect(actions).not.toEqual(expect.arrayContaining(expectedMissingActions)); }); it('handle doReconnect after the current channel was archived and setting is off', async () => { @@ -303,7 +308,7 @@ describe('Actions.Websocket doReconnect', () => { 'BATCH_WS_RECONNECT', ]; const expectedMissingActions = [ - 'BATCH_GET_POSTS', + 'BATCH_GET_POSTS_SINCE', ]; mockConfigRequest({ExperimentalViewArchivedChannels: 'false'}); @@ -337,7 +342,7 @@ describe('Actions.Websocket doReconnect', () => { 'BATCH_WS_RECONNECT', ]; const expectedMissingActions = [ - 'BATCH_GET_POSTS', + 'BATCH_GET_POSTS_SINCE', ]; mockConfigRequest();