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 @@ -172,6 +172,10 @@ removeInboundP2PMessages(const std::vector &ids) const = 0; virtual std::vector getRelatedMessages(const std::string &messageID) const = 0; + virtual void updateMessageSearchIndex( + std::string original_message_id, + std::string message_id, + std::string processed_content) 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 @@ -185,6 +185,10 @@ removeInboundP2PMessages(const std::vector &ids) const override; std::vector getRelatedMessages(const std::string &messageID) const override; + void updateMessageSearchIndex( + std::string original_message_id, + std::string message_id, + std::string processed_content) 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 @@ -1502,6 +1502,54 @@ SQLiteQueryExecutor::getConnection(), replaceMessageSQL, message); } +void SQLiteQueryExecutor::updateMessageSearchIndex( + std::string original_message_id, + std::string message_id, + std::string processed_content) const { + + sqlite3 *db = SQLiteQueryExecutor::getConnection(); + int bindResult = 0; + std::unique_ptr preparedSQL; + + static std::string insertMessageSearchResultSQL = + "INSERT INTO message_search(" + " original_message_id, message_id, processed_content) " + "VALUES (?, ?, ?);"; + static std::string updateMessageSearchResultSQL = + "UPDATE message_search " + "SET message_id = ?, processed_content = ? " + "WHERE original_message_id = ?;"; + + if (original_message_id == message_id) { + preparedSQL = std::make_unique( + db, + insertMessageSearchResultSQL, + "Failed to update message search entry."); + + bindStringToSQL(original_message_id, *preparedSQL, 1); + bindStringToSQL(message_id, *preparedSQL, 2); + bindResult = bindStringToSQL(processed_content, *preparedSQL, 3); + } else { + preparedSQL = std::make_unique( + db, + updateMessageSearchResultSQL, + "Failed to update message search entry."); + + bindStringToSQL(message_id, *preparedSQL, 1); + bindStringToSQL(processed_content, *preparedSQL, 2); + bindResult = bindStringToSQL(original_message_id, *preparedSQL, 3); + } + + if (bindResult != SQLITE_OK) { + std::stringstream error_message; + error_message << "Failed to bind key to SQL statement. Details: " + << sqlite3_errstr(bindResult) << std::endl; + throw std::runtime_error(error_message.str()); + } + + sqlite3_step(*preparedSQL); +} + void SQLiteQueryExecutor::rekeyMessage(std::string from, std::string to) const { static std::string rekeyMessageSQL = "UPDATE OR REPLACE messages " 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$@