Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3346453
D12047.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
18 KB
Referenced Files
None
Subscribers
None
D12047.diff
View Options
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
@@ -9,6 +9,15 @@
+status: string,
};
+export type OutboundP2PMessage = {
+ +messageID: string,
+ +deviceID: string,
+ +userID: string,
+ +timestamp: string,
+ +plaintext: string,
+ +ciphertext: string,
+};
+
export type SQLiteAPI = {
// read operations
+getAllInboundP2PMessage: () => Promise<InboundP2PMessage[]>,
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
@@ -9,9 +9,9 @@
#include "entities/KeyserverInfo.h"
#include "entities/Message.h"
#include "entities/MessageStoreThread.h"
-#include "entities/MessageToDevice.h"
#include "entities/OlmPersistAccount.h"
#include "entities/OlmPersistSession.h"
+#include "entities/OutboundP2PMessage.h"
#include "entities/PersistItem.h"
#include "entities/Report.h"
#include "entities/SyncedMetadataEntry.h"
@@ -135,14 +135,14 @@
std::string mainCompactionEncryptionKey) const = 0;
virtual void
restoreFromBackupLog(const std::vector<std::uint8_t> &backupLog) const = 0;
- virtual void addMessagesToDevice(
- const std::vector<ClientMessageToDevice> &messages) const = 0;
- virtual std::vector<ClientMessageToDevice>
- getAllMessagesToDevice(const std::string &deviceID) const = 0;
- virtual void removeMessagesToDeviceOlderThan(
- const ClientMessageToDevice &lastConfirmedMessage) const = 0;
+ virtual void addOutboundP2PMessages(
+ const std::vector<OutboundP2PMessage> &messages) const = 0;
+ virtual std::vector<OutboundP2PMessage>
+ getAllOutboundP2PMessages(const std::string &deviceID) const = 0;
+ virtual void removeOutboundP2PMessagesOlderThan(
+ const OutboundP2PMessage &lastConfirmedMessage) const = 0;
virtual void
- removeAllMessagesForDevice(const std::string &deviceID) const = 0;
+ removeAllOutboundP2PMessages(const std::string &deviceID) 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
@@ -145,13 +145,13 @@
std::string mainCompactionEncryptionKey) const override;
void restoreFromBackupLog(
const std::vector<std::uint8_t> &backupLog) const override;
- void addMessagesToDevice(
- const std::vector<ClientMessageToDevice> &messages) const override;
- std::vector<ClientMessageToDevice>
- getAllMessagesToDevice(const std::string &deviceID) const override;
- void removeMessagesToDeviceOlderThan(
- const ClientMessageToDevice &lastConfirmedMessage) const override;
- void removeAllMessagesForDevice(const std::string &deviceID) const override;
+ void addOutboundP2PMessages(
+ const std::vector<OutboundP2PMessage> &messages) const override;
+ std::vector<OutboundP2PMessage>
+ getAllOutboundP2PMessages(const std::string &deviceID) const override;
+ void removeOutboundP2PMessagesOlderThan(
+ const OutboundP2PMessage &lastConfirmedMessage) const override;
+ void removeAllOutboundP2PMessages(const std::string &deviceID) 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
@@ -2077,22 +2077,23 @@
return (entry == nullptr) ? "" : entry->data;
}
-void SQLiteQueryExecutor::addMessagesToDevice(
- const std::vector<ClientMessageToDevice> &messages) const {
- static std::string addMessageToDevice =
+void SQLiteQueryExecutor::addOutboundP2PMessages(
+ const std::vector<OutboundP2PMessage> &messages) const {
+ static std::string addMessage =
"REPLACE INTO messages_to_device ("
" message_id, device_id, user_id, timestamp, plaintext, ciphertext) "
"VALUES (?, ?, ?, ?, ?, ?);";
- for (const ClientMessageToDevice &clientMessage : messages) {
- MessageToDevice message = clientMessage.toMessageToDevice();
- replaceEntity<MessageToDevice>(
- SQLiteQueryExecutor::getConnection(), addMessageToDevice, message);
+ for (const OutboundP2PMessage &clientMessage : messages) {
+ SQLiteOutboundP2PMessage message =
+ clientMessage.toSQLiteOutboundP2PMessage();
+ replaceEntity<SQLiteOutboundP2PMessage>(
+ SQLiteQueryExecutor::getConnection(), addMessage, message);
}
}
-std::vector<ClientMessageToDevice>
-SQLiteQueryExecutor::getAllMessagesToDevice(const std::string &deviceID) const {
+std::vector<OutboundP2PMessage> SQLiteQueryExecutor::getAllOutboundP2PMessages(
+ const std::string &deviceID) const {
std::string query =
"SELECT * FROM messages_to_device "
"WHERE device_id = ? "
@@ -2105,24 +2106,24 @@
sqlite3_bind_text(preparedSQL, 1, deviceID.c_str(), -1, SQLITE_TRANSIENT);
- std::vector<ClientMessageToDevice> messages;
+ std::vector<OutboundP2PMessage> messages;
for (int stepResult = sqlite3_step(preparedSQL); stepResult == SQLITE_ROW;
stepResult = sqlite3_step(preparedSQL)) {
- messages.emplace_back(
- ClientMessageToDevice(MessageToDevice::fromSQLResult(preparedSQL, 0)));
+ messages.emplace_back(OutboundP2PMessage(
+ SQLiteOutboundP2PMessage::fromSQLResult(preparedSQL, 0)));
}
return messages;
}
-void SQLiteQueryExecutor::removeMessagesToDeviceOlderThan(
- const ClientMessageToDevice &lastConfirmedMessageClient) const {
+void SQLiteQueryExecutor::removeOutboundP2PMessagesOlderThan(
+ const OutboundP2PMessage &lastConfirmedMessageClient) const {
static std::string query =
"DELETE FROM messages_to_device "
"WHERE timestamp <= ? AND device_id IN (?);";
- MessageToDevice lastConfirmedMessage =
- lastConfirmedMessageClient.toMessageToDevice();
+ SQLiteOutboundP2PMessage lastConfirmedMessage =
+ lastConfirmedMessageClient.toSQLiteOutboundP2PMessage();
comm::SQLiteStatementWrapper preparedSQL(
SQLiteQueryExecutor::getConnection(),
@@ -2140,12 +2141,12 @@
int result = sqlite3_step(preparedSQL);
if (result != SQLITE_DONE) {
throw std::runtime_error(
- "Failed to execute removeMessagesToDeviceOlderThan statement: " +
+ "Failed to execute removeOutboundP2PMessagesOlderThan statement: " +
std::string(sqlite3_errmsg(SQLiteQueryExecutor::getConnection())));
}
}
-void SQLiteQueryExecutor::removeAllMessagesForDevice(
+void SQLiteQueryExecutor::removeAllOutboundP2PMessages(
const std::string &deviceID) const {
static std::string removeMessagesSQL =
"DELETE FROM messages_to_device "
diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h b/native/cpp/CommonCpp/DatabaseManagers/entities/OutboundP2PMessage.h
rename from native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h
rename to native/cpp/CommonCpp/DatabaseManagers/entities/OutboundP2PMessage.h
--- a/native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/entities/OutboundP2PMessage.h
@@ -8,7 +8,7 @@
namespace comm {
-struct MessageToDevice {
+struct SQLiteOutboundP2PMessage {
std::string message_id;
std::string device_id;
std::string user_id;
@@ -16,8 +16,8 @@
std::string plaintext;
std::string ciphertext;
- static MessageToDevice fromSQLResult(sqlite3_stmt *sqlRow, int idx) {
- return MessageToDevice{
+ static SQLiteOutboundP2PMessage fromSQLResult(sqlite3_stmt *sqlRow, int idx) {
+ return SQLiteOutboundP2PMessage{
getStringFromSQLRow(sqlRow, idx),
getStringFromSQLRow(sqlRow, idx + 1),
getStringFromSQLRow(sqlRow, idx + 2),
@@ -37,7 +37,7 @@
}
};
-struct ClientMessageToDevice {
+struct OutboundP2PMessage {
std::string message_id;
std::string device_id;
std::string user_id;
@@ -45,9 +45,9 @@
std::string plaintext;
std::string ciphertext;
- ClientMessageToDevice() = default;
+ OutboundP2PMessage() = default;
- ClientMessageToDevice(const MessageToDevice &msg) {
+ OutboundP2PMessage(const SQLiteOutboundP2PMessage &msg) {
message_id = msg.message_id;
device_id = msg.device_id;
user_id = msg.user_id;
@@ -56,8 +56,8 @@
ciphertext = msg.ciphertext;
}
- MessageToDevice toMessageToDevice() const {
- MessageToDevice msg;
+ SQLiteOutboundP2PMessage toSQLiteOutboundP2PMessage() const {
+ SQLiteOutboundP2PMessage msg;
msg.message_id = message_id;
msg.device_id = device_id;
msg.user_id = user_id;
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/OutboundP2PMessage.h"
#include <emscripten/bind.h>
#include <vector>
@@ -114,13 +114,13 @@
.field("sessionData", &OlmPersistSession::session_data)
.field("version", &OlmPersistSession::version);
- value_object<ClientMessageToDevice>("ClientMessageToDevice")
- .field("messageID", &ClientMessageToDevice::message_id)
- .field("deviceID", &ClientMessageToDevice::device_id)
- .field("userID", &ClientMessageToDevice::user_id)
- .field("timestamp", &ClientMessageToDevice::timestamp)
- .field("plaintext", &ClientMessageToDevice::plaintext)
- .field("ciphertext", &ClientMessageToDevice::ciphertext);
+ value_object<OutboundP2PMessage>("OutboundP2PMessage")
+ .field("messageID", &OutboundP2PMessage::message_id)
+ .field("deviceID", &OutboundP2PMessage::device_id)
+ .field("userID", &OutboundP2PMessage::user_id)
+ .field("timestamp", &OutboundP2PMessage::timestamp)
+ .field("plaintext", &OutboundP2PMessage::plaintext)
+ .field("ciphertext", &OutboundP2PMessage::ciphertext);
value_object<InboundP2PMessage>("InboundP2PMessage")
.field("messageID", &InboundP2PMessage::message_id)
@@ -262,16 +262,17 @@
.function(
"restoreFromBackupLog", &SQLiteQueryExecutor::restoreFromBackupLog)
.function(
- "addMessagesToDevice", &SQLiteQueryExecutor::addMessagesToDevice)
+ "addOutboundP2PMessages",
+ &SQLiteQueryExecutor::addOutboundP2PMessages)
.function(
- "removeMessagesToDeviceOlderThan",
- &SQLiteQueryExecutor::removeMessagesToDeviceOlderThan)
+ "removeOutboundP2PMessagesOlderThan",
+ &SQLiteQueryExecutor::removeOutboundP2PMessagesOlderThan)
.function(
- "removeAllMessagesForDevice",
- &SQLiteQueryExecutor::removeAllMessagesForDevice)
+ "removeAllOutboundP2PMessages",
+ &SQLiteQueryExecutor::removeAllOutboundP2PMessages)
.function(
- "getAllMessagesToDevice",
- &SQLiteQueryExecutor::getAllMessagesToDevice)
+ "getAllOutboundP2PMessages",
+ &SQLiteQueryExecutor::getAllOutboundP2PMessages)
.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/message-to-device-queries.test.js b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
rename from web/shared-worker/queries/message-to-device-queries.test.js
rename to web/shared-worker/queries/outbound-p2p-message-queries.test.js
--- a/web/shared-worker/queries/message-to-device-queries.test.js
+++ b/web/shared-worker/queries/outbound-p2p-message-queries.test.js
@@ -1,11 +1,10 @@
// @flow
+import type { OutboundP2PMessage } from 'lib/types/sqlite-types.js';
+
import { getDatabaseModule } from '../db-module.js';
import type { EmscriptenModule } from '../types/module.js';
-import {
- type ClientMessageToDevice,
- type SQLiteQueryExecutor,
-} from '../types/sqlite-query-executor.js';
+import { type SQLiteQueryExecutor } from '../types/sqlite-query-executor.js';
import { clearSensitiveData } from '../utils/db-utils.js';
const FILE_PATH = 'test.sqlite';
@@ -18,7 +17,7 @@
const device1 = 'device-1';
const device2 = 'device-2';
-const TEST_MSG_1: ClientMessageToDevice = {
+const TEST_MSG_1: OutboundP2PMessage = {
messageID: 'id-1',
deviceID: device1,
userID: 'user-1',
@@ -26,7 +25,7 @@
plaintext: 'decrypted-1',
ciphertext: 'encrypted-1',
};
-const TEST_MSG_2: ClientMessageToDevice = {
+const TEST_MSG_2: OutboundP2PMessage = {
messageID: 'id-2',
deviceID: device2,
userID: 'user-2',
@@ -35,7 +34,7 @@
ciphertext: 'encrypted-2',
};
-const TEST_MSG_3: ClientMessageToDevice = {
+const TEST_MSG_3: OutboundP2PMessage = {
messageID: 'id-3',
deviceID: device1,
userID: 'user-1',
@@ -44,7 +43,7 @@
ciphertext: 'encrypted-3',
};
-const TEST_MSG_4: ClientMessageToDevice = {
+const TEST_MSG_4: OutboundP2PMessage = {
messageID: 'id-4',
deviceID: device1,
userID: 'user-1',
@@ -55,7 +54,7 @@
const device1MessagesOrdered = [TEST_MSG_3, TEST_MSG_1, TEST_MSG_4];
-describe('Message to device queries', () => {
+describe('Outbound P2P messages queries', () => {
let queryExecutor: ?SQLiteQueryExecutor = null;
let dbModule: ?EmscriptenModule = null;
@@ -71,7 +70,7 @@
if (!queryExecutor) {
throw new Error('SQLiteQueryExecutor is missing');
}
- queryExecutor?.addMessagesToDevice([
+ queryExecutor?.addOutboundP2PMessages([
TEST_MSG_1,
TEST_MSG_2,
TEST_MSG_3,
@@ -87,31 +86,31 @@
});
it('should return all messages', () => {
- expect(queryExecutor?.getAllMessagesToDevice(device1).length).toBe(3);
- expect(queryExecutor?.getAllMessagesToDevice(device2).length).toBe(1);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device1).length).toBe(3);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device2).length).toBe(1);
});
it('should return messages in correct order', () => {
- const messages = queryExecutor?.getAllMessagesToDevice(device1);
+ const messages = queryExecutor?.getAllOutboundP2PMessages(device1);
expect(messages).toStrictEqual(device1MessagesOrdered);
});
it('should remove when there is only one message', () => {
- queryExecutor?.removeMessagesToDeviceOlderThan(TEST_MSG_2);
- expect(queryExecutor?.getAllMessagesToDevice(device2).length).toBe(0);
+ queryExecutor?.removeOutboundP2PMessagesOlderThan(TEST_MSG_2);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device2).length).toBe(0);
});
it('should remove older messages', () => {
- queryExecutor?.removeMessagesToDeviceOlderThan(TEST_MSG_1);
- expect(queryExecutor?.getAllMessagesToDevice(device1)).toStrictEqual([
+ queryExecutor?.removeOutboundP2PMessagesOlderThan(TEST_MSG_1);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device1)).toStrictEqual([
TEST_MSG_4,
]);
});
it('should remove all messages for given device', () => {
- queryExecutor?.removeAllMessagesForDevice(device1);
- expect(queryExecutor?.getAllMessagesToDevice(device1).length).toBe(0);
- queryExecutor?.removeAllMessagesForDevice(device2);
- expect(queryExecutor?.getAllMessagesToDevice(device2).length).toBe(0);
+ queryExecutor?.removeAllOutboundP2PMessages(device1);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device1).length).toBe(0);
+ queryExecutor?.removeAllOutboundP2PMessages(device2);
+ expect(queryExecutor?.getAllOutboundP2PMessages(device2).length).toBe(0);
});
});
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,12 +9,15 @@
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 { InboundP2PMessage } from 'lib/types/sqlite-types.js';
+import type {
+ OutboundP2PMessage,
+ InboundP2PMessage,
+} from 'lib/types/sqlite-types.js';
import {
- type WebClientDBThreadInfo,
- type NullableString,
type NullableInt,
+ type NullableString,
+ type WebClientDBThreadInfo,
} from './entities.js';
export type WebMessage = {
@@ -43,15 +46,6 @@
+version: number,
};
-export type ClientMessageToDevice = {
- +messageID: string,
- +deviceID: string,
- +userID: string,
- +timestamp: string,
- +plaintext: string,
- +ciphertext: string,
-};
-
declare export class SQLiteQueryExecutor {
constructor(sqliteFilePath: string): void;
@@ -163,14 +157,14 @@
restoreFromBackupLog(backupLog: Uint8Array): void;
- addMessagesToDevice(messages: $ReadOnlyArray<ClientMessageToDevice>): void;
- removeMessagesToDeviceOlderThan(
- lastConfirmedMessage: ClientMessageToDevice,
+ addOutboundP2PMessages(messages: $ReadOnlyArray<OutboundP2PMessage>): void;
+ removeOutboundP2PMessagesOlderThan(
+ lastConfirmedMessage: OutboundP2PMessage,
): void;
- removeAllMessagesForDevice(deviceID: string): void;
- getAllMessagesToDevice(
+ removeAllOutboundP2PMessages(deviceID: string): void;
+ getAllOutboundP2PMessages(
deviceID: string,
- ): $ReadOnlyArray<ClientMessageToDevice>;
+ ): $ReadOnlyArray<OutboundP2PMessage>;
addInboundP2PMessage(message: InboundP2PMessage): void;
getAllInboundP2PMessage(): $ReadOnlyArray<InboundP2PMessage>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 8:49 AM (18 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2569932
Default Alt Text
D12047.diff (18 KB)
Attached To
Mode
D12047: [lib] rename `MessageToDevice` from SQLite to `OutboundP2PMessage`
Attached
Detach File
Event Timeline
Log In to Comment