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 @@ -3,10 +3,13 @@ import reduceConnectionInfo from './connection-reducer.js'; import reduceLastCommunicatedPlatformDetails from './last-communicated-platform-details-reducer.js'; import reduceUpdatesCurrentAsOf from './updates-reducer.js'; +import { addKeyserverActionType } 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'; @@ -19,10 +22,42 @@ import { setURLPrefix } from '../utils/url-utils.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; +function reduceAddKeyserver( + state: KeyserverStore, + action: BaseAction, +): KeyserverStore { + if (action.type === addKeyserverActionType) { + return { + ...state, + keyserverInfos: { + ...state.keyserverInfos, + [action.payload.keyserverAdminUserID]: { + ...action.payload.newKeyserverInfo, + }, + }, + }; + } + + return state; +} + export default function reduceKeyserverStore( state: KeyserverStore, action: BaseAction, ): KeyserverStore { + if ( + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success || + (action.type === setNewSessionActionType && + action.payload.sessionChange.cookieInvalidated) + ) { + return { + keyserverInfos: {}, + }; + } + if (action.type === addKeyserverActionType) { + return reduceAddKeyserver(state, action); + } // this action is only dispatched on native if (action.type === resetUserStateActionType) { const stateCookie = state.keyserverInfos[ashoatKeyserverID]?.cookie;