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 @@ -3,12 +3,15 @@ import type { DraftStoreOperation, ClientDBDraftStoreOperation, + ClientDBDraftInfo, } from './draft-types.js'; import type { + ClientDBMessageInfo, ClientDBMessageStoreOperation, MessageStoreOperation, } from './message-types.js'; import type { + ClientDBThreadInfo, ClientDBThreadStoreOperation, ThreadStoreOperation, } from './thread-types.js'; @@ -24,3 +27,9 @@ +threadStoreOperations?: $ReadOnlyArray, +messageStoreOperations?: $ReadOnlyArray, }; + +export type ClientDBStore = { + +messages: $ReadOnlyArray, + +drafts: $ReadOnlyArray, + +threads: $ReadOnlyArray, +}; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -5,25 +5,17 @@ import { TurboModuleRegistry } from 'react-native'; import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport.js'; -import type { - ClientDBDraftInfo, - ClientDBDraftStoreOperation, -} from 'lib/types/draft-types.js'; +import type { ClientDBDraftStoreOperation } from 'lib/types/draft-types.js'; import type { ClientDBMessageInfo, ClientDBMessageStoreOperation, } from 'lib/types/message-types.js'; +import type { ClientDBStore } from 'lib/types/store-ops-types'; import type { ClientDBThreadInfo, ClientDBThreadStoreOperation, } from 'lib/types/thread-types.js'; -type ClientDBStore = { - +messages: $ReadOnlyArray, - +drafts: $ReadOnlyArray, - +threads: $ReadOnlyArray, -}; - type ClientPublicKeys = { +primaryIdentityPublicKeys: { +ed25519: string, diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js --- a/web/database/worker/db-worker.js +++ b/web/database/worker/db-worker.js @@ -7,6 +7,7 @@ ClientDBDraftStoreOperation, DraftStoreOperation, } from 'lib/types/draft-types.js'; +import type { ClientDBStore } from 'lib/types/store-ops-types.js'; import { type SharedWorkerMessageEvent, @@ -18,6 +19,7 @@ } from '../../types/worker-types.js'; import { getSQLiteDBVersion, setupSQLiteDB } from '../queries/db-queries.js'; import { + getAllDrafts, moveDraft, removeAllDrafts, updateDraft, @@ -81,6 +83,17 @@ } } +function getClientStore(): ClientDBStore { + if (!sqliteDb) { + throw new Error('Database not initialized'); + } + return { + drafts: getAllDrafts(sqliteDb), + messages: [], + threads: [], + }; +} + async function processAppRequest( message: WorkerRequestMessage, ): Promise { @@ -106,6 +119,11 @@ processDraftStoreOperations(draftStoreOperations); } return; + } else if (message.type === workerRequestMessageTypes.GET_CLIENT_STORE) { + return { + type: workerResponseMessageTypes.CLIENT_STORE, + store: getClientStore(), + }; } throw new Error('Request type not supported'); diff --git a/web/types/worker-types.js b/web/types/worker-types.js --- a/web/types/worker-types.js +++ b/web/types/worker-types.js @@ -1,6 +1,9 @@ // @flow -import type { ClientDBStoreOperations } from 'lib/types/store-ops-types.js'; +import type { + ClientDBStore, + ClientDBStoreOperations, +} from 'lib/types/store-ops-types.js'; // The types of messages sent from app to worker export const workerRequestMessageTypes = Object.freeze({ @@ -8,6 +11,7 @@ INIT: 1, GENERATE_DATABASE_ENCRYPTION_KEY: 2, PROCESS_STORE_OPERATIONS: 3, + GET_CLIENT_STORE: 4, }); export type PingWorkerRequestMessage = { @@ -30,11 +34,16 @@ +storeOperations: ClientDBStoreOperations, }; +export type GetClientStoreRequestMessage = { + +type: 4, +}; + export type WorkerRequestMessage = | PingWorkerRequestMessage | InitWorkerRequestMessage | GenerateDatabaseEncryptionKeyRequestMessage - | ProcessStoreOperationsRequestMessage; + | ProcessStoreOperationsRequestMessage + | GetClientStoreRequestMessage; export type WorkerRequestProxyMessage = { +id: number, @@ -44,6 +53,7 @@ // The types of messages sent from worker to app export const workerResponseMessageTypes = Object.freeze({ PONG: 0, + CLIENT_STORE: 1, }); export type PongWorkerResponseMessage = { @@ -51,7 +61,14 @@ +text: string, }; -export type WorkerResponseMessage = PongWorkerResponseMessage; +export type ClientStoreResponseMessage = { + +type: 1, + +store: ClientDBStore, +}; + +export type WorkerResponseMessage = + | PongWorkerResponseMessage + | ClientStoreResponseMessage; export type WorkerResponseProxyMessage = { +id?: number,