diff --git a/lib/ops/keyserver-store-ops.js b/lib/ops/keyserver-store-ops.js --- a/lib/ops/keyserver-store-ops.js +++ b/lib/ops/keyserver-store-ops.js @@ -8,6 +8,7 @@ import type { KeyserverInfo, KeyserverInfos, + KeyserverStore, } from '../types/keyserver-types.js'; // client types @@ -69,21 +70,21 @@ } const keyserverStoreOpsHandlers: BaseStoreOpsHandlers< - KeyserverInfos, + KeyserverStore, KeyserverStoreOperation, ClientDBKeyserverStoreOperation, KeyserverInfos, ClientDBKeyserverInfo, > = { processStoreOperations( - keyserverInfos: KeyserverInfos, + keyserverStore: KeyserverStore, ops: $ReadOnlyArray, - ): KeyserverInfos { + ): KeyserverStore { if (ops.length === 0) { - return keyserverInfos; + return keyserverStore; } - let processedKeyserverInfos = { ...keyserverInfos }; + let processedKeyserverInfos = { ...keyserverStore.keyserverInfos }; for (const operation: KeyserverStoreOperation of ops) { if (operation.type === 'replace_keyserver') { processedKeyserverInfos[operation.payload.id] = @@ -96,7 +97,7 @@ processedKeyserverInfos = {}; } } - return processedKeyserverInfos; + return { ...keyserverStore, keyserverInfos: processedKeyserverInfos }; }, convertOpsToClientDBOps( 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 @@ -68,12 +68,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [ - replaceOperation, - ]), - }, + keyserverStore: processStoreOps(state, [replaceOperation]), keyserverStoreOperations: [replaceOperation], }; } else if (action.type === removeKeyserverActionType) { @@ -85,12 +80,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [ - removeOperation, - ]), - }, + keyserverStore: processStoreOps(state, [removeOperation]), keyserverStoreOperations: [removeOperation], }; } else if (action.type === resetUserStateActionType) { @@ -114,13 +104,7 @@ } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps( - state.keyserverInfos, - replaceOperations, - ), - }, + keyserverStore: processStoreOps(state, replaceOperations), keyserverStoreOperations: replaceOperations, }; } else if (action.type === setNewSessionActionType) { @@ -187,10 +171,7 @@ } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if ( @@ -219,10 +200,7 @@ }); } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if (action.type === fullStateSyncActionType) { @@ -239,10 +217,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === incrementalStateSyncActionType) { @@ -270,10 +245,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === processUpdatesActionType) { @@ -293,10 +265,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === setURLPrefix) { @@ -311,10 +280,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === updateLastCommunicatedPlatformDetailsActionType) { @@ -330,10 +296,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === keyserverRegisterActionTypes.success) { @@ -348,10 +311,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === updateConnectionStatusActionType) { @@ -371,10 +331,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === unsupervisedBackgroundActionType) { @@ -394,10 +351,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === queueActivityUpdatesActionType) { @@ -435,10 +389,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === updateActivityActionTypes.success) { @@ -464,10 +415,7 @@ }); } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if ( @@ -497,10 +445,7 @@ }); return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if (action.type === deleteKeyserverAccountActionTypes.success) { @@ -531,10 +476,7 @@ } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if (action.type === setLateResponseActionType) { @@ -562,10 +504,7 @@ }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === updateKeyserverReachabilityActionType) { @@ -584,10 +523,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === setDeviceTokenActionTypes.success) { @@ -606,10 +542,7 @@ }); } return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, operations), - }, + keyserverStore: processStoreOps(state, operations), keyserverStoreOperations: operations, }; } else if (action.type === setConnectionIssueActionType) { @@ -628,10 +561,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } else if (action.type === setSessionRecoveryInProgressActionType) { @@ -650,10 +580,7 @@ }, }; return { - keyserverStore: { - ...state, - keyserverInfos: processStoreOps(state.keyserverInfos, [operation]), - }, + keyserverStore: processStoreOps(state, [operation]), keyserverStoreOperations: [operation], }; } diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -130,15 +130,11 @@ }); } } - if (replaceOperations.length > 0) { - keyserverStore = { - ...keyserverStore, - keyserverInfos: keyserverStoreOpsHandlers.processStoreOperations( - keyserverStore.keyserverInfos, - replaceOperations, - ), - }; - } + + keyserverStore = keyserverStoreOpsHandlers.processStoreOperations( + keyserverStore, + replaceOperations, + ); } const { draftStore, draftStoreOperations } = reduceDraftStore( diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -166,13 +166,10 @@ ...state, ...rest, userStore: { userInfos }, - keyserverStore: { - ...state.keyserverStore, - keyserverInfos: keyserverStoreOpsHandlers.processStoreOperations( - state.keyserverStore.keyserverInfos, - replaceOperations, - ), - }, + keyserverStore: keyserverStoreOpsHandlers.processStoreOperations( + state.keyserverStore, + replaceOperations, + ), initialStateLoaded: true, }, storeOperations, @@ -233,13 +230,10 @@ }; state = { ...state, - keyserverStore: { - ...state.keyserverStore, - keyserverInfos: keyserverStoreOpsHandlers.processStoreOperations( - state.keyserverStore.keyserverInfos, - [replaceOperation], - ), - }, + keyserverStore: keyserverStoreOpsHandlers.processStoreOperations( + state.keyserverStore, + [replaceOperation], + ), }; } else if (action.type === deleteKeyserverAccountActionTypes.success) { const { currentUserInfo, preRequestUserState } = action.payload;