From 34c732abe671a07e63f35dc14e2924700a9afc17 Mon Sep 17 00:00:00 2001 From: Angelika Serwa Date: Thu, 7 Nov 2024 23:23:25 +0100 Subject: [PATCH] [lib] Implement getInboundP2PMessagesByID in SQLiteAPI Summary: https://linear.app/comm/issue/ENG-9713/mitigate-risk-of-olm-already-decrypted-or-keys-skipped Depends on D13899 Test Plan: Test plan in the last diff in stack. Reviewers: tomek, kamil Reviewed By: kamil Subscribers: ashoat Differential Revision: https://phab.comm.dev/D13900 --- lib/types/sqlite-types.js | 3 +++ lib/utils/__mocks__/config.js | 1 + native/database/sqlite-api.js | 1 + web/database/sqlite-api.js | 14 ++++++++++++++ 4 files changed, 19 insertions(+) diff --git a/lib/types/sqlite-types.js b/lib/types/sqlite-types.js index ad4cd382e6..17eeb723a2 100644 --- a/lib/types/sqlite-types.js +++ b/lib/types/sqlite-types.js @@ -42,6 +42,9 @@ export type OutboundP2PMessage = { export type SQLiteAPI = { // read operations +getAllInboundP2PMessages: () => Promise>, + +getInboundP2PMessagesByID: ( + ids: $ReadOnlyArray, + ) => Promise>, +getAllOutboundP2PMessages: () => Promise>, +getRelatedMessages: ( messageID: string, diff --git a/lib/utils/__mocks__/config.js b/lib/utils/__mocks__/config.js index aee256013e..81cee4881d 100644 --- a/lib/utils/__mocks__/config.js +++ b/lib/utils/__mocks__/config.js @@ -35,6 +35,7 @@ const getConfig = (): Config => ({ }, sqliteAPI: { getAllInboundP2PMessages: jest.fn(), + getInboundP2PMessagesByID: jest.fn(), removeInboundP2PMessages: jest.fn(), processDBStoreOperations: jest.fn(), getAllOutboundP2PMessages: jest.fn(), diff --git a/native/database/sqlite-api.js b/native/database/sqlite-api.js index 3ed801ec05..321a735860 100644 --- a/native/database/sqlite-api.js +++ b/native/database/sqlite-api.js @@ -12,6 +12,7 @@ import { isTaskCancelledError } from '../utils/error-handling.js'; const sqliteAPI: SQLiteAPI = { // read operations getAllInboundP2PMessages: commCoreModule.getAllInboundP2PMessages, + getInboundP2PMessagesByID: commCoreModule.getInboundP2PMessagesByID, getAllOutboundP2PMessages: commCoreModule.getAllOutboundP2PMessages, getRelatedMessages: commCoreModule.getRelatedMessages, getOutboundP2PMessagesByID: commCoreModule.getOutboundP2PMessagesByID, diff --git a/web/database/sqlite-api.js b/web/database/sqlite-api.js index 0fea3d6cad..d3e51d946a 100644 --- a/web/database/sqlite-api.js +++ b/web/database/sqlite-api.js @@ -26,6 +26,20 @@ const sqliteAPI: SQLiteAPI = { return messages ? [...messages] : []; }, + async getInboundP2PMessagesByID( + ids: $ReadOnlyArray, + ): Promise> { + const sharedWorker = await getCommSharedWorker(); + + const data = await sharedWorker.schedule({ + type: workerRequestMessageTypes.GET_INBOUND_P2P_MESSAGES_BY_ID, + messageIDs: ids, + }); + const messages: ?$ReadOnlyArray = + data?.inboundP2PMessages; + return messages ? [...messages] : []; + }, + async getAllOutboundP2PMessages(): Promise { const sharedWorker = await getCommSharedWorker();