Page MenuHomePhabricator

D5201.id17108.diff
No OneTemporary

D5201.id17108.diff

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
@@ -39,7 +39,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;
@@ -47,7 +47,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
@@ -25,7 +25,12 @@
std::promise<T> promise;
this->databaseThread->scheduleTask([&promise, &task]() {
try {
- promise.set_value(task());
+ if constexpr (std::is_void<T>::value) {
+ task();
+ promise.set_value();
+ } else {
+ promise.set_value(task());
+ }
} catch (const std::exception &e) {
promise.set_exception(std::make_exception_ptr(e));
}
@@ -403,40 +408,29 @@
});
}
-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();
+ this->runSyncOrThrowJSError<void>(rt, [&messageStoreOps]() {
+ try {
+ DatabaseManager::getQueryExecutor().beginTransaction();
+ for (const auto &operation : messageStoreOps) {
+ operation->execute();
+ }
+ DatabaseManager::getQueryExecutor().commitTransaction();
+ } catch (const std::exception &e) {
+ DatabaseManager::getQueryExecutor().rollbackTransaction();
+ throw e;
+ }
+ });
}
jsi::Value CommCoreModule::getAllThreads(jsi::Runtime &rt) {
@@ -730,37 +724,29 @@
});
}
-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());
}
- 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();
+
+ this->runSyncOrThrowJSError<void>(rt, [&threadStoreOps]() {
+ try {
+ DatabaseManager::getQueryExecutor().beginTransaction();
+ for (const auto &operation : threadStoreOps) {
+ operation->execute();
+ }
+ DatabaseManager::getQueryExecutor().commitTransaction();
+ } catch (const std::exception &e) {
+ DatabaseManager::getQueryExecutor().rollbackTransaction();
+ throw e;
+ }
+ });
}
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
@@ -341,10 +341,12 @@
payload: { id, threadInfo: threadInfos[id] },
})),
];
- const processingResult: boolean = commCoreModule.processThreadStoreOperationsSync(
- convertThreadStoreOperationsToClientDBOperations(operations),
- );
- if (!processingResult) {
+ try {
+ commCoreModule.processThreadStoreOperationsSync(
+ convertThreadStoreOperationsToClientDBOperations(operations),
+ );
+ } catch (exception) {
+ console.log(exception);
return { ...state, cookie: null };
}
return state;
@@ -360,10 +362,10 @@
payload: translateRawMessageInfoToClientDBMessageInfo(messages[id]),
})),
];
- const processingResult: boolean = commCoreModule.processMessageStoreOperationsSync(
- operations,
- );
- if (!processingResult) {
+ try {
+ 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

Mime Type
text/plain
Expires
Sun, Nov 24, 3:37 AM (20 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573276
Default Alt Text
D5201.id17108.diff (10 KB)

Event Timeline