diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -16,6 +16,11 @@ convertConnectionInfoToNewIDSchema, } from 'lib/_generated/migration-utils.js'; import { extractKeyserverIDFromID } from 'lib/keyserver-conn/keyserver-call-utils.js'; +import { + type ClientDBIntegrityStoreOperation, + integrityStoreOpsHandlers, + type ReplaceIntegrityThreadHashesOperation, +} from 'lib/ops/integrity-store-ops.js'; import { type ClientDBKeyserverStoreOperation, keyserverStoreOpsHandlers, @@ -1125,6 +1130,30 @@ } return newState; }, + [64]: async (state: AppState) => { + const replaceOp: ReplaceIntegrityThreadHashesOperation = { + type: 'replace_integrity_thread_hashes', + payload: { + threadHashes: state.integrityStore.threadHashes, + }, + }; + + const dbOperations: $ReadOnlyArray = + integrityStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_integrity_thread_hashes' }, + replaceOp, + ]); + + try { + await commCoreModule.processIntegrityStoreOperations(dbOperations); + } catch (exception) { + if (isTaskCancelledError(exception)) { + return state; + } + return handleReduxMigrationFailure(state); + } + return state; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -1192,7 +1221,7 @@ storage: AsyncStorage, blacklist: persistBlacklist, debug: __DEV__, - version: 63, + version: 64, transforms: [ messageStoreMessagesBlocklistTransform, reportStoreTransform, diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -5,6 +5,11 @@ import storage from 'redux-persist/es/storage/index.js'; import type { PersistConfig } from 'redux-persist/src/types.js'; +import { + type ClientDBIntegrityStoreOperation, + integrityStoreOpsHandlers, + type ReplaceIntegrityThreadHashesOperation, +} from 'lib/ops/integrity-store-ops.js'; import { type ClientDBKeyserverStoreOperation, keyserverStoreOpsHandlers, @@ -262,6 +267,37 @@ return handleReduxMigrationFailure(state); } }, + [12]: async (state: AppState) => { + const databaseModule = await getDatabaseModule(); + const isDatabaseSupported = await databaseModule.isDatabaseSupported(); + if (!isDatabaseSupported) { + return state; + } + + const replaceOp: ReplaceIntegrityThreadHashesOperation = { + type: 'replace_integrity_thread_hashes', + payload: { + threadHashes: state.integrityStore.threadHashes, + }, + }; + + const integrityStoreOperations: $ReadOnlyArray = + integrityStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_integrity_thread_hashes' }, + replaceOp, + ]); + + try { + await databaseModule.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { integrityStoreOperations }, + }); + return state; + } catch (e) { + console.log(e); + return handleReduxMigrationFailure(state); + } + }, }; const migrateStorageToSQLite: StorageMigrationFunction = async debug => { @@ -307,7 +343,7 @@ { debug: isDev }, migrateStorageToSQLite, ): any), - version: 11, + version: 12, transforms: [keyserverStoreTransform], };