Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3525640
D10661.id35723.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10661.id35723.diff
View Options
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
@@ -18,6 +18,7 @@
logOutActionTypes,
deleteKeyserverAccountActionTypes,
} 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';
@@ -91,9 +92,23 @@
return updatedState;
} else if (
action.type === logOutActionTypes.success ||
- action.type === deleteKeyserverAccountActionTypes.success ||
- (action.type === setNewSessionActionType &&
- action.payload.sessionChange.cookieInvalidated)
+ action.type === deleteKeyserverAccountActionTypes.success
+ ) {
+ let updatedState = { ...state };
+ const keyserverIDsSet = new Set<string>(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 === setNewSessionActionType &&
+ action.payload.sessionChange.cookieInvalidated
) {
return {};
}
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);
+ });
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 5:55 PM (15 m, 16 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700641
Default Alt Text
D10661.id35723.diff (3 KB)
Attached To
Mode
D10661: [lib] Refactor logout in thread activity reducer
Attached
Detach File
Event Timeline
Log In to Comment