Page MenuHomePhorge

D12070.1765064652.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D12070.1765064652.diff

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<InboundP2PMessage> 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<InboundP2PMessage> 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$@<O00001
literal 0
Hc$@<O00001
diff --git a/web/shared-worker/queries/outbound-p2p-message-queries.test.js b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
--- a/web/shared-worker/queries/outbound-p2p-message-queries.test.js
+++ b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
@@ -52,7 +52,7 @@
userID: 'user-1',
timestamp: timestamp4,
plaintext: 'decrypted-4',
- ciphertext: 'encrypted-4',
+ ciphertext: '',
status: 'encrypted',
};
@@ -117,4 +117,20 @@
queryExecutor?.removeAllOutboundP2PMessages(device2);
expect(queryExecutor?.getAllOutboundP2PMessages(device2).length).toBe(0);
});
+
+ it('should set ciphertext for given message', () => {
+ 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<OutboundP2PMessage>;
+ setCiphertextForOutboundP2PMessage(
+ messageID: string,
+ deviceID: string,
+ ciphertext: string,
+ ): void;
addInboundP2PMessage(message: InboundP2PMessage): void;
getAllInboundP2PMessage(): $ReadOnlyArray<InboundP2PMessage>;

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 6, 11:44 PM (22 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5841171
Default Alt Text
D12070.1765064652.diff (5 KB)

Event Timeline