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 @@ -10,6 +10,8 @@ newThreadActionTypes, } from '../actions/thread-actions.js'; import { + deleteAccountActionTypes, + keyserverAuthActionTypes, logOutActionTypes, deleteKeyserverAccountActionTypes, logInActionTypes, @@ -46,6 +48,7 @@ } from '../types/user-types.js'; import { getMessageForException } from '../utils/errors.js'; import { assertObjectsAreEqual } from '../utils/objects.js'; +import { usingCommServicesAccessToken } from '../utils/services-utils.js'; function reduceCurrentUserInfo( state: ?CurrentUserInfo, @@ -211,9 +214,36 @@ } } else if ( action.type === logOutActionTypes.success || - action.type === deleteKeyserverAccountActionTypes.success || - (action.type === setNewSessionActionType && - action.payload.sessionChange.cookieInvalidated) + action.type === deleteAccountActionTypes.success + ) { + const userStoreOps: $ReadOnlyArray = [ + { type: 'remove_all_users' }, + ]; + const processedUserInfos: UserInfos = processUserStoreOps( + state.userInfos, + userStoreOps, + ); + assertUserStoresAreEqual( + processedUserInfos, + {}, + action.type, + onStateDifference, + ); + + if (Object.keys(state.userInfos).length === 0) { + return [state, [], []]; + } + return [ + { + userInfos: {}, + }, + [], + userStoreOps, + ]; + } else if ( + action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated && + !usingCommServicesAccessToken ) { const userStoreOps: $ReadOnlyArray = [ { type: 'remove_all_users' }, @@ -276,6 +306,35 @@ userStoreOps, ]; } + } else if (action.type === keyserverAuthActionTypes.success) { + const newUserInfos = _keyBy(userInfo => userInfo.id)( + action.payload.userInfos, + ); + const mergedUserInfos: UserInfos = { ...state.userInfos, ...newUserInfos }; + + const userStoreOps: $ReadOnlyArray = + convertUserInfosToReplaceUserOps(newUserInfos); + const processedUserInfos: UserInfos = processUserStoreOps( + state.userInfos, + userStoreOps, + ); + assertUserStoresAreEqual( + processedUserInfos, + mergedUserInfos, + action.type, + onStateDifference, + ); + + if (!_isEqual(state.userInfos)(mergedUserInfos)) { + return [ + { + ...state, + userInfos: mergedUserInfos, + }, + [], + userStoreOps, + ]; + } } else if ( action.type === incrementalStateSyncActionType || action.type === processUpdatesActionType