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 @@ -174,6 +174,8 @@ virtual std::vector getAllInboundP2PMessage() const = 0; virtual void removeInboundP2PMessages(const std::vector &ids) const = 0; + virtual std::vector + getInboundP2PMessagesByID(const std::vector &ids) const = 0; virtual std::vector getRelatedMessages(const std::string &messageID) const = 0; virtual void updateMessageSearchIndex( 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 @@ -191,6 +191,8 @@ std::vector getAllInboundP2PMessage() const override; void removeInboundP2PMessages(const std::vector &ids) const override; + std::vector + getInboundP2PMessagesByID(const std::vector &ids) const override; std::vector getRelatedMessages(const std::string &messageID) const override; void updateMessageSearchIndex( 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 @@ -2747,6 +2747,26 @@ SQLiteQueryExecutor::getConnection(), removeMessagesSQLStream.str(), ids); } +std::vector SQLiteQueryExecutor::getInboundP2PMessagesByID( + const std::vector &ids) const { + std::stringstream getInboundP2PMessagesSQLStream; + getInboundP2PMessagesSQLStream << "SELECT " + " message_id, sender_device_id, " + " plaintext, status, sender_user_id " + "FROM inbound_p2p_messages " + "WHERE message_id IN " + << getSQLStatementArray(ids.size()) << ";"; + std::string getInboundP2PMessageSQL = getInboundP2PMessagesSQLStream.str(); + + SQLiteStatementWrapper preparedSQL( + SQLiteQueryExecutor::getConnection(), + getInboundP2PMessageSQL, + "Failed to get inbound messages by ID"); + + return getAllEntitiesByPrimaryKeys( + SQLiteQueryExecutor::getConnection(), getInboundP2PMessageSQL, ids); +} + std::vector SQLiteQueryExecutor::getRelatedMessages(const std::string &messageID) const { static std::string getMessageSQL = diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -321,6 +321,9 @@ .function( "removeInboundP2PMessages", &SQLiteQueryExecutor::removeInboundP2PMessages) + .function( + "getInboundP2PMessagesByID", + &SQLiteQueryExecutor::getInboundP2PMessagesByID) .function( "getRelatedMessagesWeb", &SQLiteQueryExecutor::getRelatedMessagesWeb) .function( 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$@ { + const messages = queryExecutor?.getInboundP2PMessagesByID([ + TEST_MSG_2.messageID, + ]); + expect(messages).toStrictEqual([TEST_MSG_2]); + }); }); 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 @@ -197,6 +197,9 @@ addInboundP2PMessage(message: InboundP2PMessage): void; getAllInboundP2PMessage(): $ReadOnlyArray; removeInboundP2PMessages(ids: $ReadOnlyArray): void; + getInboundP2PMessagesByID( + ids: $ReadOnlyArray, + ): $ReadOnlyArray; getRelatedMessagesWeb(id: string): $ReadOnlyArray;