Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3340794
D11726.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D11726.diff
View Options
diff --git a/lib/types/sqlite-types.js b/lib/types/sqlite-types.js
--- a/lib/types/sqlite-types.js
+++ b/lib/types/sqlite-types.js
@@ -6,3 +6,13 @@
+plaintext: string,
+status: string,
};
+
+export type SQLiteAPI = {
+ // read operations
+ +getAllReceivedMessageToDevice: () => Promise<ReceivedMessageToDevice[]>,
+
+ // write operations
+ +removeReceivedMessagesToDevice: (
+ ids: $ReadOnlyArray<string>,
+ ) => Promise<void>,
+};
diff --git a/lib/utils/__mocks__/config.js b/lib/utils/__mocks__/config.js
--- a/lib/utils/__mocks__/config.js
+++ b/lib/utils/__mocks__/config.js
@@ -25,6 +25,10 @@
validateAndUploadPrekeys: jest.fn(),
signMessage: jest.fn(),
},
+ sqliteAPI: {
+ getAllReceivedMessageToDevice: jest.fn(),
+ removeReceivedMessagesToDevice: jest.fn(),
+ },
});
const hasConfig = (): boolean => true;
diff --git a/lib/utils/config.js b/lib/utils/config.js
--- a/lib/utils/config.js
+++ b/lib/utils/config.js
@@ -8,6 +8,7 @@
import type { RecoveryActionSource } from '../types/account-types.js';
import type { OlmAPI } from '../types/crypto-types.js';
import type { PlatformDetails } from '../types/device-types.js';
+import type { SQLiteAPI } from '../types/sqlite-types.js';
import type { DispatchActionPromise } from '../utils/redux-promise-utils.js';
export type Config = {
@@ -27,6 +28,7 @@
+platformDetails: PlatformDetails,
+authoritativeKeyserverID: string,
+olmAPI: OlmAPI,
+ +sqliteAPI: SQLiteAPI,
};
let registeredConfig: ?Config = null;
diff --git a/native/config.js b/native/config.js
--- a/native/config.js
+++ b/native/config.js
@@ -7,6 +7,7 @@
import { resolveKeyserverSessionInvalidationUsingNativeCredentials } from './account/legacy-recover-keyserver-session.js';
import { authoritativeKeyserverID } from './authoritative-keyserver.js';
import { olmAPI } from './crypto/olm-api.js';
+import { sqliteAPI } from './database/sqlite-api.js';
import { persistConfig, codeVersion } from './redux/persist.js';
registerConfig({
@@ -20,4 +21,5 @@
},
authoritativeKeyserverID,
olmAPI,
+ sqliteAPI,
});
diff --git a/native/database/sqlite-api.js b/native/database/sqlite-api.js
new file mode 100644
--- /dev/null
+++ b/native/database/sqlite-api.js
@@ -0,0 +1,15 @@
+// @flow
+
+import type { SQLiteAPI } from 'lib/types/sqlite-types.js';
+
+import { commCoreModule } from '../native-modules.js';
+
+const sqliteAPI: SQLiteAPI = {
+ // read operations
+ getAllReceivedMessageToDevice: commCoreModule.getAllReceivedMessageToDevice,
+
+ // write operations
+ removeReceivedMessagesToDevice: commCoreModule.removeReceivedMessagesToDevice,
+};
+
+export { sqliteAPI };
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -49,6 +49,7 @@
import NavigationArrows from './components/navigation-arrows.react.js';
import MinVersionHandler from './components/version-handler.react.js';
import { olmAPI } from './crypto/olm-api.js';
+import { sqliteAPI } from './database/sqlite-api.js';
import electron from './electron.js';
import InputStateContainer from './input/input-state-container.react.js';
import InviteLinkHandler from './invite-links/invite-link-handler.react.js';
@@ -106,6 +107,7 @@
},
authoritativeKeyserverID,
olmAPI,
+ sqliteAPI,
});
const versionBroadcast = new BroadcastChannel('comm_version');
diff --git a/web/database/sqlite-api.js b/web/database/sqlite-api.js
new file mode 100644
--- /dev/null
+++ b/web/database/sqlite-api.js
@@ -0,0 +1,36 @@
+// @flow
+
+import type {
+ SQLiteAPI,
+ ReceivedMessageToDevice,
+} from 'lib/types/sqlite-types.js';
+
+import { getCommSharedWorker } from '../shared-worker/shared-worker-provider.js';
+import { workerRequestMessageTypes } from '../types/worker-types.js';
+
+const sqliteAPI: SQLiteAPI = {
+ // read operations
+ async getAllReceivedMessageToDevice(): Promise<ReceivedMessageToDevice[]> {
+ const sharedWorker = await getCommSharedWorker();
+
+ const data = await sharedWorker.schedule({
+ type: workerRequestMessageTypes.GET_RECEIVED_MESSAGES_TO_DEVICE,
+ });
+ const messages: ?$ReadOnlyArray<ReceivedMessageToDevice> = data?.messages;
+ return messages ? [...messages] : [];
+ },
+
+ // write operations
+ async removeReceivedMessagesToDevice(
+ ids: $ReadOnlyArray<string>,
+ ): Promise<void> {
+ const sharedWorker = await getCommSharedWorker();
+
+ await sharedWorker.schedule({
+ type: workerRequestMessageTypes.REMOVE_RECEIVED_MESSAGES_TO_DEVICE,
+ ids,
+ });
+ },
+};
+
+export { sqliteAPI };
diff --git a/web/shared-worker/worker/shared-worker.js b/web/shared-worker/worker/shared-worker.js
--- a/web/shared-worker/worker/shared-worker.js
+++ b/web/shared-worker/worker/shared-worker.js
@@ -243,7 +243,7 @@
) {
return {
type: workerResponseMessageTypes.GET_RECEIVED_MESSAGES_TO_DEVICE,
- result: sqliteQueryExecutor.getAllReceivedMessageToDevice(),
+ messages: sqliteQueryExecutor.getAllReceivedMessageToDevice(),
};
}
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
@@ -232,7 +232,7 @@
export type GetReceivedMessagesToDeviceResponseMessage = {
+type: 6,
- +result: $ReadOnlyArray<ReceivedMessageToDevice>,
+ +messages: $ReadOnlyArray<ReceivedMessageToDevice>,
};
export type WorkerResponseMessage =
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 10:11 PM (17 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2565724
Default Alt Text
D11726.diff (5 KB)
Attached To
Mode
D11726: [SQLite/lib] implement shared SQLite interface
Attached
Detach File
Event Timeline
Log In to Comment