diff --git a/native/cpp/CommonCpp/NativeModules/MessageStoreOperations.h b/native/cpp/CommonCpp/NativeModules/MessageStoreOperations.h --- a/native/cpp/CommonCpp/NativeModules/MessageStoreOperations.h +++ b/native/cpp/CommonCpp/NativeModules/MessageStoreOperations.h @@ -210,4 +210,56 @@ std::vector thread_ids; }; +class RemoveMessageStoreLocalMessageInfosOperation : public DBOperationBase { +public: + RemoveMessageStoreLocalMessageInfosOperation( + jsi::Runtime &rt, + const jsi::Object &payload) + : ids{} { + auto payload_ids = payload.getProperty(rt, "ids").asObject(rt).asArray(rt); + for (size_t idx = 0; idx < payload_ids.size(rt); idx++) { + this->ids.push_back( + payload_ids.getValueAtIndex(rt, idx).asString(rt).utf8(rt)); + } + } + + virtual void execute() override { + DatabaseManager::getQueryExecutor().removeMessageStoreLocalMessageInfos( + this->ids); + } + +private: + std::vector ids; +}; + +class ReplaceMessageStoreLocalMessageInfoOperation : public DBOperationBase { +public: + ReplaceMessageStoreLocalMessageInfoOperation( + jsi::Runtime &rt, + const jsi::Object &payload) + : localMessageInfo{} { + std::string id = payload.getProperty(rt, "id").asString(rt).utf8(rt); + std::string local_message_info = + payload.getProperty(rt, "localMessageInfo").asString(rt).utf8(rt); + + this->localMessageInfo = LocalMessageInfo{id, local_message_info}; + } + + virtual void execute() override { + DatabaseManager::getQueryExecutor().replaceMessageStoreLocalMessageInfo( + this->localMessageInfo); + } + +private: + LocalMessageInfo localMessageInfo; +}; + +class RemoveAllMessageStoreLocalMessageInfosOperation : public DBOperationBase { +public: + virtual void execute() override { + DatabaseManager::getQueryExecutor() + .removeAllMessageStoreLocalMessageInfos(); + } +}; + } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.h --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.h +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.h @@ -24,6 +24,10 @@ static OperationType REMOVE_MESSAGE_THREADS_OPERATION; static OperationType REMOVE_ALL_MESSAGE_THREADS_OPERATION; + static OperationType REPLACE_MESSAGE_STORE_LOCAL_MESSAGE_INFO_OPERATION; + static OperationType REMOVE_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION; + static OperationType REMOVE_ALL_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION; + public: MessageStore(std::shared_ptr jsInvoker); @@ -38,6 +42,11 @@ jsi::Array parseDBMessageStoreThreads( jsi::Runtime &rt, std::shared_ptr> threadsVectorPtr) const; + + jsi::Array parseDBMessageStoreLocalMessageInfos( + jsi::Runtime &rt, + std::shared_ptr> localMessageInfosVectorPtr) + const; }; } // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.cpp b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.cpp --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.cpp +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/MessageStore.cpp @@ -19,6 +19,14 @@ OperationType MessageStore::REMOVE_ALL_MESSAGE_THREADS_OPERATION = "remove_all_threads"; +OperationType MessageStore::REPLACE_MESSAGE_STORE_LOCAL_MESSAGE_INFO_OPERATION = + "replace_local_message_info"; +OperationType MessageStore::REMOVE_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION = + "remove_local_message_infos"; +OperationType + MessageStore::REMOVE_ALL_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION = + "remove_all_local_message_infos"; + MessageStore::MessageStore( std::shared_ptr jsInvoker) : BaseDataStore(jsInvoker) { @@ -93,24 +101,25 @@ std::make_unique()); continue; } + if (op_type == REMOVE_ALL_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION) { + messageStoreOps.push_back( + std::make_unique()); + continue; + } auto payload_obj = op.getProperty(rt, "payload").asObject(rt); if (op_type == REMOVE_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); - } else if (op_type == REMOVE_MSGS_FOR_THREADS_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); - } else if (op_type == REPLACE_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); - } else if (op_type == REKEY_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); - } else if (op_type == REPLACE_MESSAGE_THREADS_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); @@ -118,6 +127,14 @@ messageStoreOps.push_back( std::make_unique( rt, payload_obj)); + } else if (op_type == REPLACE_MESSAGE_STORE_LOCAL_MESSAGE_INFO_OPERATION) { + messageStoreOps.push_back( + std::make_unique( + rt, payload_obj)); + } else if (op_type == REMOVE_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION) { + messageStoreOps.push_back( + std::make_unique( + rt, payload_obj)); } else { throw std::runtime_error("unsupported operation: " + op_type); }