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 @@ -199,22 +199,7 @@ getDMOperationsByType(const std::string &operationType) const = 0; virtual ~DatabaseQueryExecutor() = default; -#ifdef EMSCRIPTEN - virtual std::vector getAllThreadsWeb() const = 0; - virtual void replaceThreadWeb(const WebThread &thread) const = 0; - virtual std::vector getInitialMessagesWeb() const = 0; - virtual std::vector - fetchMessagesWeb(std::string threadID, int limit, int offset) const = 0; - virtual void replaceMessageWeb(const WebMessage &message) const = 0; - virtual NullableString getOlmPersistAccountDataWeb(int accountID) const = 0; - virtual std::vector - getRelatedMessagesWeb(const std::string &messageID) const = 0; - virtual std::vector searchMessagesWeb( - std::string query, - std::string threadID, - std::optional timestampCursor, - std::optional messageIDCursor) const = 0; -#else +#ifndef EMSCRIPTEN virtual void createMainCompaction(std::string backupID) const = 0; virtual void captureBackupLogs() const = 0; virtual void triggerBackupFileUpload() 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 @@ -42,8 +42,6 @@ void cleanupDatabaseExceptAllowlist(sqlite3 *db) const; #else static SQLiteConnectionManager connectionManager; - std::vector - transformToWebMessages(const std::vector &messages) const; #endif std::optional getSyncedDatabaseVersion(sqlite3 *db) const; @@ -217,22 +215,7 @@ std::vector getDMOperationsByType(const std::string &operationType) const override; -#ifdef EMSCRIPTEN - std::vector getAllThreadsWeb() const override; - void replaceThreadWeb(const WebThread &thread) const override; - std::vector getInitialMessagesWeb() const override; - std::vector - fetchMessagesWeb(std::string threadID, int limit, int offset) const override; - void replaceMessageWeb(const WebMessage &message) const override; - NullableString getOlmPersistAccountDataWeb(int accountID) const override; - std::vector - getRelatedMessagesWeb(const std::string &messageID) const override; - std::vector searchMessagesWeb( - std::string query, - std::string threadID, - std::optional timestampCursor, - std::optional messageIDCursor) const override; -#else +#ifndef EMSCRIPTEN static void clearSensitiveData(); static void initialize(std::string &databasePath); void createMainCompaction(std::string backupID) 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 @@ -2813,76 +2813,7 @@ return tableNames; } -#ifdef EMSCRIPTEN -std::vector SQLiteQueryExecutor::getAllThreadsWeb() const { - auto threads = this->getAllThreads(); - std::vector webThreads; - webThreads.reserve(threads.size()); - for (const auto &thread : threads) { - webThreads.emplace_back(thread); - } - return webThreads; -}; - -void SQLiteQueryExecutor::replaceThreadWeb(const WebThread &thread) const { - this->replaceThread(thread.toThread()); -}; - -std::vector SQLiteQueryExecutor::transformToWebMessages( - const std::vector &messages) const { - std::vector messageWithMedias; - for (auto &messageEntity : messages) { - messageWithMedias.push_back( - {Message(messageEntity.message), messageEntity.medias}); - } - - return messageWithMedias; -} - -std::vector -SQLiteQueryExecutor::getInitialMessagesWeb() const { - auto messages = this->getInitialMessages(); - return this->transformToWebMessages(messages); -} - -std::vector SQLiteQueryExecutor::fetchMessagesWeb( - std::string threadID, - int limit, - int offset) const { - auto messages = this->fetchMessages(threadID, limit, offset); - return this->transformToWebMessages(messages); -} - -void SQLiteQueryExecutor::replaceMessageWeb(const WebMessage &message) const { - this->replaceMessage(message.toMessage()); -}; - -NullableString -SQLiteQueryExecutor::getOlmPersistAccountDataWeb(int accountID) const { - std::optional accountData = - this->getOlmPersistAccountData(accountID); - if (!accountData.has_value()) { - return NullableString(); - } - return std::make_unique(accountData.value()); -} - -std::vector -SQLiteQueryExecutor::getRelatedMessagesWeb(const std::string &messageID) const { - auto relatedMessages = this->getRelatedMessages(messageID); - return this->transformToWebMessages(relatedMessages); -} - -std::vector SQLiteQueryExecutor::searchMessagesWeb( - std::string query, - std::string threadID, - std::optional timestampCursor, - std::optional messageIDCursor) const { - auto messages = - this->searchMessages(query, threadID, timestampCursor, messageIDCursor); - return this->transformToWebMessages(messages); -} -#else +#ifndef EMSCRIPTEN void SQLiteQueryExecutor::clearSensitiveData() { SQLiteQueryExecutor::closeConnection(); if (SQLiteUtils::fileExists(SQLiteQueryExecutor::sqliteFilePath) && diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/Message.h b/native/cpp/CommonCpp/DatabaseManagers/entities/Message.h --- a/native/cpp/CommonCpp/DatabaseManagers/entities/Message.h +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/Message.h @@ -1,7 +1,6 @@ #pragma once #include "Media.h" -#include "Nullable.h" #include #include #include @@ -44,48 +43,6 @@ } }; -struct WebMessage { - std::string id; - NullableString local_id; - std::string thread; - std::string user; - int type; - NullableInt future_type; - NullableString content; - std::string time; - - WebMessage() = default; - - WebMessage(const Message &message) { - id = message.id; - local_id = NullableString(message.local_id); - thread = message.thread; - user = message.user; - type = message.type; - future_type = NullableInt(message.future_type); - content = NullableString(message.content); - time = std::to_string(message.time); - } - - Message toMessage() const { - Message message; - message.id = id; - message.local_id = local_id.resetValue(); - message.thread = thread; - message.user = user; - message.type = type; - message.future_type = future_type.resetValue(); - message.content = content.resetValue(); - message.time = std::stoll(time); - return message; - } -}; - -struct MessageWithMedias { - Message message; - std::vector medias; -}; - struct MessageEntity { Message message; std::vector medias; diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/Nullable.h b/native/cpp/CommonCpp/DatabaseManagers/entities/Nullable.h deleted file mode 100644 --- a/native/cpp/CommonCpp/DatabaseManagers/entities/Nullable.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include -#include - -namespace comm { - -template struct Nullable { - T value; - bool isNull; - - Nullable() : value(T()), isNull(true) { - } - - Nullable(const std::unique_ptr &ptr) - : value((ptr) ? *ptr : T()), isNull(!ptr) { - } - - Nullable(const std::optional &opt) - : value(opt.value_or(T())), isNull(!opt.has_value()) { - } - - Nullable &operator=(const std::unique_ptr &ptr) { - if (ptr) { - value = *ptr; - isNull = false; - } else { - value = T(); - isNull = true; - } - return *this; - } - - Nullable &operator=(const std::optional &opt) { - if (opt.has_value()) { - value = *opt; - isNull = false; - } else { - value = T(); - isNull = true; - } - return *this; - } - - std::optional resetValue() const { - return isNull ? std::nullopt : std::optional(value); - } -}; - -using NullableString = Nullable; -using NullableInt = Nullable; - -} // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/entities/Thread.h b/native/cpp/CommonCpp/DatabaseManagers/entities/Thread.h --- a/native/cpp/CommonCpp/DatabaseManagers/entities/Thread.h +++ b/native/cpp/CommonCpp/DatabaseManagers/entities/Thread.h @@ -5,7 +5,6 @@ #include #include -#include "Nullable.h" #include "SQLiteDataConverters.h" namespace comm { @@ -72,68 +71,4 @@ } }; -struct WebThread { - std::string id; - int type; - NullableString name; - NullableString description; - std::string color; - std::string creation_time; - NullableString parent_thread_id; - NullableString containing_thread_id; - NullableString community; - std::string members; - std::string roles; - std::string current_user; - NullableString source_message_id; - int replies_count; - NullableString avatar; - int pinned_count; - NullableString timestamps; - - WebThread() = default; - - WebThread(const Thread &thread) { - id = thread.id; - type = thread.type; - name = NullableString(thread.name); - description = NullableString(thread.description); - color = thread.color; - creation_time = std::to_string(thread.creation_time); - parent_thread_id = NullableString(thread.parent_thread_id); - containing_thread_id = NullableString(thread.containing_thread_id); - community = NullableString(thread.community); - members = thread.members; - roles = thread.roles; - current_user = thread.current_user; - source_message_id = NullableString(thread.source_message_id); - replies_count = thread.replies_count; - avatar = NullableString(thread.avatar); - pinned_count = thread.pinned_count; - timestamps = NullableString(thread.timestamps); - } - - Thread toThread() const { - Thread thread; - thread.id = id; - thread.type = type; - thread.name = name.resetValue(); - thread.description = description.resetValue(); - thread.color = color; - thread.creation_time = std::stoll(creation_time); - thread.parent_thread_id = parent_thread_id.resetValue(); - thread.containing_thread_id = containing_thread_id.resetValue(); - thread.community = community.resetValue(); - thread.members = members; - thread.roles = roles; - thread.current_user = current_user; - thread.source_message_id = source_message_id.resetValue(); - thread.replies_count = replies_count; - thread.avatar = avatar.resetValue(); - thread.pinned_count = pinned_count; - thread.timestamps = timestamps.resetValue(); - return thread; - } -}; - } // namespace comm diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -1,7 +1,6 @@ #include "SQLiteQueryExecutor.cpp" #include "SQLiteUtils.cpp" #include "entities/InboundP2PMessage.h" -#include "entities/Nullable.h" #include "entities/OutboundP2PMessage.h" #include @@ -27,13 +26,6 @@ EMSCRIPTEN_BINDINGS(SQLiteQueryExecutor) { function("getExceptionMessage", &getExceptionMessage); - value_object("NullableString") - .field("value", &NullableString::value) - .field("isNull", &NullableString::isNull); - value_object("NullableInt") - .field("value", &NullableInt::value) - .field("isNull", &NullableInt::isNull); - value_object("Draft") .field("key", &Draft::key) .field("text", &Draft::text); 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$@ = { - +value: T, - +isNull: boolean, -}; - -export type NullableString = Nullable; - -export type NullableInt = Nullable; - export type WebClientDBThreadInfo = { +id: string, +type: number, @@ -34,32 +25,6 @@ +timestamps: ?string, }; -function createNullableString(value: ?string): NullableString { - if (value === null || value === undefined) { - return { - value: '', - isNull: true, - }; - } - return { - value, - isNull: false, - }; -} - -function createNullableInt(value: ?string): NullableInt { - if (value === null || value === undefined) { - return { - value: 0, - isNull: true, - }; - } - return { - value: Number(value), - isNull: false, - }; -} - function clientDBThreadInfoToWebThread( info: ClientDBThreadInfo, ): WebClientDBThreadInfo { @@ -178,6 +143,4 @@ webThreadToClientDBThreadInfo, clientDBMessageInfoToWebMessage, webMessageToClientDBMessageInfo, - createNullableString, - createNullableInt, };