Page MenuHomePhabricator

D13897.id45783.diff
No OneTemporary

D13897.id45783.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
@@ -174,6 +174,8 @@
virtual std::vector<InboundP2PMessage> getAllInboundP2PMessage() const = 0;
virtual void
removeInboundP2PMessages(const std::vector<std::string> &ids) const = 0;
+ virtual std::vector<InboundP2PMessage>
+ getInboundP2PMessagesByID(const std::vector<std::string> &ids) const = 0;
virtual std::vector<MessageEntity>
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<InboundP2PMessage> getAllInboundP2PMessage() const override;
void
removeInboundP2PMessages(const std::vector<std::string> &ids) const override;
+ std::vector<InboundP2PMessage>
+ getInboundP2PMessagesByID(const std::vector<std::string> &ids) const override;
std::vector<MessageEntity>
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<InboundP2PMessage> SQLiteQueryExecutor::getInboundP2PMessagesByID(
+ const std::vector<std::string> &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<InboundP2PMessage>(
+ SQLiteQueryExecutor::getConnection(), getInboundP2PMessageSQL, ids);
+}
+
std::vector<MessageEntity>
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$@<O00001
literal 0
Hc$@<O00001
diff --git a/web/shared-worker/queries/inbound-p2p-message-queries.test.js b/web/shared-worker/queries/inbound-p2p-message-queries.test.js
--- a/web/shared-worker/queries/inbound-p2p-message-queries.test.js
+++ b/web/shared-worker/queries/inbound-p2p-message-queries.test.js
@@ -77,4 +77,10 @@
expect(messages.length).toBe(2);
expect(messages).toStrictEqual([TEST_MSG_1, TEST_MSG_3]);
});
+ it('should return message by id', () => {
+ 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<InboundP2PMessage>;
removeInboundP2PMessages(ids: $ReadOnlyArray<string>): void;
+ getInboundP2PMessagesByID(
+ ids: $ReadOnlyArray<string>,
+ ): $ReadOnlyArray<InboundP2PMessage>;
getRelatedMessagesWeb(id: string): $ReadOnlyArray<MessageEntity>;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 5:46 AM (13 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569240
Default Alt Text
D13897.id45783.diff (4 KB)

Event Timeline