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 @@ -199,6 +199,7 @@ virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override; virtual jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) override; + virtual jsi::Value getStoredVersion(jsi::Runtime &rt) 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 @@ -2220,4 +2220,38 @@ }); } +jsi::Value CommCoreModule::getStoredVersion(jsi::Runtime &rt) { + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + taskType job = [=, &innerRt]() { + std::string error; + std::vector syncedMetadataStoreVector; + try { + syncedMetadataStoreVector = + DatabaseManager::getQueryExecutor().getAllSyncedMetadata(); + } catch (std::system_error &e) { + error = e.what(); + } + std::string version; + for (auto &entry : syncedMetadataStoreVector) { + if (entry.name == "db_version") { + version = entry.data; + } + } + + this->jsInvoker_->invokeAsync([&innerRt, error, promise, version]() { + if (error.size()) { + promise->reject(error); + return; + } + jsi::String jsiVersion = + jsi::String::createFromUtf8(innerRt, version); + promise->resolve(std::move(jsiVersion)); + }); + }; + GlobalDBSingleton::instance.scheduleOrRunCancellable( + job, promise, this->jsInvoker_); + }); +} + } // namespace comm 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 @@ -187,6 +187,9 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->removeReceivedMessagesToDevice(rt, args[0].asObject(rt).asArray(rt)); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getStoredVersion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->getStoredVersion(rt); +} CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr jsInvoker) : TurboModule("CommTurboModule", jsInvoker) { @@ -246,6 +249,7 @@ methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets}; methodMap_["getAllReceivedMessageToDevice"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice}; methodMap_["removeReceivedMessagesToDevice"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice}; + methodMap_["getStoredVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getStoredVersion}; } 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 @@ -76,6 +76,7 @@ virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0; virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) = 0; virtual jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) = 0; + virtual jsi::Value getStoredVersion(jsi::Runtime &rt) = 0; }; @@ -545,6 +546,14 @@ return bridging::callFromJs( rt, &T::removeReceivedMessagesToDevice, jsInvoker_, instance_, std::move(ids)); } + jsi::Value getStoredVersion(jsi::Runtime &rt) override { + static_assert( + bridging::getParameterCount(&T::getStoredVersion) == 1, + "Expected getStoredVersion(...) to have 1 parameters"); + + return bridging::callFromJs( + rt, &T::getStoredVersion, jsInvoker_, instance_); + } private: T *instance_; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -142,6 +142,7 @@ +removeReceivedMessagesToDevice: ( ids: $ReadOnlyArray, ) => Promise; + +getStoredVersion: () => Promise; } export interface CoreModuleSpec extends Spec {