diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -202,16 +202,20 @@ const newUserInfos = _keyBy(userInfo => userInfo.id)( action.payload.userInfos, ); - const updated = { ...state.userInfos, ...newUserInfos }; - for (const update of action.payload.updatesResult.newUpdates) { - if (update.type === updateTypes.DELETE_ACCOUNT) { - delete updated[update.deletedUserID]; - } - } + const updated = action.payload.updatesResult.newUpdates.reduce( + (reducedState, update) => { + const { reduceUserInfos: reduceUserInfosUpdate } = + updateSpecs[update.type]; + return reduceUserInfosUpdate + ? reduceUserInfosUpdate(reducedState, update) + : reducedState; + }, + { ...state.userInfos, ...newUserInfos }, + ); if (!_isEqual(state.userInfos)(updated)) { return { + ...state, userInfos: updated, - inconsistencyReports: state.inconsistencyReports, }; } } else if (action.type === processServerRequestsActionType) { diff --git a/lib/shared/updates/delete-account-spec.js b/lib/shared/updates/delete-account-spec.js --- a/lib/shared/updates/delete-account-spec.js +++ b/lib/shared/updates/delete-account-spec.js @@ -3,6 +3,7 @@ import type { UpdateSpec } from './update-spec.js'; import type { RawThreadInfos } from '../../types/thread-types.js'; import type { AccountDeletionUpdateInfo } from '../../types/update-types.js'; +import type { UserInfos } from '../../types/user-types.js'; export const deleteAccountSpec: UpdateSpec = Object.freeze({ @@ -32,4 +33,12 @@ } return operations; }, + reduceUserInfos(state: UserInfos, update: AccountDeletionUpdateInfo) { + const { deletedUserID } = update; + if (!state[deletedUserID]) { + return state; + } + const { [deletedUserID]: deleted, ...rest } = state; + return rest; + }, }); diff --git a/lib/shared/updates/update-spec.js b/lib/shared/updates/update-spec.js --- a/lib/shared/updates/update-spec.js +++ b/lib/shared/updates/update-spec.js @@ -4,7 +4,7 @@ import type { RawEntryInfo } from '../../types/entry-types.js'; import type { RawThreadInfos } from '../../types/thread-types.js'; import type { ClientUpdateInfo } from '../../types/update-types.js'; -import type { CurrentUserInfo } from '../../types/user-types.js'; +import type { CurrentUserInfo, UserInfos } from '../../types/user-types.js'; export type UpdateSpec = { +generateOpsForThreadUpdates?: ( @@ -20,4 +20,5 @@ state: ?CurrentUserInfo, update: UpdateInfo, ) => ?CurrentUserInfo, + +reduceUserInfos?: (state: UserInfos, update: UpdateInfo) => UserInfos, };