diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -15,6 +15,11 @@ convertCalendarFilterToNewIDSchema, convertConnectionInfoToNewIDSchema, } from 'lib/_generated/migration-utils.js'; +import { + type ClientDBKeyserverStoreOperation, + keyserverStoreOpsHandlers, + type ReplaceKeyserverOperation, +} from 'lib/ops/keyserver-store-ops.js'; import { type ClientDBMessageStoreOperation, messageStoreOpsHandlers, @@ -83,6 +88,7 @@ convertMessageStoreThreadsToNewIDSchema, convertThreadStoreThreadInfosToNewIDSchema, } from 'lib/utils/migration-utils.js'; +import { entries } from 'lib/utils/objects.js'; import { defaultNotifPermissionAlertInfo } from 'lib/utils/push-alerts.js'; import { resetUserSpecificState } from 'lib/utils/reducers-utils.js'; import { @@ -1044,6 +1050,33 @@ handleReduxMigrationFailure, ); }, + [62]: async (state: AppState) => { + const replaceOps: $ReadOnlyArray = entries( + state.keyserverStore.keyserverInfos, + ).map(([id, keyserverInfo]) => ({ + type: 'replace_keyserver', + payload: { + id, + keyserverInfo, + }, + })); + + const dbOperations: $ReadOnlyArray = + keyserverStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_keyservers' }, + ...replaceOps, + ]); + + try { + await commCoreModule.processKeyserverStoreOperations(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` @@ -1111,7 +1144,7 @@ storage: AsyncStorage, blacklist: persistBlacklist, debug: __DEV__, - version: 61, + version: 62, 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 ClientDBKeyserverStoreOperation, + keyserverStoreOpsHandlers, + type ReplaceKeyserverOperation, +} from 'lib/ops/keyserver-store-ops.js'; import { createAsyncMigrate, type StorageMigrationFunction, @@ -21,6 +26,7 @@ generateIDSchemaMigrationOpsForDrafts, convertDraftStoreToNewIDSchema, } from 'lib/utils/migration-utils.js'; +import { entries } from 'lib/utils/objects.js'; import { resetUserSpecificState } from 'lib/utils/reducers-utils.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; @@ -44,7 +50,6 @@ 'customServer', ]; -// eslint-disable-next-line no-unused-vars function handleReduxMigrationFailure(oldState: AppState): AppState { const persistedNonUserSpecificFields = nonUserSpecificFieldsWeb.filter( field => persistWhitelist.includes(field) || field === '_persist', @@ -222,6 +227,40 @@ }, }; }, + [11]: async (state: AppState) => { + const databaseModule = await getDatabaseModule(); + const isDatabaseSupported = await databaseModule.isDatabaseSupported(); + if (!isDatabaseSupported) { + return state; + } + + const replaceOps: $ReadOnlyArray = entries( + state.keyserverStore.keyserverInfos, + ).map(([id, keyserverInfo]) => ({ + type: 'replace_keyserver', + payload: { + id, + keyserverInfo, + }, + })); + + const keyserverStoreOperations: $ReadOnlyArray = + keyserverStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_keyservers' }, + ...replaceOps, + ]); + + try { + await databaseModule.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { keyserverStoreOperations }, + }); + return state; + } catch (e) { + console.log(e); + return handleReduxMigrationFailure(state); + } + }, }; const rootKey = 'root'; @@ -268,7 +307,7 @@ { debug: isDev }, migrateStorageToSQLite, ): any), - version: 10, + version: 11, transforms: [keyserverStoreTransform], };