Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3526050
D10883.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D10883.diff
View Options
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
@@ -28,7 +28,7 @@
type KeyserverStoreOperation,
} from '../ops/keyserver-store-ops.js';
import { queueActivityUpdatesActionType } from '../types/activity-types.js';
-import type { KeyserverStore, KeyserverInfos } from '../types/keyserver-types';
+import type { KeyserverStore } from '../types/keyserver-types.js';
import type { BaseAction } from '../types/redux-types.js';
import {
fullStateSyncActionType,
@@ -421,36 +421,35 @@
keyserverInfos: processStoreOps(state.keyserverInfos, operations),
};
} else if (action.type === deleteKeyserverAccountActionTypes.success) {
- const keyserverIDsToRemove = new Set<string>(action.payload.keyserverIDs);
- const newKeyserverInfos: { ...KeyserverInfos } = {};
-
- const { keyserverInfos } = state;
-
- for (const keyserverID in keyserverInfos) {
- if (!keyserverIDsToRemove.has(keyserverID)) {
- newKeyserverInfos[keyserverID] = keyserverInfos[keyserverID];
- continue;
- }
- if (keyserverID === ashoatKeyserverID) {
- const oldConnection =
- state.keyserverInfos[ashoatKeyserverID].connection;
-
- newKeyserverInfos[ashoatKeyserverID] = {
- ...state.keyserverInfos[ashoatKeyserverID],
- connection: {
- ...oldConnection,
- connectionIssue: null,
- queuedActivityUpdates: [],
- lateResponses: [],
+ const operations: KeyserverStoreOperation[] = [
+ {
+ type: 'remove_keyservers',
+ payload: { ids: action.payload.keyserverIDs },
+ },
+ ];
+ if (action.payload.keyserverIDs.includes(ashoatKeyserverID)) {
+ const oldConnection = state.keyserverInfos[ashoatKeyserverID].connection;
+ operations.push({
+ type: 'replace_keyserver',
+ payload: {
+ id: ashoatKeyserverID,
+ keyserverInfo: {
+ ...state.keyserverInfos[ashoatKeyserverID],
+ connection: {
+ ...oldConnection,
+ connectionIssue: null,
+ queuedActivityUpdates: [],
+ lateResponses: [],
+ },
+ cookie: null,
},
- cookie: null,
- };
- }
+ },
+ });
}
return {
...state,
- keyserverInfos: newKeyserverInfos,
+ keyserverInfos: processStoreOps(state.keyserverInfos, operations),
};
} 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
--- a/lib/reducers/keyserver-reducer.test.js
+++ b/lib/reducers/keyserver-reducer.test.js
@@ -3,6 +3,7 @@
import reduceKeyserverStore from './keyserver-reducer.js';
import { deleteKeyserverAccountActionTypes } from '../actions/user-actions.js';
import { defaultKeyserverInfo } from '../types/keyserver-types.js';
+import { ashoatKeyserverID } from '../utils/validation-utils.js';
describe('reduceKeyserverStore', () => {
it('removes from the store keyservers the user has disconnected from', () => {
@@ -38,4 +39,83 @@
reduceKeyserverStore(oldKeyserverStore, deleteAccountAction),
).toEqual({ keyserverInfos: { ['0']: defaultKeyserverInfo('url1') } });
});
+ it('update keyserverInfo with ashoatKeyserverID', () => {
+ const defaultAshoatKeyserverInfo = defaultKeyserverInfo('url1');
+ const oldKeyserverStore = {
+ keyserverInfos: {
+ [ashoatKeyserverID]: {
+ ...defaultAshoatKeyserverInfo,
+ connection: {
+ ...defaultAshoatKeyserverInfo.connection,
+ connectionIssue: 'not_logged_in_error',
+ },
+ },
+ },
+ };
+
+ const deleteAccountAction = {
+ type: deleteKeyserverAccountActionTypes.success,
+ payload: {
+ currentUserInfo: { anonymous: true },
+ preRequestUserState: {
+ cookiesAndSessions: {},
+ currentUserInfo: {
+ id: '1000',
+ username: 'test',
+ },
+ },
+ keyserverIDs: [ashoatKeyserverID],
+ },
+ loadingInfo: {
+ fetchIndex: 1,
+ trackMultipleRequests: false,
+ customKeyName: undefined,
+ },
+ };
+
+ expect(
+ reduceKeyserverStore(oldKeyserverStore, deleteAccountAction)
+ .keyserverInfos[ashoatKeyserverID].connection.connectionIssue,
+ ).toEqual(null);
+ });
+
+ it('return the same keyserverInfo with ashoatKeyserverID', () => {
+ const defaultAshoatKeyserverInfo = defaultKeyserverInfo('url1');
+ const oldKeyserverStore = {
+ keyserverInfos: {
+ [ashoatKeyserverID]: {
+ ...defaultAshoatKeyserverInfo,
+ connection: {
+ ...defaultAshoatKeyserverInfo.connection,
+ connectionIssue: 'not_logged_in_error',
+ },
+ },
+ },
+ };
+
+ 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)
+ .keyserverInfos[ashoatKeyserverID].connection.connectionIssue,
+ ).toEqual('not_logged_in_error');
+ });
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 7:26 PM (8 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700889
Default Alt Text
D10883.diff (5 KB)
Attached To
Mode
D10883: [lib] refactor deleting keyserver account `keyserver-reducer` to ops
Attached
Detach File
Event Timeline
Log In to Comment