diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -46,6 +46,7 @@ "messages_to_device", "integrity_store", "persist_storage", + "keyservers", }; #else SQLiteConnectionManager SQLiteQueryExecutor::connectionManager; @@ -602,7 +603,23 @@ " id TEXT UNIQUE PRIMARY KEY NOT NULL," " keyserver_info TEXT NOT NULL" ");"; - return create_table(db, query, "keyservers_synced"); + bool success = create_table(db, query, "keyservers_synced"); + if (!success) { + return false; + } + + std::string copyData = + "INSERT INTO keyservers_synced (id, keyserver_info)" + "SELECT id, keyserver_info " + "FROM keyservers;"; + + char *error; + sqlite3_exec(db, copyData.c_str(), nullptr, nullptr, &error); + if (error) { + return false; + } + + return true; } bool create_schema(sqlite3 *db) { diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -1160,6 +1160,45 @@ } return state; }, + [66]: async (state: AppState) => { + const stores = await commCoreModule.getClientDBStore(); + const keyserversDBInfo = stores.keyservers; + + const { translateClientDBData } = keyserverStoreOpsHandlers; + const keyservers = translateClientDBData(keyserversDBInfo); + + // There is no modification of the keyserver data, but the ops handling + // should correctly split the data between synced and non-synced tables + + const replaceOps: $ReadOnlyArray = entries( + keyservers, + ).map(([id, keyserverInfo]) => ({ + type: 'replace_keyserver', + payload: { + id, + keyserverInfo, + }, + })); + + const keyserverStoreOperations: $ReadOnlyArray = + keyserverStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_keyservers' }, + ...replaceOps, + ]); + + try { + await commCoreModule.processKeyserverStoreOperations( + keyserverStoreOperations, + ); + } catch (exception) { + if (isTaskCancelledError(exception)) { + return state; + } + return handleReduxMigrationFailure(state); + } + + return state; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -1227,7 +1266,7 @@ storage: AsyncStorage, blacklist: persistBlacklist, debug: __DEV__, - version: 65, + version: 66, 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 @@ -321,6 +321,55 @@ }); return rest; }, + [14]: async (state: AppState) => { + const sharedWorker = await getCommSharedWorker(); + const isSupported = await sharedWorker.isSupported(); + + if (!isSupported) { + return state; + } + + const stores = await sharedWorker.schedule({ + type: workerRequestMessageTypes.GET_CLIENT_STORE, + }); + const keyserversDBInfo = stores?.store?.keyservers; + if (!keyserversDBInfo) { + return state; + } + + const { translateClientDBData } = keyserverStoreOpsHandlers; + const keyservers = translateClientDBData(keyserversDBInfo); + + // There is no modification of the keyserver data, but the ops handling + // should correctly split the data between synced and non-synced tables + + const replaceOps: $ReadOnlyArray = entries( + keyservers, + ).map(([id, keyserverInfo]) => ({ + type: 'replace_keyserver', + payload: { + id, + keyserverInfo, + }, + })); + + const keyserverStoreOperations: $ReadOnlyArray = + keyserverStoreOpsHandlers.convertOpsToClientDBOps([ + { type: 'remove_all_keyservers' }, + ...replaceOps, + ]); + + try { + await sharedWorker.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { keyserverStoreOperations }, + }); + return state; + } catch (e) { + console.log(e); + return handleReduxMigrationFailure(state); + } + }, }; const migrateStorageToSQLite: StorageMigrationFunction = async debug => { @@ -366,7 +415,7 @@ { debug: isDev }, migrateStorageToSQLite, ): any), - version: 13, + version: 14, transforms: [keyserverStoreTransform], }; diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@