Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3351938
D5201.id16939.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D5201.id16939.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
@@ -37,7 +37,7 @@
jsi::Value processMessageStoreOperations(
jsi::Runtime &rt,
const jsi::Array &operations) override;
- bool processMessageStoreOperationsSync(
+ void processMessageStoreOperationsSync(
jsi::Runtime &rt,
const jsi::Array &operations) override;
jsi::Value getAllThreads(jsi::Runtime &rt) override;
@@ -45,7 +45,7 @@
jsi::Value processThreadStoreOperations(
jsi::Runtime &rt,
const jsi::Array &operations) override;
- bool processThreadStoreOperationsSync(
+ void processThreadStoreOperationsSync(
jsi::Runtime &rt,
const jsi::Array &operations) override;
jsi::Value
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
@@ -387,40 +387,36 @@
});
}
-bool CommCoreModule::processMessageStoreOperationsSync(
+void CommCoreModule::processMessageStoreOperationsSync(
jsi::Runtime &rt,
const jsi::Array &operations) {
-
- std::promise<bool> operationsResult;
- std::future<bool> operationsResultFuture = operationsResult.get_future();
-
std::vector<std::unique_ptr<MessageStoreOperationBase>> messageStoreOps;
- std::string operationsError;
try {
messageStoreOps = createMessageStoreOperations(rt, operations);
- } catch (std::runtime_error &e) {
- return false;
+ } catch (const std::exception &e) {
+ throw jsi::JSError(rt, e.what());
}
- this->databaseThread->scheduleTask(
- [=, &messageStoreOps, &operationsResult, &rt]() {
- std::string error = operationsError;
- if (!error.size()) {
- try {
- DatabaseManager::getQueryExecutor().beginTransaction();
- for (const auto &operation : messageStoreOps) {
- operation->execute();
- }
- DatabaseManager::getQueryExecutor().commitTransaction();
- } catch (std::system_error &e) {
- error = e.what();
- DatabaseManager::getQueryExecutor().rollbackTransaction();
- }
- }
- operationsResult.set_value(error.size() == 0);
- });
- return operationsResultFuture.get();
+ std::promise<void> operationsResult;
+ this->databaseThread->scheduleTask([&messageStoreOps, &operationsResult]() {
+ try {
+ DatabaseManager::getQueryExecutor().beginTransaction();
+ for (const auto &operation : messageStoreOps) {
+ operation->execute();
+ }
+ DatabaseManager::getQueryExecutor().commitTransaction();
+ } catch (const std::exception &e) {
+ DatabaseManager::getQueryExecutor().rollbackTransaction();
+ operationsResult.set_exception(std::make_exception_ptr(e));
+ }
+ });
+
+ try {
+ operationsResult.get_future().get();
+ } catch (const std::exception &e) {
+ throw jsi::JSError(rt, e.what());
+ }
}
jsi::Value CommCoreModule::getAllThreads(jsi::Runtime &rt) {
@@ -721,37 +717,36 @@
});
}
-bool CommCoreModule::processThreadStoreOperationsSync(
+void CommCoreModule::processThreadStoreOperationsSync(
jsi::Runtime &rt,
const jsi::Array &operations) {
-
- std::promise<bool> operationsResult;
- std::future<bool> operationsResultFuture = operationsResult.get_future();
std::vector<std::unique_ptr<ThreadStoreOperationBase>> threadStoreOps;
- std::string operationsError;
+
try {
threadStoreOps = createThreadStoreOperations(rt, operations);
- } catch (std::runtime_error &e) {
- return false;
+ } catch (const std::exception &e) {
+ throw jsi::JSError(rt, e.what());
+ }
+
+ std::promise<void> operationsResult;
+ this->databaseThread->scheduleTask([&threadStoreOps, &operationsResult]() {
+ try {
+ DatabaseManager::getQueryExecutor().beginTransaction();
+ for (const auto &operation : threadStoreOps) {
+ operation->execute();
+ }
+ DatabaseManager::getQueryExecutor().commitTransaction();
+ } catch (const std::exception &e) {
+ DatabaseManager::getQueryExecutor().rollbackTransaction();
+ operationsResult.set_exception(std::make_exception_ptr(e));
+ }
+ });
+
+ try {
+ operationsResult.get_future().get();
+ } catch (const std::exception &e) {
+ throw jsi::JSError(rt, e.what());
}
- this->databaseThread->scheduleTask(
- [=, &threadStoreOps, &operationsResult, &rt]() {
- std::string error = operationsError;
- if (!error.size()) {
- try {
- DatabaseManager::getQueryExecutor().beginTransaction();
- for (const auto &operation : threadStoreOps) {
- operation->execute();
- }
- DatabaseManager::getQueryExecutor().commitTransaction();
- } catch (std::system_error &e) {
- error = e.what();
- DatabaseManager::getQueryExecutor().rollbackTransaction();
- }
- }
- operationsResult.set_value(error.size() == 0);
- });
- return operationsResultFuture.get();
}
jsi::Value CommCoreModule::initializeCryptoAccount(
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
@@ -26,11 +26,11 @@
virtual jsi::Value getAllMessages(jsi::Runtime &rt) = 0;
virtual jsi::Array getAllMessagesSync(jsi::Runtime &rt) = 0;
virtual jsi::Value processMessageStoreOperations(jsi::Runtime &rt, const jsi::Array &operations) = 0;
-virtual bool processMessageStoreOperationsSync(jsi::Runtime &rt, const jsi::Array &operations) = 0;
+virtual void processMessageStoreOperationsSync(jsi::Runtime &rt, const jsi::Array &operations) = 0;
virtual jsi::Value getAllThreads(jsi::Runtime &rt) = 0;
virtual jsi::Array getAllThreadsSync(jsi::Runtime &rt) = 0;
virtual jsi::Value processThreadStoreOperations(jsi::Runtime &rt, const jsi::Array &operations) = 0;
-virtual bool processThreadStoreOperationsSync(jsi::Runtime &rt, const jsi::Array &operations) = 0;
+virtual void processThreadStoreOperationsSync(jsi::Runtime &rt, const jsi::Array &operations) = 0;
virtual jsi::Value initializeCryptoAccount(jsi::Runtime &rt, const jsi::String &userId) = 0;
virtual jsi::Value getUserPublicKey(jsi::Runtime &rt) = 0;
virtual jsi::Value getUserOneTimeKeys(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
@@ -37,7 +37,8 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processMessageStoreOperations(rt, args[0].getObject(rt).getArray(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_processMessageStoreOperationsSync(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processMessageStoreOperationsSync(rt, args[0].getObject(rt).getArray(rt));
+ static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processMessageStoreOperationsSync(rt, args[0].getObject(rt).getArray(rt));
+ return jsi::Value::undefined();
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllThreads(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getAllThreads(rt);
@@ -49,7 +50,8 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processThreadStoreOperations(rt, args[0].getObject(rt).getArray(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_processThreadStoreOperationsSync(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processThreadStoreOperationsSync(rt, args[0].getObject(rt).getArray(rt));
+ static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->processThreadStoreOperationsSync(rt, args[0].getObject(rt).getArray(rt));
+ return jsi::Value::undefined();
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->initializeCryptoAccount(rt, args[0].getString(rt));
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -340,10 +340,12 @@
payload: { id, threadInfo: threadInfos[id] },
})),
];
- const processingResult: boolean = global.CommCoreModule.processThreadStoreOperationsSync(
- convertThreadStoreOperationsToClientDBOperations(operations),
- );
- if (!processingResult) {
+ try {
+ global.CommCoreModule.processThreadStoreOperationsSync(
+ convertThreadStoreOperationsToClientDBOperations(operations),
+ );
+ } catch (exception) {
+ console.log(exception);
return { ...state, cookie: null };
}
return state;
@@ -359,10 +361,10 @@
payload: translateRawMessageInfoToClientDBMessageInfo(messages[id]),
})),
];
- const processingResult: boolean = global.CommCoreModule.processMessageStoreOperationsSync(
- operations,
- );
- if (!processingResult) {
+ try {
+ global.CommCoreModule.processMessageStoreOperationsSync(operations);
+ } catch (exception) {
+ console.log(exception);
return { ...state, cookie: null };
}
return state;
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -32,7 +32,7 @@
) => Promise<void>;
+processMessageStoreOperationsSync: (
operations: $ReadOnlyArray<ClientDBMessageStoreOperation>,
- ) => boolean;
+ ) => void;
+getAllThreads: () => Promise<$ReadOnlyArray<ClientDBThreadInfo>>;
+getAllThreadsSync: () => $ReadOnlyArray<ClientDBThreadInfo>;
+processThreadStoreOperations: (
@@ -40,7 +40,7 @@
) => Promise<void>;
+processThreadStoreOperationsSync: (
operations: $ReadOnlyArray<ClientDBThreadStoreOperation>,
- ) => boolean;
+ ) => void;
+initializeCryptoAccount: (userId: string) => Promise<string>;
+getUserPublicKey: () => Promise<string>;
+getUserOneTimeKeys: () => Promise<string>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 4:07 AM (21 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573842
Default Alt Text
D5201.id16939.diff (10 KB)
Attached To
Mode
D5201: [native] Throw JSError in sync functions
Attached
Detach File
Event Timeline
Log In to Comment