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 @@ -311,24 +311,37 @@ action.type === logOutActionTypes.success || action.type === deleteKeyserverAccountActionTypes.success ) { - // We want to remove all keyservers but Ashoat's keyserver - const oldConnection = state.keyserverInfos[ashoatKeyserverID].connection; + const keyserverIDsToRemove = new Set(action.payload.keyserverIDs); + const newKeyserverInfos: { ...KeyserverInfos } = {}; - const keyserverInfos = { - [ashoatKeyserverID]: { - ...state.keyserverInfos[ashoatKeyserverID], - connection: { - ...oldConnection, - connectionIssue: null, - queuedActivityUpdates: [], - }, - cookie: null, - }, - }; + const { keyserverInfos } = state; + + for (const keyserverID in keyserverInfos) { + if (keyserverIDsToRemove.has(keyserverID)) { + if (keyserverID === ashoatKeyserverID) { + const oldConnection = + state.keyserverInfos[ashoatKeyserverID].connection; + + newKeyserverInfos[ashoatKeyserverID] = { + ...state.keyserverInfos[ashoatKeyserverID], + connection: { + ...oldConnection, + connectionIssue: null, + queuedActivityUpdates: [], + lateResponses: [], + }, + cookie: null, + }; + } + + continue; + } + newKeyserverInfos[keyserverID] = keyserverInfos[keyserverID]; + } return { ...state, - keyserverInfos, + keyserverInfos: newKeyserverInfos, }; } else if (action.type === setLateResponseActionType) { const { messageID, isLate, keyserverID } = action.payload; diff --git a/lib/reducers/keyserver-reducer.test.js b/lib/reducers/keyserver-reducer.test.js new file mode 100644 --- /dev/null +++ b/lib/reducers/keyserver-reducer.test.js @@ -0,0 +1,41 @@ +// @flow + +import reduceKeyserverStore from './keyserver-reducer.js'; +import { deleteKeyserverAccountActionTypes } from '../actions/user-actions.js'; +import { defaultKeyserverInfo } from '../types/keyserver-types.js'; + +describe('reduceKeyserverStore', () => { + it('removes from the store keyservers the user has disconnected from', () => { + const oldKeyserverStore = { + keyserverInfos: { + ['0']: defaultKeyserverInfo('url1'), + ['100']: defaultKeyserverInfo('url2'), + ['200']: defaultKeyserverInfo('url3'), + }, + }; + + const deleteAccountAction = { + type: deleteKeyserverAccountActionTypes.success, + payload: { + currentUserInfo: { anonymous: true }, + preRequestUserState: { + cookiesAndSessions: {}, + currentUserInfo: { + id: '1000', + username: 'test', + }, + }, + keyserverIDs: ['100', '200'], + }, + loadingInfo: { + fetchIndex: 1, + trackMultipleRequests: false, + customKeyName: undefined, + }, + }; + + expect( + reduceKeyserverStore(oldKeyserverStore, deleteAccountAction), + ).toEqual({ keyserverInfos: { ['0']: defaultKeyserverInfo('url1') } }); + }); +});