diff --git a/web/cpp/SQLiteQueryExecutorBindings.cpp b/web/cpp/SQLiteQueryExecutorBindings.cpp index 1ba8cc2f4..fc8a1f75e 100644 --- a/web/cpp/SQLiteQueryExecutorBindings.cpp +++ b/web/cpp/SQLiteQueryExecutorBindings.cpp @@ -1,409 +1,410 @@ #include "SQLiteQueryExecutor.cpp" #include "entities/InboundP2PMessage.h" #include "entities/Nullable.h" #include "entities/OutboundP2PMessage.h" #include #include #include namespace comm { using namespace emscripten; std::string getExceptionMessage(int exceptionPtr) { if (exceptionPtr == 0) { return std::string("Exception pointer value was null"); } std::exception *e = reinterpret_cast(exceptionPtr); if (e) { return std::string(e->what()); } return std::string("Pointer to exception was invalid"); } 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); value_object("Report") .field("id", &Report::id) .field("report", &Report::report); value_object("PersistItem") .field("key", &PersistItem::key) .field("item", &PersistItem::item); value_object("UserInfo") .field("id", &UserInfo::id) .field("userInfo", &UserInfo::user_info); value_object("KeyserverInfo") .field("id", &KeyserverInfo::id) .field("keyserverInfo", &KeyserverInfo::keyserver_info) .field("syncedKeyserverInfo", &KeyserverInfo::synced_keyserver_info); value_object("MessageStoreThreads") .field("id", &MessageStoreThread::id) .field("startReached", &MessageStoreThread::start_reached); value_object("CommunityInfo") .field("id", &CommunityInfo::id) .field("communityInfo", &CommunityInfo::community_info); value_object("IntegrityThreadHash") .field("id", &IntegrityThreadHash::id) .field("threadHash", &IntegrityThreadHash::thread_hash); value_object("SyncedMetadataEntry") .field("name", &SyncedMetadataEntry::name) .field("data", &SyncedMetadataEntry::data); value_object("AuxUserInfo") .field("id", &AuxUserInfo::id) .field("auxUserInfo", &AuxUserInfo::aux_user_info); value_object("ThreadActivityEntry") .field("id", &ThreadActivityEntry::id) .field( "threadActivityStoreEntry", &ThreadActivityEntry::thread_activity_store_entry); value_object("EntryInfo") .field("id", &EntryInfo::id) .field("entry", &EntryInfo::entry); value_object("LocalMessageInfo") .field("id", &LocalMessageInfo::id) .field("localMessageInfo", &LocalMessageInfo::local_message_info); value_object("WebThread") .field("id", &WebThread::id) .field("type", &WebThread::type) .field("name", &WebThread::name) .field("description", &WebThread::description) .field("color", &WebThread::color) .field("creationTime", &WebThread::creation_time) .field("parentThreadID", &WebThread::parent_thread_id) .field("containingThreadID", &WebThread::containing_thread_id) .field("community", &WebThread::community) .field("members", &WebThread::members) .field("roles", &WebThread::roles) .field("currentUser", &WebThread::current_user) .field("sourceMessageID", &WebThread::source_message_id) .field("repliesCount", &WebThread::replies_count) .field("avatar", &WebThread::avatar) .field("pinnedCount", &WebThread::pinned_count); value_object("WebMessage") .field("id", &WebMessage::id) .field("localID", &WebMessage::local_id) .field("thread", &WebMessage::thread) .field("user", &WebMessage::user) .field("type", &WebMessage::type) .field("futureType", &WebMessage::future_type) .field("content", &WebMessage::content) .field("time", &WebMessage::time); value_object("Media") .field("id", &Media::id) .field("container", &Media::container) .field("thread", &Media::thread) .field("uri", &Media::uri) .field("type", &Media::type) .field("extras", &Media::extras); value_object("MessageWithMedias") .field("message", &MessageWithMedias::message) .field("medias", &MessageWithMedias::medias); value_object("OlmPersistSession") .field("targetDeviceID", &OlmPersistSession::target_device_id) .field("sessionData", &OlmPersistSession::session_data) .field("version", &OlmPersistSession::version); value_object("OutboundP2PMessage") .field("messageID", &OutboundP2PMessage::message_id) .field("deviceID", &OutboundP2PMessage::device_id) .field("userID", &OutboundP2PMessage::user_id) .field("timestamp", &OutboundP2PMessage::timestamp) .field("plaintext", &OutboundP2PMessage::plaintext) .field("ciphertext", &OutboundP2PMessage::ciphertext) .field("status", &OutboundP2PMessage::status) .field("supportsAutoRetry", &OutboundP2PMessage::supports_auto_retry); value_object("InboundP2PMessage") .field("messageID", &InboundP2PMessage::message_id) .field("senderDeviceID", &InboundP2PMessage::sender_device_id) .field("plaintext", &InboundP2PMessage::plaintext) .field("status", &InboundP2PMessage::status); class_("SQLiteQueryExecutor") .constructor() .function("updateDraft", &SQLiteQueryExecutor::updateDraft) .function("moveDraft", &SQLiteQueryExecutor::moveDraft) .function("getAllDrafts", &SQLiteQueryExecutor::getAllDrafts) .function("removeAllDrafts", &SQLiteQueryExecutor::removeAllDrafts) .function("removeDrafts", &SQLiteQueryExecutor::removeDrafts) .function("getAllMessagesWeb", &SQLiteQueryExecutor::getAllMessagesWeb) .function("removeAllMessages", &SQLiteQueryExecutor::removeAllMessages) .function("removeMessages", &SQLiteQueryExecutor::removeMessages) .function( "removeMessagesForThreads", &SQLiteQueryExecutor::removeMessagesForThreads) .function("replaceMessageWeb", &SQLiteQueryExecutor::replaceMessageWeb) .function("rekeyMessage", &SQLiteQueryExecutor::rekeyMessage) .function("removeAllMedia", &SQLiteQueryExecutor::removeAllMedia) .function( "removeMediaForThreads", &SQLiteQueryExecutor::removeMediaForThreads) .function( "removeMediaForMessage", &SQLiteQueryExecutor::removeMediaForMessage) .function( "removeMediaForMessages", &SQLiteQueryExecutor::removeMediaForMessages) .function("replaceMedia", &SQLiteQueryExecutor::replaceMedia) .function( "rekeyMediaContainers", &SQLiteQueryExecutor::rekeyMediaContainers) .function( "replaceMessageStoreThreads", &SQLiteQueryExecutor::replaceMessageStoreThreads) .function( "removeMessageStoreThreads", &SQLiteQueryExecutor::removeMessageStoreThreads) .function( "getAllMessageStoreThreads", &SQLiteQueryExecutor::getAllMessageStoreThreads) .function( "removeAllMessageStoreThreads", &SQLiteQueryExecutor::removeAllMessageStoreThreads) .function("setMetadata", &SQLiteQueryExecutor::setMetadata) .function("clearMetadata", &SQLiteQueryExecutor::clearMetadata) .function("getMetadata", &SQLiteQueryExecutor::getMetadata) .function("replaceReport", &SQLiteQueryExecutor::replaceReport) .function("removeReports", &SQLiteQueryExecutor::removeReports) .function("removeAllReports", &SQLiteQueryExecutor::removeAllReports) .function("getAllReports", &SQLiteQueryExecutor::getAllReports) .function( "setPersistStorageItem", &SQLiteQueryExecutor::setPersistStorageItem) .function( "removePersistStorageItem", &SQLiteQueryExecutor::removePersistStorageItem) .function( "getPersistStorageItem", &SQLiteQueryExecutor::getPersistStorageItem) .function("replaceUser", &SQLiteQueryExecutor::replaceUser) .function("removeUsers", &SQLiteQueryExecutor::removeUsers) .function("removeAllUsers", &SQLiteQueryExecutor::removeAllUsers) .function("getAllUsers", &SQLiteQueryExecutor::getAllUsers) .function("replaceThreadWeb", &SQLiteQueryExecutor::replaceThreadWeb) .function("getAllThreadsWeb", &SQLiteQueryExecutor::getAllThreadsWeb) .function("removeAllThreads", &SQLiteQueryExecutor::removeAllThreads) .function("removeThreads", &SQLiteQueryExecutor::removeThreads) .function("replaceKeyserver", &SQLiteQueryExecutor::replaceKeyserver) .function("removeKeyservers", &SQLiteQueryExecutor::removeKeyservers) .function( "removeAllKeyservers", &SQLiteQueryExecutor::removeAllKeyservers) .function("getAllKeyservers", &SQLiteQueryExecutor::getAllKeyservers) .function("replaceCommunity", &SQLiteQueryExecutor::replaceCommunity) .function("removeCommunities", &SQLiteQueryExecutor::removeCommunities) .function( "removeAllCommunities", &SQLiteQueryExecutor::removeAllCommunities) .function("getAllCommunities", &SQLiteQueryExecutor::getAllCommunities) .function( "replaceIntegrityThreadHashes", &SQLiteQueryExecutor::replaceIntegrityThreadHashes) .function( "removeIntegrityThreadHashes", &SQLiteQueryExecutor::removeIntegrityThreadHashes) .function( "removeAllIntegrityThreadHashes", &SQLiteQueryExecutor::removeAllIntegrityThreadHashes) .function( "getAllIntegrityThreadHashes", &SQLiteQueryExecutor::getAllIntegrityThreadHashes) .function( "replaceSyncedMetadataEntry", &SQLiteQueryExecutor::replaceSyncedMetadataEntry) .function( "removeSyncedMetadata", &SQLiteQueryExecutor::removeSyncedMetadata) .function( "removeAllSyncedMetadata", &SQLiteQueryExecutor::removeAllSyncedMetadata) .function( "getAllSyncedMetadata", &SQLiteQueryExecutor::getAllSyncedMetadata) .function("replaceAuxUserInfo", &SQLiteQueryExecutor::replaceAuxUserInfo) .function("removeAuxUserInfos", &SQLiteQueryExecutor::removeAuxUserInfos) .function( "removeAllAuxUserInfos", &SQLiteQueryExecutor::removeAllAuxUserInfos) .function("getAllAuxUserInfos", &SQLiteQueryExecutor::getAllAuxUserInfos) .function( "replaceThreadActivityEntry", &SQLiteQueryExecutor::replaceThreadActivityEntry) .function( "removeThreadActivityEntries", &SQLiteQueryExecutor::removeThreadActivityEntries) .function( "removeAllThreadActivityEntries", &SQLiteQueryExecutor::removeAllThreadActivityEntries) .function( "getAllThreadActivityEntries", &SQLiteQueryExecutor::getAllThreadActivityEntries) .function("replaceEntry", &SQLiteQueryExecutor::replaceEntry) .function("removeEntries", &SQLiteQueryExecutor::removeEntries) .function("removeAllEntries", &SQLiteQueryExecutor::removeAllEntries) .function("getAllEntries", &SQLiteQueryExecutor::getAllEntries) .function( "replaceMessageStoreLocalMessageInfo", &SQLiteQueryExecutor::replaceMessageStoreLocalMessageInfo) .function( "removeMessageStoreLocalMessageInfos", &SQLiteQueryExecutor::removeMessageStoreLocalMessageInfos) .function( "removeAllMessageStoreLocalMessageInfos", &SQLiteQueryExecutor::removeAllMessageStoreLocalMessageInfos) .function( "getAllMessageStoreLocalMessageInfos", &SQLiteQueryExecutor::getAllMessageStoreLocalMessageInfos) .function("beginTransaction", &SQLiteQueryExecutor::beginTransaction) .function("commitTransaction", &SQLiteQueryExecutor::commitTransaction) .function( "getContentAccountID", &SQLiteQueryExecutor::getContentAccountID) .function("getNotifsAccountID", &SQLiteQueryExecutor::getNotifsAccountID) .function( "getOlmPersistSessionsData", &SQLiteQueryExecutor::getOlmPersistSessionsData) .function( "getOlmPersistAccountDataWeb", &SQLiteQueryExecutor::getOlmPersistAccountDataWeb) .function( "storeOlmPersistSession", &SQLiteQueryExecutor::storeOlmPersistSession) .function( "storeOlmPersistAccount", &SQLiteQueryExecutor::storeOlmPersistAccount) .function( "rollbackTransaction", &SQLiteQueryExecutor::rollbackTransaction) .function( "restoreFromMainCompaction", &SQLiteQueryExecutor::restoreFromMainCompaction) .function( "restoreFromBackupLog", &SQLiteQueryExecutor::restoreFromBackupLog) .function( "addOutboundP2PMessages", &SQLiteQueryExecutor::addOutboundP2PMessages) .function( "removeOutboundP2PMessagesOlderThan", &SQLiteQueryExecutor::removeOutboundP2PMessagesOlderThan) .function( "removeAllOutboundP2PMessages", &SQLiteQueryExecutor::removeAllOutboundP2PMessages) .function( "getOutboundP2PMessagesByID", &SQLiteQueryExecutor::getOutboundP2PMessagesByID) .function( "getAllOutboundP2PMessages", &SQLiteQueryExecutor::getAllOutboundP2PMessages) .function( "setCiphertextForOutboundP2PMessage", &SQLiteQueryExecutor::setCiphertextForOutboundP2PMessage) .function( "markOutboundP2PMessageAsSent", &SQLiteQueryExecutor::markOutboundP2PMessageAsSent) .function( "addInboundP2PMessage", &SQLiteQueryExecutor::addInboundP2PMessage) .function( "getAllInboundP2PMessage", &SQLiteQueryExecutor::getAllInboundP2PMessage) .function( "removeInboundP2PMessages", &SQLiteQueryExecutor::removeInboundP2PMessages) .function( "getRelatedMessagesWeb", &SQLiteQueryExecutor::getRelatedMessagesWeb) .function( "updateMessageSearchIndex", - &SQLiteQueryExecutor::updateMessageSearchIndex); + &SQLiteQueryExecutor::updateMessageSearchIndex) + .function("searchMessages", &SQLiteQueryExecutor::searchMessagesWeb); } } // namespace comm namespace emscripten { namespace internal { template struct BindingType> { using ValBinding = BindingType; using WireType = ValBinding::WireType; static WireType toWireType(const std::vector &vec) { std::vector valVec(vec.begin(), vec.end()); return BindingType::toWireType(val::array(valVec)); } static std::vector fromWireType(WireType value) { return vecFromJSArray(ValBinding::fromWireType(value)); } }; template struct TypeID< T, typename std::enable_if_t::type, std::vector< typename Canonicalized::type::value_type, typename Canonicalized::type::allocator_type>>::value>> { static constexpr TYPEID get() { return TypeID::get(); } }; template struct TypeID> { static constexpr TYPEID get() { return LightTypeID::get(); } }; template struct TypeID> { static constexpr TYPEID get() { return LightTypeID::get(); } }; template struct TypeID &> { static constexpr TYPEID get() { return LightTypeID::get(); } }; template struct TypeID &&> { static constexpr TYPEID get() { return LightTypeID::get(); } }; template struct TypeID &> { static constexpr TYPEID get() { return LightTypeID::get(); } }; template struct BindingType> { using ValBinding = BindingType; using WireType = ValBinding::WireType; static WireType toWireType(std::optional const &opt) { if (!opt.has_value()) { return ValBinding::toWireType(val::null()); } return ValBinding::toWireType(val(opt.value())); } static std::optional fromWireType(WireType value) { val convertedVal = ValBinding::fromWireType(value); if (convertedVal.isNull() || convertedVal.isUndefined()) { return std::nullopt; } return std::make_optional(convertedVal.as()); } }; } // namespace internal } // namespace emscripten diff --git a/web/shared-worker/_generated/comm_query_executor.wasm b/web/shared-worker/_generated/comm_query_executor.wasm index c161f0a27..baac9dd93 100755 Binary files a/web/shared-worker/_generated/comm_query_executor.wasm and b/web/shared-worker/_generated/comm_query_executor.wasm differ diff --git a/web/shared-worker/types/sqlite-query-executor.js b/web/shared-worker/types/sqlite-query-executor.js index a776f871a..019816b37 100644 --- a/web/shared-worker/types/sqlite-query-executor.js +++ b/web/shared-worker/types/sqlite-query-executor.js @@ -1,211 +1,217 @@ // @flow import type { ClientDBAuxUserInfo } from 'lib/ops/aux-user-store-ops.js'; import type { ClientDBCommunityInfo } from 'lib/ops/community-store-ops.js'; import type { ClientDBEntryInfo } from 'lib/ops/entries-store-ops.js'; import type { ClientDBIntegrityThreadHash } from 'lib/ops/integrity-store-ops.js'; import type { ClientDBKeyserverInfo } from 'lib/ops/keyserver-store-ops.js'; import type { ClientDBReport } from 'lib/ops/report-store-ops.js'; import type { ClientDBSyncedMetadataEntry } from 'lib/ops/synced-metadata-store-ops.js'; import type { ClientDBThreadActivityEntry } from 'lib/ops/thread-activity-store-ops.js'; import type { ClientDBUserInfo } from 'lib/ops/user-store-ops.js'; import type { ClientDBDraftInfo } from 'lib/types/draft-types.js'; import type { ClientDBLocalMessageInfo } from 'lib/types/message-types.js'; import type { OutboundP2PMessage, InboundP2PMessage, } from 'lib/types/sqlite-types.js'; import { type NullableInt, type NullableString, type WebClientDBThreadInfo, } from './entities.js'; export type WebMessage = { +id: string, +localID: NullableString, +thread: string, +user: string, +type: number, +futureType: NullableInt, +content: NullableString, +time: string, }; export type Media = { +id: string, +container: string, +thread: string, +uri: string, +type: 'photo' | 'video', +extras: string, }; export type OlmPersistSession = { +targetDeviceID: string, +sessionData: string, +version: number, }; type MessageEntity = { +message: WebMessage, +medias: $ReadOnlyArray, }; declare export class SQLiteQueryExecutor { constructor(sqliteFilePath: string): void; updateDraft(key: string, text: string): void; moveDraft(oldKey: string, newKey: string): boolean; getAllDrafts(): ClientDBDraftInfo[]; removeAllDrafts(): void; removeDrafts(ids: $ReadOnlyArray): void; getAllMessagesWeb(): $ReadOnlyArray; removeAllMessages(): void; removeMessages(ids: $ReadOnlyArray): void; removeMessagesForThreads(threadIDs: $ReadOnlyArray): void; replaceMessageWeb(message: WebMessage): void; rekeyMessage(from: string, to: string): void; removeAllMedia(): void; removeMediaForThreads(threadIDs: $ReadOnlyArray): void; removeMediaForMessages(msgIDs: $ReadOnlyArray): void; removeMediaForMessage(msgID: string): void; replaceMedia(media: Media): void; rekeyMediaContainers(from: string, to: string): void; replaceMessageStoreThreads( threads: $ReadOnlyArray<{ +id: string, +startReached: number }>, ): void; removeMessageStoreThreads($ReadOnlyArray): void; getAllMessageStoreThreads(): $ReadOnlyArray<{ +id: string, +startReached: number, }>; removeAllMessageStoreThreads(): void; setMetadata(entryName: string, data: string): void; clearMetadata(entryName: string): void; getMetadata(entryName: string): string; replaceReport(report: ClientDBReport): void; removeReports(ids: $ReadOnlyArray): void; removeAllReports(): void; getAllReports(): ClientDBReport[]; setPersistStorageItem(key: string, item: string): void; removePersistStorageItem(key: string): void; getPersistStorageItem(key: string): string; replaceUser(userInfo: ClientDBUserInfo): void; removeUsers(ids: $ReadOnlyArray): void; removeAllUsers(): void; getAllUsers(): ClientDBUserInfo[]; replaceThreadWeb(thread: WebClientDBThreadInfo): void; removeThreads(ids: $ReadOnlyArray): void; removeAllThreads(): void; getAllThreadsWeb(): WebClientDBThreadInfo[]; replaceKeyserver(keyserverInfo: ClientDBKeyserverInfo): void; removeKeyservers(ids: $ReadOnlyArray): void; removeAllKeyservers(): void; getAllKeyservers(): ClientDBKeyserverInfo[]; replaceCommunity(communityInfo: ClientDBCommunityInfo): void; removeCommunities(ids: $ReadOnlyArray): void; removeAllCommunities(): void; getAllCommunities(): ClientDBCommunityInfo[]; replaceIntegrityThreadHashes( threadHashes: $ReadOnlyArray, ): void; removeIntegrityThreadHashes(ids: $ReadOnlyArray): void; removeAllIntegrityThreadHashes(): void; getAllIntegrityThreadHashes(): ClientDBIntegrityThreadHash[]; replaceSyncedMetadataEntry( syncedMetadataEntry: ClientDBSyncedMetadataEntry, ): void; removeSyncedMetadata(names: $ReadOnlyArray): void; removeAllSyncedMetadata(): void; getAllSyncedMetadata(): ClientDBSyncedMetadataEntry[]; replaceAuxUserInfo(auxUserInfo: ClientDBAuxUserInfo): void; removeAuxUserInfos(ids: $ReadOnlyArray): void; removeAllAuxUserInfos(): void; getAllAuxUserInfos(): ClientDBAuxUserInfo[]; replaceThreadActivityEntry( threadActivityEntry: ClientDBThreadActivityEntry, ): void; removeThreadActivityEntries(ids: $ReadOnlyArray): void; removeAllThreadActivityEntries(): void; getAllThreadActivityEntries(): ClientDBThreadActivityEntry[]; replaceEntry(entryInfo: ClientDBEntryInfo): void; removeEntries(ids: $ReadOnlyArray): void; removeAllEntries(): void; getAllEntries(): $ReadOnlyArray; replaceMessageStoreLocalMessageInfo( localMessageInfo: ClientDBLocalMessageInfo, ): void; removeMessageStoreLocalMessageInfos(ids: $ReadOnlyArray): void; removeAllMessageStoreLocalMessageInfos(): void; getAllMessageStoreLocalMessageInfos(): ClientDBLocalMessageInfo[]; beginTransaction(): void; commitTransaction(): void; rollbackTransaction(): void; getContentAccountID(): number; getNotifsAccountID(): number; getOlmPersistAccountDataWeb(accountID: number): NullableString; getOlmPersistSessionsData(): $ReadOnlyArray; storeOlmPersistAccount(accountID: number, accountData: string): void; storeOlmPersistSession(session: OlmPersistSession): void; restoreFromMainCompaction( mainCompactionPath: string, mainCompactionEncryptionKey: string, maxVersion: string, ): void; restoreFromBackupLog(backupLog: Uint8Array): void; addOutboundP2PMessages(messages: $ReadOnlyArray): void; removeOutboundP2PMessagesOlderThan( lastConfirmedMessageID: string, deviceID: string, ): void; removeAllOutboundP2PMessages(deviceID: string): void; getOutboundP2PMessagesByID( ids: $ReadOnlyArray, ): $ReadOnlyArray; getAllOutboundP2PMessages(): $ReadOnlyArray; setCiphertextForOutboundP2PMessage( messageID: string, deviceID: string, ciphertext: string, ): void; markOutboundP2PMessageAsSent(messageID: string, deviceID: string): void; addInboundP2PMessage(message: InboundP2PMessage): void; getAllInboundP2PMessage(): $ReadOnlyArray; removeInboundP2PMessages(ids: $ReadOnlyArray): void; getRelatedMessagesWeb(id: string): $ReadOnlyArray; updateMessageSearchIndex( originalMessageID: string, messageID: string, content: string, ): void; + searchMessages( + query: string, + threadID: string, + timestampCursor: ?string, + messageIDCursor: ?string, + ): $ReadOnlyArray; // method is provided to manually signal that a C++ object // is no longer needed and can be deleted delete(): void; } export type SQLiteQueryExecutorType = typeof SQLiteQueryExecutor;