diff --git a/lib/ops/aux-user-store-ops.js b/lib/ops/aux-user-store-ops.js --- a/lib/ops/aux-user-store-ops.js +++ b/lib/ops/aux-user-store-ops.js @@ -90,8 +90,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(operation => { if ( operation.type === 'remove_aux_user_infos' || diff --git a/lib/ops/base-ops.js b/lib/ops/base-ops.js --- a/lib/ops/base-ops.js +++ b/lib/ops/base-ops.js @@ -12,7 +12,7 @@ ops: $ReadOnlyArray, ) => Store, convertOpsToClientDBOps: ( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ) => $ReadOnlyArray, translateClientDBData: (data: $ReadOnlyArray) => DataType, }; diff --git a/lib/ops/community-store-ops.js b/lib/ops/community-store-ops.js --- a/lib/ops/community-store-ops.js +++ b/lib/ops/community-store-ops.js @@ -90,8 +90,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(operation => { if ( operation.type === 'remove_communities' || diff --git a/lib/ops/integrity-store-ops.js b/lib/ops/integrity-store-ops.js --- a/lib/ops/integrity-store-ops.js +++ b/lib/ops/integrity-store-ops.js @@ -82,8 +82,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } const convertedOperations = ops.map(integrityStoreOperation => { if ( integrityStoreOperation.type === 'remove_all_integrity_thread_hashes' || 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 @@ -139,8 +139,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(operation => { if ( operation.type === 'remove_keyservers' || diff --git a/lib/ops/message-store-ops.js b/lib/ops/message-store-ops.js --- a/lib/ops/message-store-ops.js +++ b/lib/ops/message-store-ops.js @@ -143,8 +143,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } const convertedOperations = ops.map(messageStoreOperation => { if (messageStoreOperation.type === 'replace') { return { diff --git a/lib/ops/report-store-ops.js b/lib/ops/report-store-ops.js --- a/lib/ops/report-store-ops.js +++ b/lib/ops/report-store-ops.js @@ -88,8 +88,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(operation => { if ( operation.type === 'remove_reports' || diff --git a/lib/ops/synced-metadata-store-ops.js b/lib/ops/synced-metadata-store-ops.js --- a/lib/ops/synced-metadata-store-ops.js +++ b/lib/ops/synced-metadata-store-ops.js @@ -77,8 +77,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops; }, diff --git a/lib/ops/thread-activity-store-ops.js b/lib/ops/thread-activity-store-ops.js --- a/lib/ops/thread-activity-store-ops.js +++ b/lib/ops/thread-activity-store-ops.js @@ -94,8 +94,11 @@ return processedThreadActivityStore; }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(threadActivityStoreOperation => { if ( threadActivityStoreOperation.type === diff --git a/lib/ops/thread-store-ops.js b/lib/ops/thread-store-ops.js --- a/lib/ops/thread-store-ops.js +++ b/lib/ops/thread-store-ops.js @@ -71,8 +71,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(threadStoreOperation => { if (threadStoreOperation.type === 'replace') { return { diff --git a/lib/ops/user-store-ops.js b/lib/ops/user-store-ops.js --- a/lib/ops/user-store-ops.js +++ b/lib/ops/user-store-ops.js @@ -87,8 +87,11 @@ }, convertOpsToClientDBOps( - ops: $ReadOnlyArray, + ops: ?$ReadOnlyArray, ): $ReadOnlyArray { + if (!ops) { + return []; + } return ops.map(operation => { if ( operation.type === 'remove_users' || diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js --- a/lib/types/store-ops-types.js +++ b/lib/types/store-ops-types.js @@ -67,17 +67,17 @@ } from '../ops/user-store-ops.js'; export type StoreOperations = { - +draftStoreOperations: $ReadOnlyArray, - +threadStoreOperations: $ReadOnlyArray, - +messageStoreOperations: $ReadOnlyArray, - +reportStoreOperations: $ReadOnlyArray, - +userStoreOperations: $ReadOnlyArray, - +keyserverStoreOperations: $ReadOnlyArray, - +communityStoreOperations: $ReadOnlyArray, - +integrityStoreOperations: $ReadOnlyArray, - +syncedMetadataStoreOperations: $ReadOnlyArray, - +auxUserStoreOperations: $ReadOnlyArray, - +threadActivityStoreOperations: $ReadOnlyArray, + +draftStoreOperations?: $ReadOnlyArray, + +threadStoreOperations?: $ReadOnlyArray, + +messageStoreOperations?: $ReadOnlyArray, + +reportStoreOperations?: $ReadOnlyArray, + +userStoreOperations?: $ReadOnlyArray, + +keyserverStoreOperations?: $ReadOnlyArray, + +communityStoreOperations?: $ReadOnlyArray, + +integrityStoreOperations?: $ReadOnlyArray, + +syncedMetadataStoreOperations?: $ReadOnlyArray, + +auxUserStoreOperations?: $ReadOnlyArray, + +threadActivityStoreOperations?: $ReadOnlyArray, }; export type ClientDBStoreOperations = { diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -299,40 +299,18 @@ state = baseReducerResult.state; const { storeOperations } = baseReducerResult; - const { - draftStoreOperations, - threadStoreOperations, - messageStoreOperations, - reportStoreOperations, - userStoreOperations, - keyserverStoreOperations, - communityStoreOperations, - integrityStoreOperations, - syncedMetadataStoreOperations, - auxUserStoreOperations, - threadActivityStoreOperations, - } = storeOperations; const fixUnreadActiveThreadResult = fixUnreadActiveThread(state, action); state = fixUnreadActiveThreadResult.state; const threadStoreOperationsWithUnreadFix = [ - ...threadStoreOperations, + ...(storeOperations.threadStoreOperations ?? []), ...fixUnreadActiveThreadResult.threadStoreOperations, ]; const ops = { - draftStoreOperations, - messageStoreOperations, + ...storeOperations, threadStoreOperations: threadStoreOperationsWithUnreadFix, - reportStoreOperations, - userStoreOperations, - keyserverStoreOperations, - communityStoreOperations, - integrityStoreOperations, - syncedMetadataStoreOperations, - auxUserStoreOperations, - threadActivityStoreOperations, }; state = { ...state, diff --git a/native/redux/redux-utils.js b/native/redux/redux-utils.js --- a/native/redux/redux-utils.js +++ b/native/redux/redux-utils.js @@ -63,7 +63,7 @@ syncedMetadataStoreOperations, ); const keyserversToRemoveFromNotifsStore = - getKeyserversToRemoveFromNotifsStore(keyserverStoreOperations); + getKeyserversToRemoveFromNotifsStore(keyserverStoreOperations ?? []); const convertedIntegrityStoreOperations = integrityStoreOpsHandlers.convertOpsToClientDBOps(integrityStoreOperations); const convertedAuxUserStoreOperations = @@ -96,7 +96,7 @@ auxUserStoreOperations: convertedAuxUserStoreOperations, threadActivityStoreOperations: convertedThreadActivityStoreOperations, }; - if (values(dbOps).some(ops => ops.length > 0)) { + if (values(dbOps).some(ops => ops && ops.length > 0)) { promises.push(commCoreModule.processDBStoreOperations(dbOps)); } await Promise.all(promises); 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 @@ -157,19 +157,7 @@ function reducer(oldState: AppState | void, action: Action): AppState { invariant(oldState, 'should be set'); let state = oldState; - let storeOperations: StoreOperations = { - draftStoreOperations: [], - threadStoreOperations: [], - messageStoreOperations: [], - reportStoreOperations: [], - userStoreOperations: [], - keyserverStoreOperations: [], - communityStoreOperations: [], - integrityStoreOperations: [], - syncedMetadataStoreOperations: [], - auxUserStoreOperations: [], - threadActivityStoreOperations: [], - }; + let storeOperations: StoreOperations = {}; if ( (action.type === setNewSessionActionType && @@ -237,7 +225,7 @@ return validateStateAndQueueOpsProcessing(action, oldState, newState, { ...storeOperations, keyserverStoreOperations: [ - ...storeOperations.keyserverStoreOperations, + ...(storeOperations.keyserverStoreOperations ?? []), ...replaceOperations, ], }); @@ -307,7 +295,7 @@ storeOperations = { ...storeOperations, keyserverStoreOperations: [ - ...storeOperations.keyserverStoreOperations, + ...(storeOperations.keyserverStoreOperations ?? []), replaceOperation, ], }; @@ -375,8 +363,8 @@ storeOperations = { ...baseReducerResult.storeOperations, keyserverStoreOperations: [ - ...storeOperations.keyserverStoreOperations, - ...baseReducerResult.storeOperations.keyserverStoreOperations, + ...(storeOperations.keyserverStoreOperations ?? []), + ...(baseReducerResult.storeOperations.keyserverStoreOperations ?? []), ], }; } @@ -516,7 +504,7 @@ storeOperations = { ...storeOperations, threadActivityStoreOperations: [ - ...storeOperations.threadActivityStoreOperations, + ...(storeOperations.threadActivityStoreOperations ?? []), replaceOperation, ], }; @@ -533,7 +521,7 @@ storeOperations = { ...storeOperations, threadStoreOperations: [ - ...storeOperations.threadStoreOperations, + ...(storeOperations.threadStoreOperations ?? []), ...updateActiveThreadOps, ], }; diff --git a/web/shared-worker/utils/store.js b/web/shared-worker/utils/store.js --- a/web/shared-worker/utils/store.js +++ b/web/shared-worker/utils/store.js @@ -187,7 +187,7 @@ if ( convertedThreadStoreOperations.length === 0 && convertedReportStoreOperations.length === 0 && - draftStoreOperations.length === 0 && + (!draftStoreOperations || draftStoreOperations.length === 0) && convertedKeyserverStoreOperations.length === 0 && convertedCommunityStoreOperations.length === 0 && convertedIntegrityStoreOperations.length === 0 &&