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 @@ -307,10 +307,7 @@ ...state, keyserverInfos, }; - } else if ( - action.type === logOutActionTypes.success || - action.type === deleteKeyserverAccountActionTypes.success - ) { + } else if (action.type === logOutActionTypes.success) { // We want to remove all keyservers but Ashoat's keyserver const oldConnection = state.keyserverInfos[ashoatKeyserverID].connection; @@ -330,6 +327,39 @@ ...state, keyserverInfos, }; + } else if (action.type === deleteKeyserverAccountActionTypes.success) { + const keyserverIDsToRemove = new Set(action.payload.keyserverIDs); + const newKeyserverInfos: { ...KeyserverInfos } = {}; + + 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: newKeyserverInfos, + }; } else if (action.type === setLateResponseActionType) { const { messageID, isLate, keyserverID } = action.payload; const lateResponsesSet = new Set( 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') } }); + }); +});