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 @@ -143,6 +143,10 @@ const OutboundP2PMessage &lastConfirmedMessage) const = 0; virtual void removeAllOutboundP2PMessages(const std::string &deviceID) const = 0; + virtual void setCiphertextForOutboundP2PMessage( + std::string messageID, + std::string deviceID, + std::string ciphertext) const = 0; virtual void addInboundP2PMessage(InboundP2PMessage message) const = 0; virtual std::vector getAllInboundP2PMessage() const = 0; virtual void 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,6 +152,10 @@ void removeOutboundP2PMessagesOlderThan( const OutboundP2PMessage &lastConfirmedMessage) const override; void removeAllOutboundP2PMessages(const std::string &deviceID) const override; + void setCiphertextForOutboundP2PMessage( + std::string messageID, + std::string deviceID, + std::string ciphertext) const override; void addInboundP2PMessage(InboundP2PMessage message) const override; std::vector getAllInboundP2PMessage() const override; void 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 @@ -2180,6 +2180,27 @@ SQLiteQueryExecutor::getConnection(), removeMessagesSQL, keys); } +void SQLiteQueryExecutor::setCiphertextForOutboundP2PMessage( + std::string messageID, + std::string deviceID, + std::string ciphertext) const { + static std::string query = + "UPDATE outbound_p2p_messages " + "SET ciphertext = ?, status = 'encrypted' " + "WHERE message_id = ? AND device_id = ?;"; + + comm::SQLiteStatementWrapper preparedSQL( + SQLiteQueryExecutor::getConnection(), + query, + "Failed to set ciphertext for OutboundP2PMessage"); + + bindStringToSQL(ciphertext.c_str(), preparedSQL, 1); + bindStringToSQL(messageID.c_str(), preparedSQL, 2); + bindStringToSQL(deviceID.c_str(), preparedSQL, 3); + + sqlite3_step(preparedSQL); +} + void SQLiteQueryExecutor::addInboundP2PMessage( InboundP2PMessage message) const { static std::string addMessage = diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -274,6 +274,9 @@ .function( "getAllOutboundP2PMessages", &SQLiteQueryExecutor::getAllOutboundP2PMessages) + .function( + "setCiphertextForOutboundP2PMessage", + &SQLiteQueryExecutor::setCiphertextForOutboundP2PMessage) .function( "addInboundP2PMessage", &SQLiteQueryExecutor::addInboundP2PMessage) .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 ciphertext = 'updated'; + + queryExecutor?.setCiphertextForOutboundP2PMessage( + TEST_MSG_4.messageID, + TEST_MSG_4.deviceID, + ciphertext, + ); + + const messages = queryExecutor?.getAllOutboundP2PMessages(device1) ?? []; + expect(messages.length).toBe(3); + expect( + messages.find(msg => msg.messageID === TEST_MSG_4.messageID)?.ciphertext, + ).toBe(ciphertext); + }); }); 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 @@ -165,6 +165,11 @@ getAllOutboundP2PMessages( deviceID: string, ): $ReadOnlyArray; + setCiphertextForOutboundP2PMessage( + messageID: string, + deviceID: string, + ciphertext: string, + ): void; addInboundP2PMessage(message: InboundP2PMessage): void; getAllInboundP2PMessage(): $ReadOnlyArray;