diff --git a/lib/reducers/keyserver-reducer.js b/lib/reducers/keyserver-reducer.js --- a/lib/reducers/keyserver-reducer.js +++ b/lib/reducers/keyserver-reducer.js @@ -4,10 +4,16 @@ import { reduceDeviceToken } from './device-token-reducer.js'; import reduceLastCommunicatedPlatformDetails from './last-communicated-platform-details-reducer.js'; import reduceUpdatesCurrentAsOf from './updates-reducer.js'; +import { + addKeyserverActionType, + removeKeyserverActionType, +} from '../actions/keyserver-actions.js'; import { siweAuthActionTypes } from '../actions/siwe-actions.js'; import { logInActionTypes, resetUserStateActionType, + logOutActionTypes, + deleteAccountActionTypes, } from '../actions/user-actions.js'; import type { KeyserverStore } from '../types/keyserver-types'; import type { BaseAction } from '../types/redux-types.js'; @@ -24,8 +30,48 @@ state: KeyserverStore, action: BaseAction, ): KeyserverStore { - // this action is only dispatched on native - if (action.type === resetUserStateActionType) { + if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success || + (action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated) + ) { + state = { + keyserverInfos: { + [ashoatKeyserverID]: { + ...state.keyserverInfos[ashoatKeyserverID], + }, + }, + }; + } else if (action.type === addKeyserverActionType) { + return { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [action.payload.keyserverAdminUserID]: { + ...action.payload.newKeyserverInfo, + }, + }, + }; + } else if (action.type === removeKeyserverActionType) { + const filteredKeys = Object.keys(state.keyserverInfos).filter( + key => key !== action.payload.keyserverAdminUserID, + ); + + const filteredKeyserverInfos = filteredKeys.reduce( + (newKeyserverInfos, key) => { + newKeyserverInfos[key] = state.keyserverInfos[key]; + return newKeyserverInfos; + }, + {}, + ); + + return { + ...state, + keyserverInfos: filteredKeyserverInfos, + }; + } else if (action.type === resetUserStateActionType) { + // this action is only dispatched on native const stateCookie = state.keyserverInfos[ashoatKeyserverID]?.cookie; const cookie = stateCookie && stateCookie.startsWith('anonymous=') ? stateCookie : null;