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, @@ -82,6 +87,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 { deprecatedConvertClientDBThreadInfoToRawThreadInfo, @@ -1004,6 +1010,33 @@ minimallyEncodeThreadInfosFunc, ); }, + [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 { ...state, cookie: null }; + } + return state; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -1082,7 +1115,7 @@ 'connection', ], 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, @@ -20,6 +25,7 @@ generateIDSchemaMigrationOpsForDrafts, convertDraftStoreToNewIDSchema, } from 'lib/utils/migration-utils.js'; +import { entries } from 'lib/utils/objects.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import commReduxStorageEngine from './comm-redux-storage-engine.js'; @@ -192,6 +198,35 @@ }, }; }, + [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, + ]); + + await databaseModule.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { keyserverStoreOperations }, + }); + return state; + }, }; const persistWhitelist = [ @@ -248,7 +283,7 @@ { debug: isDev }, migrateStorageToSQLite, ): any), - version: 10, + version: 11, transforms: [keyserverStoreTransform], };