diff --git a/lib/handlers/db-ops-handler.react.js b/lib/handlers/db-ops-handler.react.js --- a/lib/handlers/db-ops-handler.react.js +++ b/lib/handlers/db-ops-handler.react.js @@ -50,7 +50,7 @@ deviceID: senderDeviceID, payload: JSON.stringify(message), }); - await sqliteAPI.removeReceivedMessagesToDevice([messageID]); + await sqliteAPI.removeInboundP2PMessages([messageID]); } })(); }, [queueFront, dispatch, processDBStoreOperations, sendMessage, sqliteAPI]); 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 @@ -2,7 +2,7 @@ import type { StoreOperations } from './store-ops-types.js'; -export type ReceivedMessageToDevice = { +export type InboundP2PMessage = { +messageID: string, +senderDeviceID: string, +plaintext: string, @@ -11,12 +11,10 @@ export type SQLiteAPI = { // read operations - +getAllReceivedMessageToDevice: () => Promise, + +getAllInboundP2PMessage: () => Promise, // write operations - +removeReceivedMessagesToDevice: ( - ids: $ReadOnlyArray, - ) => Promise, + +removeInboundP2PMessages: (ids: $ReadOnlyArray) => Promise, +processDBStoreOperations: ( operations: StoreOperations, 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 @@ -27,8 +27,8 @@ verifyMessage: jest.fn(), }, sqliteAPI: { - getAllReceivedMessageToDevice: jest.fn(), - removeReceivedMessagesToDevice: jest.fn(), + getAllInboundP2PMessage: jest.fn(), + removeInboundP2PMessages: jest.fn(), processDBStoreOperations: jest.fn(), }, }); diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h @@ -4,6 +4,7 @@ #include "entities/AuxUserInfo.h" #include "entities/CommunityInfo.h" #include "entities/Draft.h" +#include "entities/InboundP2PMessage.h" #include "entities/IntegrityThreadHash.h" #include "entities/KeyserverInfo.h" #include "entities/Message.h" @@ -12,7 +13,6 @@ #include "entities/OlmPersistAccount.h" #include "entities/OlmPersistSession.h" #include "entities/PersistItem.h" -#include "entities/ReceivedMessageToDevice.h" #include "entities/Report.h" #include "entities/SyncedMetadataEntry.h" #include "entities/Thread.h" @@ -143,12 +143,10 @@ const ClientMessageToDevice &lastConfirmedMessage) const = 0; virtual void removeAllMessagesForDevice(const std::string &deviceID) const = 0; + virtual void addInboundP2PMessage(InboundP2PMessage message) const = 0; + virtual std::vector getAllInboundP2PMessage() const = 0; virtual void - addReceivedMessageToDevice(ReceivedMessageToDevice message) const = 0; - virtual std::vector - getAllReceivedMessageToDevice() const = 0; - virtual void - removeReceivedMessagesToDevice(const std::vector &ids) const = 0; + removeInboundP2PMessages(const std::vector &ids) const = 0; #ifdef EMSCRIPTEN virtual std::vector getAllThreadsWeb() const = 0; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -152,12 +152,10 @@ void removeMessagesToDeviceOlderThan( const ClientMessageToDevice &lastConfirmedMessage) const override; void removeAllMessagesForDevice(const std::string &deviceID) const override; + void addInboundP2PMessage(InboundP2PMessage message) const override; + std::vector getAllInboundP2PMessage() const override; void - addReceivedMessageToDevice(ReceivedMessageToDevice message) const override; - std::vector - getAllReceivedMessageToDevice() const override; - void removeReceivedMessagesToDevice( - const std::vector &ids) const override; + removeInboundP2PMessages(const std::vector &ids) const override; #ifdef EMSCRIPTEN std::vector getAllThreadsWeb() const override; diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -2155,27 +2155,27 @@ SQLiteQueryExecutor::getConnection(), removeMessagesSQL, keys); } -void SQLiteQueryExecutor::addReceivedMessageToDevice( - ReceivedMessageToDevice message) const { +void SQLiteQueryExecutor::addInboundP2PMessage( + InboundP2PMessage message) const { static std::string addMessage = "REPLACE INTO received_messages_to_device (" " message_id, sender_device_id, plaintext, status)" "VALUES (?, ?, ?, ?);"; - replaceEntity( + replaceEntity( SQLiteQueryExecutor::getConnection(), addMessage, message); } -std::vector -SQLiteQueryExecutor::getAllReceivedMessageToDevice() const { +std::vector +SQLiteQueryExecutor::getAllInboundP2PMessage() const { static std::string query = "SELECT message_id, sender_device_id, plaintext, status " "FROM received_messages_to_device;"; - return getAllEntities( + return getAllEntities( SQLiteQueryExecutor::getConnection(), query); } -void SQLiteQueryExecutor::removeReceivedMessagesToDevice( +void SQLiteQueryExecutor::removeInboundP2PMessages( const std::vector &ids) const { if (!ids.size()) { return; diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/ReceivedMessageToDevice.h b/native/cpp/CommonCpp/DatabaseManagers/entities/InboundP2PMessage.h rename from native/cpp/CommonCpp/DatabaseManagers/entities/ReceivedMessageToDevice.h rename to native/cpp/CommonCpp/DatabaseManagers/entities/InboundP2PMessage.h --- a/native/cpp/CommonCpp/DatabaseManagers/entities/ReceivedMessageToDevice.h +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/InboundP2PMessage.h @@ -8,14 +8,14 @@ namespace comm { -struct ReceivedMessageToDevice { +struct InboundP2PMessage { std::string message_id; std::string sender_device_id; std::string plaintext; std::string status; - static ReceivedMessageToDevice fromSQLResult(sqlite3_stmt *sqlRow, int idx) { - return ReceivedMessageToDevice{ + static InboundP2PMessage fromSQLResult(sqlite3_stmt *sqlRow, int idx) { + return InboundP2PMessage{ getStringFromSQLRow(sqlRow, idx), getStringFromSQLRow(sqlRow, idx + 1), getStringFromSQLRow(sqlRow, idx + 2), diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -196,9 +196,9 @@ jsi::Object siweBackupSecrets) override; virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) override; virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override; - virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override; + virtual jsi::Value getAllInboundP2PMessage(jsi::Runtime &rt) override; virtual jsi::Value - removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) override; + removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) override; public: CommCoreModule(std::shared_ptr jsInvoker); diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -1460,15 +1460,15 @@ GlobalDBSingleton::instance.scheduleOrRunCancellable( [=, &persistencePromise]() { try { - ReceivedMessageToDevice message{ + InboundP2PMessage message{ messageIDCpp, deviceIDCpp, decryptedMessage, "decrypted"}; DatabaseManager::getQueryExecutor().beginTransaction(); - DatabaseManager::getQueryExecutor() - .addReceivedMessageToDevice(message); + DatabaseManager::getQueryExecutor().addInboundP2PMessage( + message); DatabaseManager::getQueryExecutor().storeOlmPersistData( DatabaseManager::getQueryExecutor() .getContentAccountID(), @@ -2140,23 +2140,22 @@ }); } -jsi::Value CommCoreModule::getAllReceivedMessageToDevice(jsi::Runtime &rt) { +jsi::Value CommCoreModule::getAllInboundP2PMessage(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { taskType job = [=, &innerRt]() { std::string error; - std::vector messages; + std::vector messages; try { - messages = DatabaseManager::getQueryExecutor() - .getAllReceivedMessageToDevice(); + messages = + DatabaseManager::getQueryExecutor().getAllInboundP2PMessage(); } catch (std::system_error &e) { error = e.what(); } - auto messagesPtr = - std::make_shared>( - std::move(messages)); + auto messagesPtr = std::make_shared>( + std::move(messages)); this->jsInvoker_->invokeAsync( [&innerRt, messagesPtr, error, promise]() { @@ -2168,7 +2167,7 @@ jsi::Array jsiMessages = jsi::Array(innerRt, messagesPtr->size()); size_t writeIdx = 0; - for (const ReceivedMessageToDevice &msg : *messagesPtr) { + for (const InboundP2PMessage &msg : *messagesPtr) { jsi::Object jsiMsg = jsi::Object(innerRt); jsiMsg.setProperty(innerRt, "messageID", msg.message_id); jsiMsg.setProperty( @@ -2186,9 +2185,8 @@ }); } -jsi::Value CommCoreModule::removeReceivedMessagesToDevice( - jsi::Runtime &rt, - jsi::Array ids) { +jsi::Value +CommCoreModule::removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) { std::vector msgIDsCPP{}; for (auto idx = 0; idx < ids.size(rt); idx++) { std::string msgID = ids.getValueAtIndex(rt, idx).asString(rt).utf8(rt); @@ -2202,7 +2200,7 @@ taskType job = [this, promise, msgIDsCPP]() { std::string error; try { - DatabaseManager::getQueryExecutor().removeReceivedMessagesToDevice( + DatabaseManager::getQueryExecutor().removeInboundP2PMessages( msgIDsCPP); } catch (std::system_error &e) { error = e.what(); diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -181,11 +181,11 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getSIWEBackupSecrets(rt); } -static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->getAllReceivedMessageToDevice(rt); +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllInboundP2PMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->getAllInboundP2PMessage(rt); } -static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->removeReceivedMessagesToDevice(rt, args[0].asObject(rt).asArray(rt)); +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeInboundP2PMessages(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->removeInboundP2PMessages(rt, args[0].asObject(rt).asArray(rt)); } CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) @@ -244,8 +244,8 @@ methodMap_["retrieveLatestSIWEBackupData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestSIWEBackupData}; methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets}; methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets}; - methodMap_["getAllReceivedMessageToDevice"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice}; - methodMap_["removeReceivedMessagesToDevice"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice}; + methodMap_["getAllInboundP2PMessage"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllInboundP2PMessage}; + methodMap_["removeInboundP2PMessages"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeInboundP2PMessages}; } diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -74,8 +74,8 @@ virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) = 0; virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0; virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0; - virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) = 0; - virtual jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) = 0; + virtual jsi::Value getAllInboundP2PMessage(jsi::Runtime &rt) = 0; + virtual jsi::Value removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) = 0; }; @@ -529,21 +529,21 @@ return bridging::callFromJs( rt, &T::getSIWEBackupSecrets, jsInvoker_, instance_); } - jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override { + jsi::Value getAllInboundP2PMessage(jsi::Runtime &rt) override { static_assert( - bridging::getParameterCount(&T::getAllReceivedMessageToDevice) == 1, - "Expected getAllReceivedMessageToDevice(...) to have 1 parameters"); + bridging::getParameterCount(&T::getAllInboundP2PMessage) == 1, + "Expected getAllInboundP2PMessage(...) to have 1 parameters"); return bridging::callFromJs( - rt, &T::getAllReceivedMessageToDevice, jsInvoker_, instance_); + rt, &T::getAllInboundP2PMessage, jsInvoker_, instance_); } - jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) override { + jsi::Value removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) override { static_assert( - bridging::getParameterCount(&T::removeReceivedMessagesToDevice) == 2, - "Expected removeReceivedMessagesToDevice(...) to have 2 parameters"); + bridging::getParameterCount(&T::removeInboundP2PMessages) == 2, + "Expected removeInboundP2PMessages(...) to have 2 parameters"); return bridging::callFromJs( - rt, &T::removeReceivedMessagesToDevice, jsInvoker_, instance_, std::move(ids)); + rt, &T::removeInboundP2PMessages, jsInvoker_, instance_, std::move(ids)); } private: diff --git a/native/database/sqlite-api.js b/native/database/sqlite-api.js --- a/native/database/sqlite-api.js +++ b/native/database/sqlite-api.js @@ -7,10 +7,10 @@ const sqliteAPI: SQLiteAPI = { // read operations - getAllReceivedMessageToDevice: commCoreModule.getAllReceivedMessageToDevice, + getAllInboundP2PMessage: commCoreModule.getAllInboundP2PMessage, // write operations - removeReceivedMessagesToDevice: commCoreModule.removeReceivedMessagesToDevice, + removeInboundP2PMessages: commCoreModule.removeInboundP2PMessages, processDBStoreOperations, }; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -17,7 +17,7 @@ } from 'lib/types/crypto-types.js'; import type { ClientDBMessageInfo } from 'lib/types/message-types.js'; import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js'; -import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js'; +import type { InboundP2PMessage } from 'lib/types/sqlite-types.js'; import type { ClientDBStore, ClientDBStoreOperations, @@ -138,10 +138,8 @@ +retrieveLatestSIWEBackupData: () => Promise; +setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise; +getSIWEBackupSecrets: () => Promise; - +getAllReceivedMessageToDevice: () => Promise; - +removeReceivedMessagesToDevice: ( - ids: $ReadOnlyArray, - ) => Promise; + +getAllInboundP2PMessage: () => Promise; + +removeInboundP2PMessages: (ids: $ReadOnlyArray) => Promise; } export interface CoreModuleSpec extends Spec { diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -1,7 +1,7 @@ #include "SQLiteQueryExecutor.cpp" +#include "entities/InboundP2PMessage.h" #include "entities/MessageToDevice.h" #include "entities/Nullable.h" -#include "entities/ReceivedMessageToDevice.h" #include #include @@ -122,11 +122,11 @@ .field("plaintext", &ClientMessageToDevice::plaintext) .field("ciphertext", &ClientMessageToDevice::ciphertext); - value_object("ReceivedMessageToDevice") - .field("messageID", &ReceivedMessageToDevice::message_id) - .field("senderDeviceID", &ReceivedMessageToDevice::sender_device_id) - .field("plaintext", &ReceivedMessageToDevice::plaintext) - .field("status", &ReceivedMessageToDevice::status); + value_object("InboundP2PMessage") + .field("messageID", &InboundP2PMessage::message_id) + .field("senderDeviceID", &InboundP2PMessage::sender_device_id) + .field("plaintext", &InboundP2PMessage::plaintext) + .field("status", &InboundP2PMessage::status); class_("SQLiteQueryExecutor") .constructor() @@ -273,14 +273,13 @@ "getAllMessagesToDevice", &SQLiteQueryExecutor::getAllMessagesToDevice) .function( - "addReceivedMessageToDevice", - &SQLiteQueryExecutor::addReceivedMessageToDevice) + "addInboundP2PMessage", &SQLiteQueryExecutor::addInboundP2PMessage) .function( - "getAllReceivedMessageToDevice", - &SQLiteQueryExecutor::getAllReceivedMessageToDevice) + "getAllInboundP2PMessage", + &SQLiteQueryExecutor::getAllInboundP2PMessage) .function( - "removeReceivedMessagesToDevice", - &SQLiteQueryExecutor::removeReceivedMessagesToDevice); + "removeInboundP2PMessages", + &SQLiteQueryExecutor::removeInboundP2PMessages); } } // namespace comm diff --git a/web/database/sqlite-api.js b/web/database/sqlite-api.js --- a/web/database/sqlite-api.js +++ b/web/database/sqlite-api.js @@ -1,9 +1,6 @@ // @flow -import type { - SQLiteAPI, - ReceivedMessageToDevice, -} from 'lib/types/sqlite-types.js'; +import type { SQLiteAPI, InboundP2PMessage } from 'lib/types/sqlite-types.js'; import { getCommSharedWorker } from '../shared-worker/shared-worker-provider.js'; import { processDBStoreOperations } from '../shared-worker/utils/store.js'; @@ -11,24 +8,22 @@ const sqliteAPI: SQLiteAPI = { // read operations - async getAllReceivedMessageToDevice(): Promise { + async getAllInboundP2PMessage(): Promise { const sharedWorker = await getCommSharedWorker(); const data = await sharedWorker.schedule({ - type: workerRequestMessageTypes.GET_RECEIVED_MESSAGES_TO_DEVICE, + type: workerRequestMessageTypes.GET_INBOUND_P2P_MESSAGES, }); - const messages: ?$ReadOnlyArray = data?.messages; + const messages: ?$ReadOnlyArray = data?.messages; return messages ? [...messages] : []; }, // write operations - async removeReceivedMessagesToDevice( - ids: $ReadOnlyArray, - ): Promise { + async removeInboundP2PMessages(ids: $ReadOnlyArray): Promise { const sharedWorker = await getCommSharedWorker(); await sharedWorker.schedule({ - type: workerRequestMessageTypes.REMOVE_RECEIVED_MESSAGES_TO_DEVICE, + type: workerRequestMessageTypes.REMOVE_INBOUND_P2P_MESSAGES, ids, }); }, diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ { +describe('Inbound P2P message queries', () => { let queryExecutor: ?SQLiteQueryExecutor = null; let dbModule: ?EmscriptenModule = null; @@ -51,9 +51,9 @@ if (!queryExecutor) { throw new Error('SQLiteQueryExecutor is missing'); } - queryExecutor?.addReceivedMessageToDevice(TEST_MSG_1); - queryExecutor?.addReceivedMessageToDevice(TEST_MSG_2); - queryExecutor?.addReceivedMessageToDevice(TEST_MSG_3); + queryExecutor?.addInboundP2PMessage(TEST_MSG_1); + queryExecutor?.addInboundP2PMessage(TEST_MSG_2); + queryExecutor?.addInboundP2PMessage(TEST_MSG_3); }); afterEach(() => { @@ -64,13 +64,13 @@ }); it('should return all messages', () => { - const messages = queryExecutor?.getAllReceivedMessageToDevice() ?? []; + const messages = queryExecutor?.getAllInboundP2PMessage() ?? []; expect(messages.length).toBe(3); expect(messages).toStrictEqual(messagesOrdered); }); it('should remove messages', () => { - queryExecutor?.removeReceivedMessagesToDevice([TEST_MSG_2.messageID]); - const messages = queryExecutor?.getAllReceivedMessageToDevice() ?? []; + queryExecutor?.removeInboundP2PMessages([TEST_MSG_2.messageID]); + const messages = queryExecutor?.getAllInboundP2PMessage() ?? []; expect(messages.length).toBe(2); expect(messages).toStrictEqual([TEST_MSG_1, TEST_MSG_3]); }); diff --git a/web/shared-worker/types/sqlite-query-executor.js b/web/shared-worker/types/sqlite-query-executor.js --- a/web/shared-worker/types/sqlite-query-executor.js +++ b/web/shared-worker/types/sqlite-query-executor.js @@ -9,7 +9,7 @@ import type { ClientDBThreadActivityEntry } from 'lib/ops/thread-activity-store-ops.js'; import type { ClientDBUserInfo } from 'lib/ops/user-store-ops.js'; import type { ClientDBDraftInfo } from 'lib/types/draft-types.js'; -import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js'; +import type { InboundP2PMessage } from 'lib/types/sqlite-types.js'; import { type WebClientDBThreadInfo, @@ -172,9 +172,9 @@ deviceID: string, ): $ReadOnlyArray; - addReceivedMessageToDevice(message: ReceivedMessageToDevice): void; - getAllReceivedMessageToDevice(): $ReadOnlyArray; - removeReceivedMessagesToDevice(ids: $ReadOnlyArray): void; + addInboundP2PMessage(message: InboundP2PMessage): void; + getAllInboundP2PMessage(): $ReadOnlyArray; + removeInboundP2PMessages(ids: $ReadOnlyArray): void; // method is provided to manually signal that a C++ object // is no longer needed and can be deleted 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 @@ -239,11 +239,11 @@ item: sqliteQueryExecutor.getPersistStorageItem(message.key), }; } else if ( - message.type === workerRequestMessageTypes.GET_RECEIVED_MESSAGES_TO_DEVICE + message.type === workerRequestMessageTypes.GET_INBOUND_P2P_MESSAGES ) { return { - type: workerResponseMessageTypes.GET_RECEIVED_MESSAGES_TO_DEVICE, - messages: sqliteQueryExecutor.getAllReceivedMessageToDevice(), + type: workerResponseMessageTypes.GET_INBOUND_P2P_MESSAGES, + messages: sqliteQueryExecutor.getAllInboundP2PMessage(), }; } @@ -311,10 +311,9 @@ message.backupLogDataKey, ); } else if ( - message.type === - workerRequestMessageTypes.REMOVE_RECEIVED_MESSAGES_TO_DEVICE + message.type === workerRequestMessageTypes.REMOVE_INBOUND_P2P_MESSAGES ) { - sqliteQueryExecutor.removeReceivedMessagesToDevice(message.ids); + sqliteQueryExecutor.removeInboundP2PMessages(message.ids); } persistNeeded = true; diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js --- a/web/shared-worker/worker/worker-crypto.js +++ b/web/shared-worker/worker/worker-crypto.js @@ -24,7 +24,7 @@ IdentityExistingDeviceKeyUpload, } from 'lib/types/identity-service-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; -import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js'; +import type { InboundP2PMessage } from 'lib/types/sqlite-types.js'; import { getMessageForException } from 'lib/utils/errors.js'; import { entries } from 'lib/utils/objects.js'; import { @@ -492,7 +492,7 @@ ); } - const receivedMessage: ReceivedMessageToDevice = { + const receivedMessage: InboundP2PMessage = { messageID, senderDeviceID: deviceID, plaintext: result, @@ -501,7 +501,7 @@ sqliteQueryExecutor.beginTransaction(); try { - sqliteQueryExecutor.addReceivedMessageToDevice(receivedMessage); + sqliteQueryExecutor.addInboundP2PMessage(receivedMessage); persistCryptoStore(true); sqliteQueryExecutor.commitTransaction(); } catch (e) { 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 @@ -11,7 +11,7 @@ IdentityServiceClient, IdentityServiceAuthLayer, } from 'lib/types/identity-service-types.js'; -import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js'; +import type { InboundP2PMessage } from 'lib/types/sqlite-types.js'; import type { ClientDBStore, ClientDBStoreOperations, @@ -35,8 +35,8 @@ CREATE_IDENTITY_SERVICE_CLIENT: 13, CALL_IDENTITY_CLIENT_METHOD: 14, CALL_OLM_API_METHOD: 15, - GET_RECEIVED_MESSAGES_TO_DEVICE: 16, - REMOVE_RECEIVED_MESSAGES_TO_DEVICE: 17, + GET_INBOUND_P2P_MESSAGES: 16, + REMOVE_INBOUND_P2P_MESSAGES: 17, }); export const workerWriteRequests: $ReadOnlyArray = [ @@ -46,7 +46,7 @@ workerRequestMessageTypes.REMOVE_PERSIST_STORAGE_ITEM, workerRequestMessageTypes.BACKUP_RESTORE, workerRequestMessageTypes.INITIALIZE_CRYPTO_ACCOUNT, - workerRequestMessageTypes.REMOVE_RECEIVED_MESSAGES_TO_DEVICE, + workerRequestMessageTypes.REMOVE_INBOUND_P2P_MESSAGES, ]; export const workerOlmAPIRequests: $ReadOnlyArray = [ @@ -155,11 +155,11 @@ +args: $ReadOnlyArray, }; -export type GetReceivedMessagesToDeviceRequestMessage = { +export type GetInboundP2PMessagesRequestMessage = { +type: 16, }; -export type RemoveReceivedMessagesToDeviceRequestMessage = { +export type RemoveInboundP2PMessagesRequestMessage = { +type: 17, +ids: $ReadOnlyArray, }; @@ -181,8 +181,8 @@ | CreateIdentityServiceClientRequestMessage | CallIdentityClientMethodRequestMessage | CallOLMApiMethodRequestMessage - | GetReceivedMessagesToDeviceRequestMessage - | RemoveReceivedMessagesToDeviceRequestMessage; + | GetInboundP2PMessagesRequestMessage + | RemoveInboundP2PMessagesRequestMessage; export type WorkerRequestProxyMessage = { +id: number, @@ -197,7 +197,7 @@ GET_PERSIST_STORAGE_ITEM: 3, CALL_IDENTITY_CLIENT_METHOD: 4, CALL_OLM_API_METHOD: 5, - GET_RECEIVED_MESSAGES_TO_DEVICE: 6, + GET_INBOUND_P2P_MESSAGES: 6, }); export type PongWorkerResponseMessage = { @@ -230,9 +230,9 @@ +result: mixed, }; -export type GetReceivedMessagesToDeviceResponseMessage = { +export type GetInboundP2PMessagesResponseMessage = { +type: 6, - +messages: $ReadOnlyArray, + +messages: $ReadOnlyArray, }; export type WorkerResponseMessage = @@ -242,7 +242,7 @@ | GetPersistStorageItemResponseMessage | CallIdentityClientMethodResponseMessage | CallOLMApiMethodResponseMessage - | GetReceivedMessagesToDeviceResponseMessage; + | GetInboundP2PMessagesResponseMessage; export type WorkerResponseProxyMessage = { +id?: number,