diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js --- a/lib/types/store-ops-types.js +++ b/lib/types/store-ops-types.js @@ -12,7 +12,10 @@ import type { ClientReportCreationRequest } from './report-types.js'; import type { ClientDBThreadInfo, ThreadStore } from './thread-types.js'; import type { UserInfos } from './user-types.js'; -import type { ClientDBKeyserverInfo } from '../ops/keyserver-store-ops.js'; +import type { + ClientDBKeyserverInfo, + ClientDBKeyserverStoreOperation, +} from '../ops/keyserver-store-ops.js'; import type { ClientDBMessageStoreOperation, MessageStoreOperation, @@ -44,6 +47,7 @@ +threadStoreOperations?: $ReadOnlyArray, +messageStoreOperations?: $ReadOnlyArray, +reportStoreOperations?: $ReadOnlyArray, + +keyserverStoreOperations?: $ReadOnlyArray, }; export type ClientDBStore = { diff --git a/web/database/worker/process-operations.js b/web/database/worker/process-operations.js --- a/web/database/worker/process-operations.js +++ b/web/database/worker/process-operations.js @@ -1,5 +1,6 @@ // @flow +import type { ClientDBKeyserverStoreOperation } from 'lib/ops/keyserver-store-ops.js'; import type { ClientDBReportStoreOperation } from 'lib/ops/report-store-ops.js'; import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js'; import type { @@ -122,13 +123,48 @@ } } +function processKeyserverStoreOperations( + sqliteQueryExecutor: SQLiteQueryExecutor, + operations: $ReadOnlyArray, + module: EmscriptenModule, +) { + for (const operation: ClientDBKeyserverStoreOperation of operations) { + try { + if (operation.type === 'remove_all_keyservers') { + sqliteQueryExecutor.removeAllKeyservers(); + } else if (operation.type === 'remove_keyservers') { + const { ids } = operation.payload; + sqliteQueryExecutor.removeKeyservers(ids); + } else if (operation.type === 'replace_keyserver') { + const { id, keyserverInfo } = operation.payload; + sqliteQueryExecutor.replaceKeyserver({ id, keyserverInfo }); + } else { + throw new Error('Unsupported keyserver operation'); + } + } catch (e) { + throw new Error( + `Error while processing ${ + operation.type + } keyserver operation: ${getProcessingStoreOpsExceptionMessage( + e, + module, + )}`, + ); + } + } +} + function processDBStoreOperations( sqliteQueryExecutor: SQLiteQueryExecutor, storeOperations: ClientDBStoreOperations, module: EmscriptenModule, ) { - const { draftStoreOperations, reportStoreOperations, threadStoreOperations } = - storeOperations; + const { + draftStoreOperations, + reportStoreOperations, + threadStoreOperations, + keyserverStoreOperations, + } = storeOperations; try { sqliteQueryExecutor.beginTransaction(); @@ -153,6 +189,13 @@ module, ); } + if (keyserverStoreOperations && keyserverStoreOperations.length > 0) { + processKeyserverStoreOperations( + sqliteQueryExecutor, + keyserverStoreOperations, + module, + ); + } sqliteQueryExecutor.commitTransaction(); } catch (e) { sqliteQueryExecutor.rollbackTransaction(); @@ -173,7 +216,7 @@ messageStoreThreads: [], reports: sqliteQueryExecutor.getAllReports(), users: [], - keyservers: [], + keyservers: sqliteQueryExecutor.getAllKeyservers(), }; }