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 @@ -7,6 +7,7 @@ #include "entities/MessageStoreThread.h" #include "entities/OlmPersistAccount.h" #include "entities/OlmPersistSession.h" +#include "entities/Report.h" #include "entities/Thread.h" #include @@ -61,6 +62,10 @@ virtual void removeThreads(std::vector ids) const = 0; virtual void replaceThread(const Thread &thread) const = 0; virtual void removeAllThreads() const = 0; + virtual void replaceReport(const Report &report) const = 0; + virtual void removeReports(const std::vector &ids) const = 0; + virtual void removeAllReports() const = 0; + virtual std::vector getAllReports() const = 0; virtual void beginTransaction() const = 0; virtual void commitTransaction() const = 0; virtual void rollbackTransaction() 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 @@ -59,6 +59,10 @@ void removeThreads(std::vector ids) const override; void replaceThread(const Thread &thread) const override; void removeAllThreads() const override; + void replaceReport(const Report &report) const override; + void removeReports(const std::vector &ids) const override; + void removeAllReports() const override; + std::vector getAllReports() const override; void beginTransaction() const override; void commitTransaction() const override; void rollbackTransaction() 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 @@ -375,6 +375,15 @@ return create_table(db, query, "message_store_threads"); } +bool create_reports_table(sqlite3 *db) { + std::string query = + "CREATE TABLE IF NOT EXISTS reports (" + " id TEXT UNIQUE PRIMARY KEY NOT NULL," + " report TEXT NOT NULL" + ");"; + return create_table(db, query, "reports"); +} + bool create_schema(sqlite3 *db) { char *error; sqlite3_exec( @@ -445,6 +454,11 @@ " last_pruned BIGINT NOT NULL" ");" + "CREATE TABLE IF NOT EXISTS reports (" + " id TEXT UNIQUE PRIMARY KEY NOT NULL," + " report TEXT NOT NULL" + ");" + "CREATE INDEX IF NOT EXISTS media_idx_container" " ON media (container);" @@ -682,7 +696,8 @@ {25, {add_not_null_constraint_to_metadata, true}}, {26, {add_avatar_column_to_threads_table, true}}, {27, {add_pinned_count_column_to_threads, true}}, - {28, {create_message_store_threads_table, true}}}}; + {28, {create_message_store_threads_table, true}}, + {29, {create_reports_table, true}}}}; enum class MigrationResult { SUCCESS, FAILURE, NOT_APPLIED }; @@ -896,7 +911,11 @@ make_column("start_reached", &MessageStoreThread::start_reached), make_column( "last_navigated_to", &MessageStoreThread::last_navigated_to), - make_column("last_pruned", &MessageStoreThread::last_pruned))); + make_column("last_pruned", &MessageStoreThread::last_pruned)), + make_table( + "reports", + make_column("id", &Report::id, unique(), primary_key()), + make_column("report", &Report::report))); storage.on_open = on_database_open; return storage; } @@ -1122,6 +1141,24 @@ SQLiteQueryExecutor::getStorage().remove_all(); }; +void SQLiteQueryExecutor::replaceReport(const Report &report) const { + SQLiteQueryExecutor::getStorage().replace(report); +} + +void SQLiteQueryExecutor::removeAllReports() const { + SQLiteQueryExecutor::getStorage().remove_all(); +} + +void SQLiteQueryExecutor::removeReports( + const std::vector &ids) const { + SQLiteQueryExecutor::getStorage().remove_all( + where(in(&Report::id, ids))); +} + +std::vector SQLiteQueryExecutor::getAllReports() const { + return SQLiteQueryExecutor::getStorage().get_all(); +} + void SQLiteQueryExecutor::beginTransaction() const { SQLiteQueryExecutor::getStorage().begin_transaction(); } diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/Report.h b/native/cpp/CommonCpp/DatabaseManagers/entities/Report.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/Report.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace comm { + +struct Report { + std::string id; + std::string report; +}; + +} // namespace comm