diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -62,11 +62,8 @@ } }; - const [userStore, newUserInconsistencies] = reduceUserInfos( - state.userStore, - action, - onStateDifferenceForStaff, - ); + const [userStore, newUserInconsistencies, userStoreOperations] = + reduceUserInfos(state.userStore, action, onStateDifferenceForStaff); const newInconsistencies = [ ...newEntryInconsistencies, @@ -182,6 +179,7 @@ threadStoreOperations, messageStoreOperations, reportStoreOperations, + userStoreOperations, }, }; } 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 @@ -178,7 +178,11 @@ state: UserStore, action: BaseAction, onStateDifference: (message: string) => mixed, -): [UserStore, $ReadOnlyArray] { +): [ + UserStore, + $ReadOnlyArray, + $ReadOnlyArray, +] { if ( action.type === joinThreadActionTypes.success || action.type === newThreadActionTypes.success @@ -187,9 +191,11 @@ action.payload.userInfos, ); + const userStoreOps: $ReadOnlyArray = + convertUserInfosToReplaceUserOps(newUserInfos); const processedUserInfos: UserInfos = processUserStoreOps( state.userInfos, - convertUserInfosToReplaceUserOps(newUserInfos), + userStoreOps, ); const updated: UserInfos = { ...state.userInfos, ...newUserInfos }; assertUserStoresAreEqual( @@ -206,6 +212,7 @@ userInfos: updated, }, [], + userStoreOps, ]; } } else if ( @@ -214,9 +221,13 @@ (action.type === setNewSessionActionType && action.payload.sessionChange.cookieInvalidated) ) { - const processedUserInfos: UserInfos = processUserStoreOps(state.userInfos, [ + const userStoreOps: $ReadOnlyArray = [ { type: 'remove_all_users' }, - ]); + ]; + const processedUserInfos: UserInfos = processUserStoreOps( + state.userInfos, + userStoreOps, + ); assertUserStoresAreEqual( processedUserInfos, {}, @@ -225,13 +236,14 @@ ); if (Object.keys(state.userInfos).length === 0) { - return [state, []]; + return [state, [], []]; } return [ { userInfos: {}, }, [], + userStoreOps, ]; } else if ( action.type === logInActionTypes.success || @@ -242,10 +254,14 @@ const newUserInfos = _keyBy(userInfo => userInfo.id)( action.payload.userInfos, ); - const processedUserInfos: UserInfos = processUserStoreOps(state.userInfos, [ + const userStoreOps: $ReadOnlyArray = [ { type: 'remove_all_users' }, ...convertUserInfosToReplaceUserOps(newUserInfos), - ]); + ]; + const processedUserInfos: UserInfos = processUserStoreOps( + state.userInfos, + userStoreOps, + ); assertUserStoresAreEqual( processedUserInfos, newUserInfos, @@ -258,6 +274,7 @@ userInfos: newUserInfos, }, [], + userStoreOps, ]; } } else if ( @@ -267,7 +284,7 @@ const newUserInfos = _keyBy(userInfo => userInfo.id)( action.payload.userInfos, ); - const userStoreOps: UserStoreOperation[] = [ + const userStoreOps: $ReadOnlyArray = [ ...convertUserInfosToReplaceUserOps(newUserInfos), ...generateOpsForUserUpdates(state.userInfos, action.payload), ]; @@ -299,6 +316,7 @@ userInfos: updated, }, [], + userStoreOps, ]; } } else if (action.type === processServerRequestsActionType) { @@ -306,11 +324,11 @@ candidate => candidate.type === serverRequestTypes.CHECK_STATE, ); if (!checkStateRequest || !checkStateRequest.stateChanges) { - return [state, []]; + return [state, [], []]; } const { userInfos, deleteUserInfoIDs } = checkStateRequest.stateChanges; if (!userInfos && !deleteUserInfoIDs) { - return [state, []]; + return [state, [], []]; } const userStoreOps: UserStoreOperation[] = []; @@ -352,14 +370,17 @@ userInfos: newUserInfos, }, newInconsistencies, + userStoreOps, ]; } else if (action.type === updateUserAvatarActionTypes.success) { const newUserInfos = _keyBy(userInfo => userInfo.id)( action.payload.updates.userInfos, ); + const userStoreOps: $ReadOnlyArray = + convertUserInfosToReplaceUserOps(newUserInfos); const processedUserInfos: UserInfos = processUserStoreOps( state.userInfos, - convertUserInfosToReplaceUserOps(newUserInfos), + userStoreOps, ); const updated: UserInfos = { ...state.userInfos, ...newUserInfos }; assertUserStoresAreEqual( @@ -374,10 +395,10 @@ userInfos: updated, } : state; - return [newState, []]; + return [newState, [], userStoreOps]; } - return [state, []]; + return [state, [], []]; } export { reduceCurrentUserInfo, reduceUserInfos }; diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js --- a/lib/types/store-ops-types.js +++ b/lib/types/store-ops-types.js @@ -23,12 +23,14 @@ ClientDBThreadStoreOperation, ThreadStoreOperation, } from '../ops/thread-store-ops.js'; +import type { UserStoreOperation } from '../ops/user-store-ops.js'; export type StoreOperations = { +draftStoreOperations: $ReadOnlyArray, +threadStoreOperations: $ReadOnlyArray, +messageStoreOperations: $ReadOnlyArray, +reportStoreOperations: $ReadOnlyArray, + +userStoreOperations: $ReadOnlyArray, }; export type ClientDBStoreOperations = { diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -234,6 +234,7 @@ threadStoreOperations, messageStoreOperations, reportStoreOperations, + userStoreOperations, } = storeOperations; const fixUnreadActiveThreadResult = fixUnreadActiveThread(state, action); @@ -249,6 +250,7 @@ messageStoreOperations, threadStoreOperations: threadStoreOperationsWithUnreadFix, reportStoreOperations, + userStoreOperations, }); return state;