diff --git a/native/cpp/CommonCpp/NativeModules/EntryStoreOperations.h b/native/cpp/CommonCpp/NativeModules/EntryStoreOperations.h --- a/native/cpp/CommonCpp/NativeModules/EntryStoreOperations.h +++ b/native/cpp/CommonCpp/NativeModules/EntryStoreOperations.h @@ -21,15 +21,18 @@ class ReplaceEntryOperation : public DBOperationBase { public: - ReplaceEntryOperation(EntryInfo &&entry) : entry{std::move(entry)} { + ReplaceEntryOperation(EntryInfo &&entry, bool backupItem) + : entry{std::move(entry)}, backupItem(backupItem) { } virtual void execute(DatabaseIdentifier id) override { - DatabaseManager::getQueryExecutor(id).replaceEntry(this->entry, false); + DatabaseManager::getQueryExecutor(id).replaceEntry( + this->entry, this->backupItem); } private: EntryInfo entry; + bool backupItem; }; class RemoveAllEntriesOperation : public DBOperationBase { 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 @@ -58,8 +58,11 @@ class ReplaceMessageOperation : public DBOperationBase { public: - ReplaceMessageOperation(jsi::Runtime &rt, const jsi::Object &payload) - : media_vector{} { + ReplaceMessageOperation( + jsi::Runtime &rt, + const jsi::Object &payload, + bool backupItem) + : media_vector{}, backupItem(backupItem) { auto msg_id = payload.getProperty(rt, "id").asString(rt).utf8(rt); @@ -115,15 +118,16 @@ DatabaseManager::getQueryExecutor().removeMediaForMessage(msg->id); for (auto &&media : this->media_vector) { DatabaseManager::getQueryExecutor().replaceMedia( - std::move(*media), false); + std::move(*media), this->backupItem); } DatabaseManager::getQueryExecutor().replaceMessage( - std::move(*this->msg), false); + std::move(*this->msg), this->backupItem); } private: std::unique_ptr msg; std::vector> media_vector; + bool backupItem; }; class RekeyMessageOperation : public DBOperationBase { @@ -154,8 +158,11 @@ class ReplaceMessageThreadsOperation : public DBOperationBase { public: - ReplaceMessageThreadsOperation(jsi::Runtime &rt, const jsi::Object &payload) - : msg_threads{} { + ReplaceMessageThreadsOperation( + jsi::Runtime &rt, + const jsi::Object &payload, + bool backupItem) + : msg_threads{}, backupItem(backupItem) { auto threads = payload.getProperty(rt, "threads").asObject(rt).asArray(rt); for (size_t idx = 0; idx < threads.size(rt); idx++) { auto thread = threads.getValueAtIndex(rt, idx).asObject(rt); @@ -171,11 +178,12 @@ virtual void execute(DatabaseIdentifier id) override { DatabaseManager::getQueryExecutor(id).replaceMessageStoreThreads( - this->msg_threads, false); + this->msg_threads, this->backupItem); } private: std::vector msg_threads; + bool backupItem; }; class RemoveAllMessageStoreThreadsOperation : public DBOperationBase { @@ -233,8 +241,9 @@ public: ReplaceMessageStoreLocalMessageInfoOperation( jsi::Runtime &rt, - const jsi::Object &payload) - : localMessageInfo{} { + const jsi::Object &payload, + bool backupItem) + : localMessageInfo{}, backupItem(backupItem) { std::string id = payload.getProperty(rt, "id").asString(rt).utf8(rt); std::string local_message_info = payload.getProperty(rt, "localMessageInfo").asString(rt).utf8(rt); @@ -244,11 +253,12 @@ virtual void execute(DatabaseIdentifier id) override { DatabaseManager::getQueryExecutor(id).replaceMessageStoreLocalMessageInfo( - this->localMessageInfo, false); + this->localMessageInfo, this->backupItem); } private: LocalMessageInfo localMessageInfo; + bool backupItem; }; class RemoveAllMessageStoreLocalMessageInfosOperation : public DBOperationBase { diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/EntryStore.cpp b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/EntryStore.cpp --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/EntryStore.cpp +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/EntryStore.cpp @@ -55,11 +55,12 @@ std::string id = entryObj.getProperty(rt, "id").asString(rt).utf8(rt); std::string entry_info = entryObj.getProperty(rt, "entry").asString(rt).utf8(rt); + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); EntryInfo entry{id, entry_info}; - entryStoreOps.push_back( - std::make_unique(std::move(entry))); + entryStoreOps.push_back(std::make_unique( + std::move(entry), isBackedUp)); } else { throw std::runtime_error("unsupported operation: " + opType); } 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 @@ -113,22 +113,26 @@ messageStoreOps.push_back( std::make_unique(rt, payload_obj)); } else if (op_type == REPLACE_OPERATION) { - messageStoreOps.push_back( - std::make_unique(rt, payload_obj)); + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); + messageStoreOps.push_back(std::make_unique( + rt, payload_obj, isBackedUp)); } else if (op_type == REKEY_OPERATION) { messageStoreOps.push_back( std::make_unique(rt, payload_obj)); } else if (op_type == REPLACE_MESSAGE_THREADS_OPERATION) { + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); messageStoreOps.push_back( - std::make_unique(rt, payload_obj)); + std::make_unique( + rt, payload_obj, isBackedUp)); } else if (op_type == REMOVE_MESSAGE_THREADS_OPERATION) { messageStoreOps.push_back( std::make_unique( rt, payload_obj)); } else if (op_type == REPLACE_MESSAGE_STORE_LOCAL_MESSAGE_INFO_OPERATION) { + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); messageStoreOps.push_back( std::make_unique( - rt, payload_obj)); + rt, payload_obj, isBackedUp)); } else if (op_type == REMOVE_MESSAGE_STORE_LOCAL_MESSAGE_INFOS_OPERATION) { messageStoreOps.push_back( std::make_unique( diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadActivityStore.cpp b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadActivityStore.cpp --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadActivityStore.cpp +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadActivityStore.cpp @@ -72,12 +72,13 @@ payloadObj.getProperty(rt, "threadActivityStoreEntry") .asString(rt) .utf8(rt); + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); ThreadActivityEntry threadActivityEntry{id, thread_activity_store_entry}; threadActivityStoreOps.push_back( std::make_unique( - std::move(threadActivityEntry))); + std::move(threadActivityEntry), isBackedUp)); } else { throw std::runtime_error("unsupported operation: " + opType); } diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadStore.cpp b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadStore.cpp --- a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadStore.cpp +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/DataStores/ThreadStore.cpp @@ -181,6 +181,8 @@ std::optional timestamps = maybeTimestamps.isString() ? std::optional(maybeTimestamps.asString(rt).utf8(rt)) : std::nullopt; + bool isBackedUp = op.getProperty(rt, "isBackedUp").asBool(); + Thread thread{ threadID, type, @@ -200,8 +202,8 @@ pinnedCount, timestamps}; - threadStoreOps.push_back( - std::make_unique(std::move(thread))); + threadStoreOps.push_back(std::make_unique( + std::move(thread), isBackedUp)); } else { throw std::runtime_error("unsupported operation: " + opType); } diff --git a/native/cpp/CommonCpp/NativeModules/ThreadActivityStoreOperations.h b/native/cpp/CommonCpp/NativeModules/ThreadActivityStoreOperations.h --- a/native/cpp/CommonCpp/NativeModules/ThreadActivityStoreOperations.h +++ b/native/cpp/CommonCpp/NativeModules/ThreadActivityStoreOperations.h @@ -24,17 +24,21 @@ class ReplaceThreadActivityEntryOperation : public DBOperationBase { public: - ReplaceThreadActivityEntryOperation(ThreadActivityEntry &&threadActivityEntry) - : threadActivityEntry{std::move(threadActivityEntry)} { + ReplaceThreadActivityEntryOperation( + ThreadActivityEntry &&threadActivityEntry, + bool backupItem) + : threadActivityEntry{std::move(threadActivityEntry)}, + backupItem(backupItem) { } virtual void execute(DatabaseIdentifier id) override { DatabaseManager::getQueryExecutor(id).replaceThreadActivityEntry( - this->threadActivityEntry, false); + this->threadActivityEntry, this->backupItem); } private: ThreadActivityEntry threadActivityEntry; + bool backupItem; }; class RemoveAllThreadActivityEntriesOperation : public DBOperationBase { diff --git a/native/cpp/CommonCpp/NativeModules/ThreadStoreOperations.h b/native/cpp/CommonCpp/NativeModules/ThreadStoreOperations.h --- a/native/cpp/CommonCpp/NativeModules/ThreadStoreOperations.h +++ b/native/cpp/CommonCpp/NativeModules/ThreadStoreOperations.h @@ -23,15 +23,18 @@ class ReplaceThreadOperation : public DBOperationBase { public: - ReplaceThreadOperation(Thread &&thread) : thread{std::move(thread)} { + ReplaceThreadOperation(Thread &&thread, bool backupItem) + : thread{std::move(thread)}, backupItem(backupItem) { } virtual void execute(DatabaseIdentifier id) override { - DatabaseManager::getQueryExecutor(id).replaceThread(this->thread, false); + DatabaseManager::getQueryExecutor(id).replaceThread( + this->thread, this->backupItem); } private: Thread thread; + bool backupItem; }; class RemoveAllThreadsOperation : public DBOperationBase { diff --git a/web/shared-worker/worker/process-operations.js b/web/shared-worker/worker/process-operations.js --- a/web/shared-worker/worker/process-operations.js +++ b/web/shared-worker/worker/process-operations.js @@ -118,7 +118,7 @@ } else if (operation.type === 'replace') { sqliteQueryExecutor.replaceThread( clientDBThreadInfoToWebThread(operation.payload), - false, + operation.isBackedUp, ); } else { throw new Error('Unsupported thread operation'); @@ -281,9 +281,9 @@ const { message, medias } = clientDBMessageInfoToWebMessage( operation.payload, ); - sqliteQueryExecutor.replaceMessage(message, false); + sqliteQueryExecutor.replaceMessage(message, operation.isBackedUp); for (const media of medias) { - sqliteQueryExecutor.replaceMedia(media, false); + sqliteQueryExecutor.replaceMedia(media, operation.isBackedUp); } } else if (operation.type === 'remove_all') { sqliteQueryExecutor.removeAllMessages(); @@ -299,7 +299,7 @@ id, startReached: Number(start_reached), })), - false, + operation.isBackedUp, ); } else if (operation.type === 'remove_all_threads') { sqliteQueryExecutor.removeAllMessageStoreThreads(); @@ -313,7 +313,7 @@ id, localMessageInfo, }, - false, + operation.isBackedUp, ); } else if (operation.type === 'remove_local_message_infos') { const { ids } = operation.payload; @@ -557,7 +557,7 @@ id, threadActivityStoreEntry, }, - false, + operation.isBackedUp, ); } else { throw new Error('Unsupported thread activity operation'); @@ -589,7 +589,7 @@ sqliteQueryExecutor.removeEntries(ids); } else if (operation.type === 'replace_entry') { const { id, entry } = operation.payload; - sqliteQueryExecutor.replaceEntry({ id, entry }, false); + sqliteQueryExecutor.replaceEntry({ id, entry }, operation.isBackedUp); } else { throw new Error('Unsupported entry store operation'); }