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 @@ -101,6 +101,8 @@ restoreFromBackupLog(const std::vector &backupLog) const = 0; virtual void addMessagesToDevice( const std::vector &messages) const = 0; + virtual std::vector + getAllMessagesToDevice(const std::string &deviceID) const = 0; #ifdef EMSCRIPTEN virtual std::vector getAllThreadsWeb() const = 0; 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 @@ -114,6 +114,8 @@ const std::vector &backupLog) const override; void addMessagesToDevice( const std::vector &messages) const override; + std::vector + getAllMessagesToDevice(const std::string &deviceID) const override; #ifdef EMSCRIPTEN std::vector getAllThreadsWeb() const override; 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 @@ -1708,6 +1708,29 @@ } } +std::vector +SQLiteQueryExecutor::getAllMessagesToDevice(const std::string &deviceID) const { + std::string query = + "SELECT * FROM messages_to_device " + "WHERE device_id = ? " + "ORDER BY timestamp;"; + + SQLiteStatementWrapper preparedSQL( + SQLiteQueryExecutor::getConnection(), + query, + "Failed to get all messages to device"); + + sqlite3_bind_text(preparedSQL, 1, deviceID.c_str(), -1, SQLITE_TRANSIENT); + + std::vector messages; + for (int stepResult = sqlite3_step(preparedSQL); stepResult == SQLITE_ROW; + stepResult = sqlite3_step(preparedSQL)) { + messages.emplace_back( + ClientMessageToDevice(MessageToDevice::fromSQLResult(preparedSQL, 0))); + } + + return messages; +} #ifdef EMSCRIPTEN std::vector SQLiteQueryExecutor::getAllThreadsWeb() const { auto threads = this->getAllThreads(); 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$@