Skip to content

Commit

Permalink
[lib] Implement getInboundP2PMessagesByID in SQLiteAPI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
graszka22 committed Nov 13, 2024
1 parent 829132a commit 34c732a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/types/sqlite-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export type OutboundP2PMessage = {
export type SQLiteAPI = {
// read operations
+getAllInboundP2PMessages: () => Promise<Array<InboundP2PMessage>>,
+getInboundP2PMessagesByID: (
ids: $ReadOnlyArray<string>,
) => Promise<Array<InboundP2PMessage>>,
+getAllOutboundP2PMessages: () => Promise<Array<OutboundP2PMessage>>,
+getRelatedMessages: (
messageID: string,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/__mocks__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const getConfig = (): Config => ({
},
sqliteAPI: {
getAllInboundP2PMessages: jest.fn(),
getInboundP2PMessagesByID: jest.fn(),
removeInboundP2PMessages: jest.fn(),
processDBStoreOperations: jest.fn(),
getAllOutboundP2PMessages: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions native/database/sqlite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions web/database/sqlite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ const sqliteAPI: SQLiteAPI = {
return messages ? [...messages] : [];
},

async getInboundP2PMessagesByID(
ids: $ReadOnlyArray<string>,
): Promise<Array<InboundP2PMessage>> {
const sharedWorker = await getCommSharedWorker();

const data = await sharedWorker.schedule({
type: workerRequestMessageTypes.GET_INBOUND_P2P_MESSAGES_BY_ID,
messageIDs: ids,
});
const messages: ?$ReadOnlyArray<InboundP2PMessage> =
data?.inboundP2PMessages;
return messages ? [...messages] : [];
},

async getAllOutboundP2PMessages(): Promise<OutboundP2PMessage[]> {
const sharedWorker = await getCommSharedWorker();

Expand Down

0 comments on commit 34c732a

Please sign in to comment.