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 @@ -58,6 +58,8 @@ jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) override; jsi::Value clearNotifyToken(jsi::Runtime &rt) override; + void setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) override; + jsi::String getCurrentUserID(jsi::Runtime &rt) override; void clearSensitiveData(jsi::Runtime &rt) override; public: 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 @@ -955,6 +955,41 @@ }); }; +void CommCoreModule::setCurrentUserID( + jsi::Runtime &rt, + const jsi::String &userID) { + std::promise setCurrentUserIDResult; + auto setCurrentUserIDResultFuture = setCurrentUserIDResult.get_future(); + this->databaseThread->scheduleTask([&rt, &setCurrentUserIDResult, &userID]() { + try { + auto currentUserID{userID.utf8(rt)}; + DatabaseManager::getQueryExecutor().setCurrentUserID(currentUserID); + setCurrentUserIDResult.set_value(); + } catch (const std::exception &e) { + setCurrentUserIDResult.set_exception( + std::make_exception_ptr(jsi::JSError(rt, e.what()))); + } + }); + setCurrentUserIDResultFuture.get(); +} + +jsi::String CommCoreModule::getCurrentUserID(jsi::Runtime &rt) { + std::promise getCurrentUserIDResult; + auto getCurrentUserIDResultFuture = getCurrentUserIDResult.get_future(); + this->databaseThread->scheduleTask([&rt, &getCurrentUserIDResult]() { + try { + std::string currentUserID = + DatabaseManager::getQueryExecutor().getCurrentUserID(); + getCurrentUserIDResult.set_value( + jsi::String::createFromUtf8(rt, currentUserID)); + } catch (const std::exception &e) { + getCurrentUserIDResult.set_exception( + std::make_exception_ptr(jsi::JSError(rt, e.what()))); + } + }); + return getCurrentUserIDResultFuture.get(); +} + void CommCoreModule::clearSensitiveData(jsi::Runtime &rt) { try { DatabaseManager::getQueryExecutor().clearSensitiveData(); 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 @@ -38,6 +38,8 @@ virtual double getCodeVersion(jsi::Runtime &rt) = 0; virtual jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) = 0; virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0; +virtual void setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) = 0; +virtual jsi::String getCurrentUserID(jsi::Runtime &rt) = 0; virtual void clearSensitiveData(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 @@ -72,6 +72,13 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->clearNotifyToken(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + static_cast(&turboModule)->setCurrentUserID(rt, args[0].getString(rt)); + return jsi::Value::undefined(); +} +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->getCurrentUserID(rt); +} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { static_cast(&turboModule)->clearSensitiveData(rt); return jsi::Value::undefined(); @@ -99,6 +106,8 @@ methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion}; methodMap_["setNotifyToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken}; methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken}; + methodMap_["setCurrentUserID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID}; + methodMap_["getCurrentUserID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID}; methodMap_["clearSensitiveData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData}; } diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -48,6 +48,8 @@ +getCodeVersion: () => number; +setNotifyToken: (token: string) => Promise; +clearNotifyToken: () => Promise; + +setCurrentUserID: (userID: string) => void; + +getCurrentUserID: () => string; +clearSensitiveData: () => void; }