diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -721,14 +721,14 @@ const draftOperations = generateIDSchemaMigrationOpsForDrafts(drafts); try { - await Promise.all([ - commCoreModule.processMessageStoreOperations([ + await commCoreModule.processDBStoreOperations({ + messageStoreOperations: [ ...messageStoreMessagesOperations, ...messageStoreThreadsOperations, - ]), - commCoreModule.processThreadStoreOperations(threadOperations), - commCoreModule.processDraftStoreOperations(draftOperations), - ]); + ], + threadStoreOperations: threadOperations, + draftStoreOperations: draftOperations, + }); } catch (exception) { console.log(exception); return { ...state, cookie: null }; @@ -994,7 +994,9 @@ userStoreOpsHandlers.convertOpsToClientDBOps(userStoreOperations); try { - await commCoreModule.processUserStoreOperations(dbOperations); + await commCoreModule.processDBStoreOperations({ + userStoreOperations: dbOperations, + }); } catch (exception) { if (isTaskCancelledError(exception)) { return state; @@ -1096,7 +1098,9 @@ ]); try { - await commCoreModule.processKeyserverStoreOperations(dbOperations); + await commCoreModule.processDBStoreOperations({ + keyserverStoreOperations: dbOperations, + }); } catch (exception) { if (isTaskCancelledError(exception)) { return state; @@ -1136,7 +1140,9 @@ ), }; try { - await commCoreModule.processKeyserverStoreOperations(dbOperations); + await commCoreModule.processDBStoreOperations({ + keyserverStoreOperations: dbOperations, + }); } catch (exception) { if (isTaskCancelledError(exception)) { return newState; @@ -1164,7 +1170,9 @@ ]); try { - await commCoreModule.processIntegrityStoreOperations(dbOperations); + await commCoreModule.processDBStoreOperations({ + integrityStoreOperations: dbOperations, + }); } catch (exception) { if (isTaskCancelledError(exception)) { return state; @@ -1200,9 +1208,9 @@ ]); try { - await commCoreModule.processKeyserverStoreOperations( + await commCoreModule.processDBStoreOperations({ keyserverStoreOperations, - ); + }); } catch (exception) { if (isTaskCancelledError(exception)) { return state; @@ -1277,7 +1285,9 @@ ]); try { - await commCoreModule.processThreadActivityStoreOperations(dbOperations); + await commCoreModule.processDBStoreOperations({ + threadActivityStoreOperations: dbOperations, + }); } catch (exception) { if (isTaskCancelledError(exception)) { return 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 @@ -16,6 +16,7 @@ import { threadStoreOpsHandlers } from 'lib/ops/thread-store-ops.js'; import { userStoreOpsHandlers } from 'lib/ops/user-store-ops.js'; import type { StoreOperations } from 'lib/types/store-ops-types.js'; +import { values } from 'lib/utils/objects.js'; import type { AppState } from './state-types.js'; import { commCoreModule } from '../native-modules.js'; @@ -74,51 +75,6 @@ try { const promises = []; - if (convertedThreadStoreOperations.length > 0) { - promises.push( - commCoreModule.processThreadStoreOperations( - convertedThreadStoreOperations, - ), - ); - } - if (convertedMessageStoreOperations.length > 0) { - promises.push( - commCoreModule.processMessageStoreOperations( - convertedMessageStoreOperations, - ), - ); - } - if (draftStoreOperations.length > 0) { - promises.push( - commCoreModule.processDraftStoreOperations(draftStoreOperations), - ); - } - if (convertedReportStoreOperations.length > 0) { - promises.push( - commCoreModule.processReportStoreOperations( - convertedReportStoreOperations, - ), - ); - } - if (convertedUserStoreOperations.length > 0) { - promises.push( - commCoreModule.processUserStoreOperations(convertedUserStoreOperations), - ); - } - if (convertedKeyserverStoreOperations.length > 0) { - promises.push( - commCoreModule.processKeyserverStoreOperations( - convertedKeyserverStoreOperations, - ), - ); - } - if (convertedCommunityStoreOperations.length > 0) { - promises.push( - commCoreModule.processCommunityStoreOperations( - convertedCommunityStoreOperations, - ), - ); - } if (keyserversToRemoveFromNotifsStore.length > 0) { promises.push( commCoreModule.removeKeyserverDataFromNotifStorage( @@ -126,33 +82,22 @@ ), ); } - if (convertedIntegrityStoreOperations.length > 0) { - promises.push( - commCoreModule.processIntegrityStoreOperations( - convertedIntegrityStoreOperations, - ), - ); - } - if (convertedSyncedMetadataStoreOperations.length > 0) { - promises.push( - commCoreModule.processSyncedMetadataStoreOperations( - convertedSyncedMetadataStoreOperations, - ), - ); - } - if (convertedAuxUserStoreOperations.length > 0) { - promises.push( - commCoreModule.processAuxUserStoreOperations( - convertedAuxUserStoreOperations, - ), - ); - } - if (convertedThreadActivityStoreOperations.length > 0) { - promises.push( - commCoreModule.processThreadActivityStoreOperations( - convertedThreadActivityStoreOperations, - ), - ); + + const dbOps = { + draftStoreOperations, + threadStoreOperations: convertedThreadStoreOperations, + messageStoreOperations: convertedMessageStoreOperations, + reportStoreOperations: convertedReportStoreOperations, + userStoreOperations: convertedUserStoreOperations, + keyserverStoreOperations: convertedKeyserverStoreOperations, + communityStoreOperations: convertedCommunityStoreOperations, + integrityStoreOperations: convertedIntegrityStoreOperations, + syncedMetadataStoreOperations: convertedSyncedMetadataStoreOperations, + auxUserStoreOperations: convertedAuxUserStoreOperations, + threadActivityStoreOperations: convertedThreadActivityStoreOperations, + }; + if (values(dbOps).some(ops => ops.length > 0)) { + promises.push(commCoreModule.processDBStoreOperations(dbOps)); } await Promise.all(promises); } catch (e) {