diff --git a/lib/reducers/thread-activity-reducer.js b/lib/reducers/thread-activity-reducer.js --- a/lib/reducers/thread-activity-reducer.js +++ b/lib/reducers/thread-activity-reducer.js @@ -17,7 +17,9 @@ import { logOutActionTypes, deleteKeyserverAccountActionTypes, + deleteAccountActionTypes, } from '../actions/user-actions.js'; +import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js'; import { setNewSessionActionType } from '../keyserver-conn/keyserver-conn-types.js'; import type { BaseAction } from '../types/redux-types.js'; import { incrementalStateSyncActionType } from '../types/socket-types.js'; @@ -88,10 +90,23 @@ const { [update.threadID]: _, ...stateSansRemovedThread } = updatedState; updatedState = stateSansRemovedThread; } + return updatedState; + } else if (action.type === deleteKeyserverAccountActionTypes.success) { + let updatedState = { ...state }; + const keyserverIDsSet = new Set(action.payload.keyserverIDs); + + for (const threadID in state) { + if (!keyserverIDsSet.has(extractKeyserverIDFromID(threadID))) { + continue; + } + const { [threadID]: _, ...stateSansRemovedThread } = updatedState; + updatedState = stateSansRemovedThread; + } + return updatedState; } else if ( action.type === logOutActionTypes.success || - action.type === deleteKeyserverAccountActionTypes.success || + action.type === deleteAccountActionTypes.success || (action.type === setNewSessionActionType && action.payload.sessionChange.cookieInvalidated) ) { diff --git a/lib/reducers/thread-activity-reducer.test.js b/lib/reducers/thread-activity-reducer.test.js --- a/lib/reducers/thread-activity-reducer.test.js +++ b/lib/reducers/thread-activity-reducer.test.js @@ -1,6 +1,7 @@ // @flow import { reduceThreadActivity } from './thread-activity-reducer.js'; +import { deleteKeyserverAccountActionTypes } from '../actions/user-actions.js'; import { updateThreadLastNavigatedActionType } from '../types/thread-activity-types.js'; // NOTE: These unit tests were generated by GitHub Copilot. @@ -66,4 +67,45 @@ const result = reduceThreadActivity(initialState, action); expect(result).toEqual(expectedState); }); + + test('removes threads of keyserver the user has disconnected from', () => { + const keyserver1 = '100'; + const keyserver2 = '200'; + const keyserver3 = '300'; + const threads1 = { + [keyserver1 + '|1']: { lastNavigatedTo: 1, lastPruned: 1 }, + [keyserver1 + '|2']: { lastNavigatedTo: 1, lastPruned: 1 }, + }; + const threads2 = { + [keyserver2 + '|1']: { lastNavigatedTo: 1, lastPruned: 1 }, + [keyserver2 + '|2']: { lastNavigatedTo: 1, lastPruned: 1 }, + }; + const threads3 = { + [keyserver3 + '|1']: { lastNavigatedTo: 1, lastPruned: 1 }, + [keyserver3 + '|2']: { lastNavigatedTo: 1, lastPruned: 1 }, + }; + + const threads = { ...threads1, ...threads2, ...threads3 }; + const action = { + type: deleteKeyserverAccountActionTypes.success, + payload: { + currentUserInfo: { anonymous: true }, + preRequestUserState: { + cookiesAndSessions: {}, + currentUserInfo: { + id: '83810', + username: 'user1', + }, + }, + keyserverIDs: [keyserver1, keyserver2], + }, + loadingInfo: { + fetchIndex: 1, + trackMultipleRequests: false, + customKeyName: undefined, + }, + }; + + expect(reduceThreadActivity(threads, action)).toEqual(threads3); + }); });