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 @@ -236,6 +236,10 @@ jsi::Runtime &rt, jsi::Object siweBackupSecrets) override; virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override; + virtual jsi::Value setUserDataKeys( + jsi::Runtime &rt, + jsi::String backupDataKey, + jsi::String backupLogDataKey) override; virtual jsi::Value getAllInboundP2PMessages(jsi::Runtime &rt) override; virtual jsi::Value removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) 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 @@ -2820,6 +2820,36 @@ }); } +jsi::Value CommCoreModule::setUserDataKeys( + jsi::Runtime &rt, + jsi::String backupDataKey, + jsi::String backupLogDataKey) { + auto backupDataKeyCpp{backupDataKey.utf8(rt)}; + auto backupLogDataKeyCpp{backupLogDataKey.utf8(rt)}; + + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + taskType job = [=]() { + std::string error; + try { + DatabaseManager::getQueryExecutor().setUserDataKeys( + backupDataKeyCpp, backupLogDataKeyCpp); + } catch (std::system_error &e) { + error = e.what(); + } + this->jsInvoker_->invokeAsync([error, promise]() { + if (error.size()) { + promise->reject(error); + } else { + promise->resolve(jsi::Value::undefined()); + } + }); + }; + GlobalDBSingleton::instance.scheduleOrRunCancellable( + job, promise, this->jsInvoker_); + }); +} + jsi::Value CommCoreModule::getAllInboundP2PMessages(jsi::Runtime &rt) { return createPromiseAsJSIValue( rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -205,6 +205,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getSIWEBackupSecrets(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setUserDataKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->setUserDataKeys(rt, args[0].asString(rt), args[1].asString(rt)); +} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllInboundP2PMessages(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getAllInboundP2PMessages(rt); } @@ -309,6 +312,7 @@ methodMap_["getBackupUserKeys"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getBackupUserKeys}; methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets}; methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets}; + methodMap_["setUserDataKeys"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setUserDataKeys}; methodMap_["getAllInboundP2PMessages"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllInboundP2PMessages}; methodMap_["removeInboundP2PMessages"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeInboundP2PMessages}; methodMap_["getInboundP2PMessagesByID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getInboundP2PMessagesByID}; diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -82,6 +82,7 @@ virtual jsi::Value getBackupUserKeys(jsi::Runtime &rt, jsi::String userIdentifier, jsi::String backupSecret, jsi::String backupID) = 0; virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0; virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0; + virtual jsi::Value setUserDataKeys(jsi::Runtime &rt, jsi::String backupDataKey, jsi::String backupLogDataKey) = 0; virtual jsi::Value getAllInboundP2PMessages(jsi::Runtime &rt) = 0; virtual jsi::Value removeInboundP2PMessages(jsi::Runtime &rt, jsi::Array ids) = 0; virtual jsi::Value getInboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) = 0; @@ -612,6 +613,14 @@ return bridging::callFromJs( rt, &T::getSIWEBackupSecrets, jsInvoker_, instance_); } + jsi::Value setUserDataKeys(jsi::Runtime &rt, jsi::String backupDataKey, jsi::String backupLogDataKey) override { + static_assert( + bridging::getParameterCount(&T::setUserDataKeys) == 3, + "Expected setUserDataKeys(...) to have 3 parameters"); + + return bridging::callFromJs( + rt, &T::setUserDataKeys, jsInvoker_, instance_, std::move(backupDataKey), std::move(backupLogDataKey)); + } jsi::Value getAllInboundP2PMessages(jsi::Runtime &rt) override { static_assert( bridging::getParameterCount(&T::getAllInboundP2PMessages) == 1, diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -178,6 +178,10 @@ ) => Promise; +setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise; +getSIWEBackupSecrets: () => Promise; + +setUserDataKeys: ( + backupDataKey: string, + backupLogDataKey: string, + ) => Promise; +getAllInboundP2PMessages: () => Promise>; +removeInboundP2PMessages: (ids: $ReadOnlyArray) => Promise; +getInboundP2PMessagesByID: (