diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index 0ee45e48a0..cbad38a3e0 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -233,7 +233,7 @@ export function reconnect() { // we can request for getPosts again when socket is connected dispatch(getPosts(currentChannelId)); } - StatusActions.loadStatusesForChannelAndSidebar(); + dispatch(StatusActions.loadStatusesForChannelAndSidebar()); const crtEnabled = isCollapsedThreadsEnabled(state); dispatch(TeamActions.getMyTeamUnreads(crtEnabled, true)); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts index c0e1da102b..e79f887d35 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts @@ -280,12 +280,10 @@ export function getMissingProfilesByUsernames(usernames: string[]): ActionFunc { export function getProfilesByIds(userIds: string[], options?: any): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { - const {currentUserId} = getState().entities.users; let profiles: UserProfile[]; try { profiles = await Client4.getProfilesByIds(userIds, options); - removeUserFromList(currentUserId, profiles); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); dispatch(logError(error)); diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.test.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.test.ts index 296258177a..66e32e6dec 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.test.ts @@ -4,6 +4,9 @@ import {UserTypes, ChannelTypes} from 'mattermost-redux/action_types'; import {GenericAction} from 'mattermost-redux/types/actions'; import reducer from 'mattermost-redux/reducers/entities/users'; + +import {TestHelper} from 'utils/test_helper'; + type ReducerState = ReturnType; describe('Reducers.users', () => { @@ -673,4 +676,35 @@ describe('Reducers.users', () => { expect(newState.profilesNotInGroup).toEqual(expectedState.profilesNotInGroup); }); }); + describe('profiles', () => { + it('UserTypes.RECEIVED_PROFILES_LIST, should merge existing users with new ones', () => { + const firstUser = TestHelper.getUserMock({id: 'first_user_id'}); + const secondUser = TestHelper.getUserMock({id: 'seocnd_user_id'}); + const thirdUser = TestHelper.getUserMock({id: 'third_user_id'}); + const partialUpdatedFirstUser = { + ...firstUser, + update_at: 123456789, + }; + Reflect.deleteProperty(partialUpdatedFirstUser, 'email'); + Reflect.deleteProperty(partialUpdatedFirstUser, 'notify_props'); + const state = { + profiles: { + first_user_id: firstUser, + second_user_id: secondUser, + }, + }; + const action = { + type: UserTypes.RECEIVED_PROFILES_LIST, + data: [ + partialUpdatedFirstUser, + thirdUser, + ], + }; + const {profiles: newProfiles} = reducer(state as unknown as ReducerState, action); + + expect(newProfiles.first_user_id).toEqual({...firstUser, ...partialUpdatedFirstUser}); + expect(newProfiles.second_user_id).toEqual(secondUser); + expect(newProfiles.third_user_id).toEqual(thirdUser); + }); + }); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.ts index 834e13ae0c..746f35e09e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/users.ts @@ -198,15 +198,18 @@ function profiles(state: IDMappedObjects = {}, action: GenericActio const users: UserProfile[] = action.data; return users.reduce((nextState, user) => { - const oldUser = nextState[user.id]; + const oldUser = nextState[user.id] || {}; - if (oldUser && isEqual(user, oldUser)) { + if (isEqual(user, oldUser)) { return nextState; } return { ...nextState, - [user.id]: user, + [user.id]: { + ...oldUser, + ...user, + }, }; }, state); }