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 @@ -23,6 +23,10 @@ * following the RAII pattern */ class DatabaseQueryExecutor { + virtual void setMetadata(std::string entry_name, std::string data) const = 0; + virtual void clearMetadata(std::string entry_name) const = 0; + virtual std::string getMetadata(std::string entry_name) const = 0; + public: virtual std::string getDraft(std::string key) const = 0; virtual std::unique_ptr getThread(std::string threadID) 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 @@ -13,6 +13,9 @@ void migrate() const; static void assign_encryption_key(); static auto &getStorage(); + void setMetadata(std::string entry_name, std::string data) const override; + void clearMetadata(std::string entry_name) const override; + std::string getMetadata(std::string entry_name) const override; static std::once_flag initialized; static int sqlcipherEncryptionKeySize; 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 @@ -899,30 +899,38 @@ } void SQLiteQueryExecutor::setNotifyToken(std::string token) const { - Metadata entry{ - "notify_token", - token, - }; - SQLiteQueryExecutor::getStorage().replace(entry); + this->setMetadata("notify_token", token); } void SQLiteQueryExecutor::clearNotifyToken() const { - SQLiteQueryExecutor::getStorage().remove("notify_token"); + this->clearMetadata("notify_token"); } void SQLiteQueryExecutor::setCurrentUserID(std::string userID) const { + this->setMetadata("current_user_id", userID); +} + +std::string SQLiteQueryExecutor::getCurrentUserID() const { + return this->getMetadata("current_user_id"); +} + +void SQLiteQueryExecutor::setMetadata(std::string entry_name, std::string data) + const { Metadata entry{ - "current_user_id", - userID, + entry_name, + data, }; SQLiteQueryExecutor::getStorage().replace(entry); } -std::string SQLiteQueryExecutor::getCurrentUserID() const { - std::unique_ptr currentUserID = - SQLiteQueryExecutor::getStorage().get_pointer( - "current_user_id"); - return (currentUserID == nullptr) ? "" : currentUserID->data; +void SQLiteQueryExecutor::clearMetadata(std::string entry_name) const { + SQLiteQueryExecutor::getStorage().remove(entry_name); +} + +std::string SQLiteQueryExecutor::getMetadata(std::string entry_name) const { + std::unique_ptr entry = + SQLiteQueryExecutor::getStorage().get_pointer(entry_name); + return (entry == nullptr) ? "" : entry->data; } void SQLiteQueryExecutor::clearSensitiveData() const {