diff --git a/web/redux/primary-identity-public-key-reducer.js b/web/redux/primary-identity-public-key-reducer.js new file mode 100644 --- /dev/null +++ b/web/redux/primary-identity-public-key-reducer.js @@ -0,0 +1,29 @@ +// @flow + +import { + logOutActionTypes, + deleteAccountActionTypes, +} from 'lib/actions/user-actions'; +import { setNewSessionActionType } from 'lib/utils/action-utils.js'; + +import type { Action } from './redux-setup.js'; + +const setPrimaryIdentityPublicKey = 'SET_PRIMARY_IDENTITY_PUBLIC_KEY'; +function reducePrimaryIdentityPublicKey( + state: ?string, + action: Action, +): ?string { + if (action.type === setPrimaryIdentityPublicKey) { + return action.payload; + } else if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success || + (action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated) + ) { + return null; + } + return state; +} + +export { setPrimaryIdentityPublicKey, reducePrimaryIdentityPublicKey }; diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -37,6 +37,10 @@ } from './action-types'; import { reduceDeviceID } from './device-id-reducer'; import reduceNavInfo from './nav-reducer'; +import { + reducePrimaryIdentityPublicKey, + setPrimaryIdentityPublicKey, +} from './primary-identity-public-key-reducer'; import { getVisibility } from './visibility'; export type WindowDimensions = { width: number, height: number }; @@ -85,7 +89,8 @@ | { type: 'SET_DEVICE_ID', payload: string, - }; + } + | { +type: 'SET_PRIMARY_IDENTITY_PUBLIC_KEY', payload: ?string }; export function reducer(oldState: AppState | void, action: Action): AppState { invariant(oldState, 'should be set'); @@ -134,7 +139,8 @@ if ( action.type !== updateNavInfoActionType && - action.type !== setDeviceIDActionType + action.type !== setDeviceIDActionType && + action.type !== setPrimaryIdentityPublicKey ) { state = baseReducer(state, action).state; } @@ -147,6 +153,10 @@ state.threadStore.threadInfos, ), deviceID: reduceDeviceID(state.deviceID, action), + primaryIdentityPublicKey: reducePrimaryIdentityPublicKey( + state.primaryIdentityPublicKey, + action, + ), }; return validateState(oldState, state);