diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h b/native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/MessageToDevice.h @@ -0,0 +1,71 @@ +#pragma once + +#include +#include +#include + +#include "SQLiteDataConverters.h" + +namespace comm { + +struct MessageToDevice { + std::string message_id; + std::string device_id; + std::string user_id; + int64_t timestamp; + std::string plaintext; + std::string ciphertext; + + static MessageToDevice fromSQLResult(sqlite3_stmt *sqlRow, int idx) { + return MessageToDevice{ + getStringFromSQLRow(sqlRow, idx), + getStringFromSQLRow(sqlRow, idx + 1), + getStringFromSQLRow(sqlRow, idx + 2), + getInt64FromSQLRow(sqlRow, idx + 3), + getStringFromSQLRow(sqlRow, idx + 4), + getStringFromSQLRow(sqlRow, idx + 5), + }; + } + + int bindToSQL(sqlite3_stmt *sql, int idx) const { + bindStringToSQL(message_id, sql, idx); + bindStringToSQL(device_id, sql, idx + 1); + bindStringToSQL(user_id, sql, idx + 2); + bindInt64ToSQL(timestamp, sql, idx + 3); + bindStringToSQL(plaintext, sql, idx + 4); + return bindStringToSQL(ciphertext, sql, idx + 5); + } +}; + +struct ClientMessageToDevice { + std::string message_id; + std::string device_id; + std::string user_id; + std::string timestamp; + std::string plaintext; + std::string ciphertext; + + ClientMessageToDevice() = default; + + ClientMessageToDevice(const MessageToDevice &msg) { + message_id = msg.message_id; + device_id = msg.device_id; + user_id = msg.user_id; + timestamp = std::to_string(msg.timestamp); + plaintext = msg.plaintext; + ciphertext = msg.ciphertext; + } + + MessageToDevice toMessageToDevice() const { + MessageToDevice msg; + msg.message_id = message_id; + msg.device_id = device_id; + msg.user_id = user_id; + msg.timestamp = std::stoll(timestamp); + msg.plaintext = plaintext; + msg.ciphertext = ciphertext; + return msg; + } +}; + +} // namespace comm diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -1,4 +1,5 @@ #include "SQLiteQueryExecutor.cpp" +#include "entities/MessageToDevice.h" #include "entities/Nullable.h" #include @@ -96,6 +97,14 @@ .field("targetUserID", &OlmPersistSession::target_user_id) .field("sessionData", &OlmPersistSession::session_data); + value_object("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); + class_("SQLiteQueryExecutor") .constructor() .function("updateDraft", &SQLiteQueryExecutor::updateDraft) diff --git a/web/database/_generated/comm_query_executor.wasm b/web/database/_generated/comm_query_executor.wasm index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@