diff --git a/lib/ops/report-store-ops.js b/lib/ops/report-store-ops.js --- a/lib/ops/report-store-ops.js +++ b/lib/ops/report-store-ops.js @@ -23,7 +23,7 @@ export type ClientDBReplaceQueuedReportOperation = { +type: 'replace_report', - +payload: { +id: string, +report: string }, + +payload: ClientDBReport, }; export type ClientDBReportStoreOperation = @@ -31,6 +31,8 @@ | RemoveQueuedReportsOperation | RemoveAllQueuedReportsOperation; +export type ClientDBReport = { +id: string, +report: string }; + function processReportStoreOperations( queuedReports: $ReadOnlyArray, reportStoreOps: $ReadOnlyArray, diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js --- a/lib/types/store-ops-types.js +++ b/lib/types/store-ops-types.js @@ -16,7 +16,10 @@ ClientDBThreadStoreOperation, ThreadStoreOperation, } from './thread-types.js'; -import type { ReportStoreOperation } from '../ops/report-store-ops.js'; +import type { + ReportStoreOperation, + ClientDBReport, +} from '../ops/report-store-ops.js'; export type StoreOperations = { +draftStoreOperations: $ReadOnlyArray, @@ -36,4 +39,5 @@ +drafts: $ReadOnlyArray, +threads: $ReadOnlyArray, +messageStoreThreads: $ReadOnlyArray, + +reports: $ReadOnlyArray, }; diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -290,6 +290,22 @@ return jsiThreads; } +jsi::Array parseDBReportStore( + jsi::Runtime &rt, + std::shared_ptr> reportStoreVectorPtr) { + size_t numReports = reportStoreVectorPtr->size(); + jsi::Array jsiReports = jsi::Array(rt, numReports); + size_t writeIdx = 0; + + for (const Report &report : *reportStoreVectorPtr) { + jsi::Object jsiReport = jsi::Object(rt); + jsiReport.setProperty(rt, "id", report.id); + jsiReport.setProperty(rt, "report", report.report); + jsiReports.setValueAtIndex(rt, writeIdx++, jsiReport); + } + return jsiReports; +} + jsi::Value CommCoreModule::getClientDBStore(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { @@ -299,6 +315,7 @@ std::vector threadsVector; std::vector>> messagesVector; std::vector messageStoreThreadsVector; + std::vector reportStoreVector; try { draftsVector = DatabaseManager::getQueryExecutor().getAllDrafts(); messagesVector = @@ -306,6 +323,8 @@ threadsVector = DatabaseManager::getQueryExecutor().getAllThreads(); messageStoreThreadsVector = DatabaseManager::getQueryExecutor().getAllMessageStoreThreads(); + reportStoreVector = + DatabaseManager::getQueryExecutor().getAllReports(); } catch (std::system_error &e) { error = e.what(); } @@ -319,11 +338,14 @@ auto messageStoreThreadsVectorPtr = std::make_shared>( std::move(messageStoreThreadsVector)); + auto reportStoreVectorPtr = std::make_shared>( + std::move(reportStoreVector)); this->jsInvoker_->invokeAsync([&innerRt, draftsVectorPtr, messagesVectorPtr, threadsVectorPtr, messageStoreThreadsVectorPtr, + reportStoreVectorPtr, error, promise]() { if (error.size()) { @@ -336,6 +358,8 @@ jsi::Array jsiThreads = parseDBThreads(innerRt, threadsVectorPtr); jsi::Array jsiMessageStoreThreads = parseDBMessageStoreThreads( innerRt, messageStoreThreadsVectorPtr); + jsi::Array jsiReportStore = + parseDBReportStore(innerRt, reportStoreVectorPtr); auto jsiClientDBStore = jsi::Object(innerRt); jsiClientDBStore.setProperty(innerRt, "messages", jsiMessages); @@ -343,6 +367,7 @@ jsiClientDBStore.setProperty(innerRt, "drafts", jsiDrafts); jsiClientDBStore.setProperty( innerRt, "messageStoreThreads", jsiMessageStoreThreads); + jsiClientDBStore.setProperty(innerRt, "reports", jsiReportStore); promise->resolve(std::move(jsiClientDBStore)); }); diff --git a/web/database/worker/db-worker.js b/web/database/worker/db-worker.js --- a/web/database/worker/db-worker.js +++ b/web/database/worker/db-worker.js @@ -131,6 +131,7 @@ messages: [], threads: [], messageStoreThreads: [], + reports: [], }; }