Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3500347
D5774.id19097.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D5774.id19097.diff
View Options
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
@@ -31,6 +31,7 @@
jsi::Runtime &rt,
const jsi::String &oldKey,
const jsi::String &newKey) override;
+ jsi::Value getClientDBStore(jsi::Runtime &rt) override;
jsi::Value getAllDrafts(jsi::Runtime &rt) override;
jsi::Value removeAllDrafts(jsi::Runtime &rt) override;
jsi::Value getAllMessages(jsi::Runtime &rt) override;
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
@@ -255,6 +255,57 @@
return jsiThreads;
}
+jsi::Value CommCoreModule::getClientDBStore(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ std::vector<Draft> draftsVector;
+ std::vector<Thread> threadsVector;
+ std::vector<std::pair<Message, std::vector<Media>>> messagesVector;
+ try {
+ draftsVector = DatabaseManager::getQueryExecutor().getAllDrafts();
+ messagesVector =
+ DatabaseManager::getQueryExecutor().getAllMessages();
+ threadsVector = DatabaseManager::getQueryExecutor().getAllThreads();
+ } catch (std::system_error &e) {
+ error = e.what();
+ }
+ auto draftsVectorPtr =
+ std::make_shared<std::vector<Draft>>(std::move(draftsVector));
+ auto messagesVectorPtr = std::make_shared<
+ std::vector<std::pair<Message, std::vector<Media>>>>(
+ std::move(messagesVector));
+ auto threadsVectorPtr =
+ std::make_shared<std::vector<Thread>>(std::move(threadsVector));
+ this->jsInvoker_->invokeAsync([&innerRt,
+ draftsVectorPtr,
+ messagesVectorPtr,
+ threadsVectorPtr,
+ error,
+ promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+ jsi::Array jsiDrafts = parseDBDrafts(innerRt, draftsVectorPtr);
+ jsi::Array jsiMessages =
+ parseDBMessages(innerRt, messagesVectorPtr);
+ jsi::Array jsiThreads = parseDBThreads(innerRt, threadsVectorPtr);
+
+ auto jsiClientDBStore = jsi::Object(innerRt);
+ jsiClientDBStore.setProperty(innerRt, "messages", jsiMessages);
+ jsiClientDBStore.setProperty(innerRt, "threads", jsiThreads);
+ jsiClientDBStore.setProperty(innerRt, "drafts", jsiDrafts);
+
+ promise->resolve(std::move(jsiClientDBStore));
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
+
jsi::Value CommCoreModule::getAllDrafts(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
diff --git a/native/cpp/CommonCpp/_generated/NativeModules.h b/native/cpp/CommonCpp/_generated/NativeModules.h
--- a/native/cpp/CommonCpp/_generated/NativeModules.h
+++ b/native/cpp/CommonCpp/_generated/NativeModules.h
@@ -21,6 +21,7 @@
virtual jsi::Value getDraft(jsi::Runtime &rt, const jsi::String &key) = 0;
virtual jsi::Value updateDraft(jsi::Runtime &rt, const jsi::String &key, const jsi::String &text) = 0;
virtual jsi::Value moveDraft(jsi::Runtime &rt, const jsi::String &oldKey, const jsi::String &newKey) = 0;
+virtual jsi::Value getClientDBStore(jsi::Runtime &rt) = 0;
virtual jsi::Value getAllDrafts(jsi::Runtime &rt) = 0;
virtual jsi::Value removeAllDrafts(jsi::Runtime &rt) = 0;
virtual jsi::Value getAllMessages(jsi::Runtime &rt) = 0;
diff --git a/native/cpp/CommonCpp/_generated/NativeModules.cpp b/native/cpp/CommonCpp/_generated/NativeModules.cpp
--- a/native/cpp/CommonCpp/_generated/NativeModules.cpp
+++ b/native/cpp/CommonCpp/_generated/NativeModules.cpp
@@ -21,6 +21,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_moveDraft(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->moveDraft(rt, args[0].getString(rt), args[1].getString(rt));
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getClientDBStore(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getClientDBStore(rt);
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllDrafts(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getAllDrafts(rt);
}
@@ -95,6 +98,7 @@
methodMap_["getDraft"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDraft};
methodMap_["updateDraft"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_updateDraft};
methodMap_["moveDraft"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_moveDraft};
+ methodMap_["getClientDBStore"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getClientDBStore};
methodMap_["getAllDrafts"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllDrafts};
methodMap_["removeAllDrafts"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeAllDrafts};
methodMap_["getAllMessages"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllMessages};
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -18,10 +18,17 @@
ClientDBThreadStoreOperation,
} from 'lib/types/thread-types';
+type ClientDBStore = {
+ +messages: $ReadOnlyArray<ClientDBMessageInfo>,
+ +drafts: $ReadOnlyArray<ClientDBDraftInfo>,
+ +threads: $ReadOnlyArray<ClientDBThreadInfo>,
+};
+
export interface Spec extends TurboModule {
+getDraft: (key: string) => Promise<string>;
+updateDraft: (key: string, text: string) => Promise<boolean>;
+moveDraft: (oldKey: string, newKey: string) => Promise<boolean>;
+ +getClientDBStore: () => Promise<ClientDBStore>;
+getAllDrafts: () => Promise<$ReadOnlyArray<ClientDBDraftInfo>>;
+removeAllDrafts: () => Promise<void>;
+getAllMessages: () => Promise<$ReadOnlyArray<ClientDBMessageInfo>>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 1:17 AM (17 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2682718
Default Alt Text
D5774.id19097.diff (6 KB)
Attached To
Mode
D5774: Implement bulk JSI call te retrieve all SQLite data
Attached
Detach File
Event Timeline
Log In to Comment