diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseQueryExecutor.h @@ -55,6 +55,7 @@ virtual std::vector getOlmPersistSessionsData() const = 0; virtual folly::Optional getOlmPersistAccountData() const = 0; virtual void storeOlmPersistData(crypto::Persist persist) const = 0; + virtual void setNotifyToken(std::string token) const = 0; }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h @@ -48,6 +48,7 @@ std::vector getOlmPersistSessionsData() const override; folly::Optional getOlmPersistAccountData() const override; void storeOlmPersistData(crypto::Persist persist) const override; + void setNotifyToken(std::string token) const override; }; } // namespace comm diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp @@ -733,4 +733,12 @@ } } +void SQLiteQueryExecutor::setNotifyToken(std::string token) const { + Metadata entry{ + "notify_token", + token, + }; + SQLiteQueryExecutor::getStorage().replace(entry); +} + } // namespace comm 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 @@ -55,6 +55,8 @@ jsi::Object openSocket(jsi::Runtime &rt, const jsi::String &endpoint) override; double getCodeVersion(jsi::Runtime &rt) override; + jsi::Value + setNotifyToken(jsi::Runtime &rt, const jsi::String &token) override; public: CommCoreModule(std::shared_ptr jsInvoker); 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 @@ -904,6 +904,32 @@ double CommCoreModule::getCodeVersion(jsi::Runtime &rt) { return this->codeVersion; +} + +jsi::Value +CommCoreModule::setNotifyToken(jsi::Runtime &rt, const jsi::String &token) { + auto notifyToken{token.utf8(rt)}; + return createPromiseAsJSIValue( + rt, + [this, + notifyToken](jsi::Runtime &innerRt, std::shared_ptr promise) { + this->databaseThread->scheduleTask([this, notifyToken, promise]() { + std::string error; + try { + DatabaseManager::getQueryExecutor().setNotifyToken(notifyToken); + } 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()); + } + }); + }); + }); }; } // namespace comm 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 @@ -36,6 +36,7 @@ virtual jsi::Value getUserOneTimeKeys(jsi::Runtime &rt) = 0; virtual jsi::Object openSocket(jsi::Runtime &rt, const jsi::String &endpoint) = 0; virtual double getCodeVersion(jsi::Runtime &rt) = 0; +virtual jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) = 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 @@ -66,6 +66,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getCodeVersion(rt); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->setNotifyToken(rt, args[0].getString(rt)); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -87,6 +90,7 @@ methodMap_["getUserOneTimeKeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserOneTimeKeys}; methodMap_["openSocket"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_openSocket}; methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion}; + methodMap_["setNotifyToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken}; } diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -46,6 +46,7 @@ +getUserOneTimeKeys: () => Promise; +openSocket: (endpoint: string) => Object; +getCodeVersion: () => number; + +setNotifyToken: (token: string) => Promise; } export default (TurboModuleRegistry.getEnforcing(