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 @@ -128,6 +128,11 @@ virtual jsi::Value getKeyserverDataFromNotifStorage( jsi::Runtime &rt, jsi::Array keyserverIDs) override; + virtual jsi::Value updateUnreadThickThreadsInNotifsStorage( + jsi::Runtime &rt, + jsi::Array unreadThickThreadIDs) override; + virtual jsi::Value + getUnreadThickThreadIDsFromNotifsStorage(jsi::Runtime &rt) override; virtual jsi::Value initializeContentOutboundSession( jsi::Runtime &rt, jsi::String identityKeys, 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 @@ -1471,6 +1471,74 @@ }); } +jsi::Value CommCoreModule::updateUnreadThickThreadsInNotifsStorage( + jsi::Runtime &rt, + jsi::Array unreadThickThreadIDs) { + std::vector unreadThickThreadIDsCpp{}; + for (auto idx = 0; idx < unreadThickThreadIDs.size(rt); idx++) { + std::string thickThreadID = + unreadThickThreadIDs.getValueAtIndex(rt, idx).asString(rt).utf8(rt); + unreadThickThreadIDsCpp.push_back(thickThreadID); + } + + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + std::string error; + try { + CommMMKV::setStringSet( + "NOTIFS.UNREAD_THICK_THREADS", unreadThickThreadIDsCpp); + } catch (const std::exception &e) { + error = e.what(); + } + + this->jsInvoker_->invokeAsync([=, &innerRt]() { + if (error.size()) { + promise->reject(error); + return; + } + promise->resolve(jsi::Value::undefined()); + }); + }); +} + +jsi::Value +CommCoreModule::getUnreadThickThreadIDsFromNotifsStorage(jsi::Runtime &rt) { + return createPromiseAsJSIValue( + rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { + std::string error; + std::vector unreadThickThreadIDs{}; + try { + unreadThickThreadIDs = + CommMMKV::getStringSet("NOTIFS.UNREAD_THICK_THREADS"); + } catch (const std::exception &e) { + error = e.what(); + } + + auto unreadThreadThickThreadIDsPtr = + std::make_shared>( + std::move(unreadThickThreadIDs)); + + this->jsInvoker_->invokeAsync([=, &innerRt]() { + if (error.size()) { + promise->reject(error); + return; + } + + jsi::Array jsiUnreadThickThreadIDs = + jsi::Array(innerRt, unreadThreadThickThreadIDsPtr->size()); + size_t writeIdx = 0; + + for (const auto &thickThreadID : *unreadThreadThickThreadIDsPtr) { + jsi::String jsiThickThreadID = + jsi::String::createFromUtf8(innerRt, thickThreadID); + jsiUnreadThickThreadIDs.setValueAtIndex( + innerRt, writeIdx++, jsiThickThreadID); + } + promise->resolve(std::move(jsiUnreadThickThreadIDs)); + }); + }); +} + jsi::Value CommCoreModule::initializeContentOutboundSession( jsi::Runtime &rt, jsi::String identityKeys, 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 @@ -84,6 +84,12 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getKeyserverDataFromNotifStorage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getKeyserverDataFromNotifStorage(rt, args[0].asObject(rt).asArray(rt)); } +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_updateUnreadThickThreadsInNotifsStorage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->updateUnreadThickThreadsInNotifsStorage(rt, args[0].asObject(rt).asArray(rt)); +} +static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUnreadThickThreadIDsFromNotifsStorage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { + return static_cast(&turboModule)->getUnreadThickThreadIDsFromNotifsStorage(rt); +} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentOutboundSession(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->initializeContentOutboundSession(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].isNull() || args[3].isUndefined() ? std::nullopt : std::make_optional(args[3].asString(rt)), args[4].asString(rt)); } @@ -264,6 +270,8 @@ methodMap_["updateKeyserverDataInNotifStorage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_updateKeyserverDataInNotifStorage}; methodMap_["removeKeyserverDataFromNotifStorage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeKeyserverDataFromNotifStorage}; methodMap_["getKeyserverDataFromNotifStorage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getKeyserverDataFromNotifStorage}; + methodMap_["updateUnreadThickThreadsInNotifsStorage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_updateUnreadThickThreadsInNotifsStorage}; + methodMap_["getUnreadThickThreadIDsFromNotifsStorage"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUnreadThickThreadIDsFromNotifsStorage}; methodMap_["initializeContentOutboundSession"] = MethodMetadata {5, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentOutboundSession}; methodMap_["initializeContentInboundSession"] = MethodMetadata {5, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentInboundSession}; methodMap_["isContentSessionInitialized"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_isContentSessionInitialized}; 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 @@ -43,6 +43,8 @@ virtual jsi::Value updateKeyserverDataInNotifStorage(jsi::Runtime &rt, jsi::Array keyserversData) = 0; virtual jsi::Value removeKeyserverDataFromNotifStorage(jsi::Runtime &rt, jsi::Array keyserverIDsToDelete) = 0; virtual jsi::Value getKeyserverDataFromNotifStorage(jsi::Runtime &rt, jsi::Array keyserverIDs) = 0; + virtual jsi::Value updateUnreadThickThreadsInNotifsStorage(jsi::Runtime &rt, jsi::Array unreadThickThreadIDs) = 0; + virtual jsi::Value getUnreadThickThreadIDsFromNotifsStorage(jsi::Runtime &rt) = 0; virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, std::optional oneTimeKey, jsi::String deviceID) = 0; virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::Object encryptedContent, jsi::String deviceID, double sessionVersion, bool overwrite) = 0; virtual jsi::Value isContentSessionInitialized(jsi::Runtime &rt, jsi::String deviceID) = 0; @@ -298,6 +300,22 @@ return bridging::callFromJs( rt, &T::getKeyserverDataFromNotifStorage, jsInvoker_, instance_, std::move(keyserverIDs)); } + jsi::Value updateUnreadThickThreadsInNotifsStorage(jsi::Runtime &rt, jsi::Array unreadThickThreadIDs) override { + static_assert( + bridging::getParameterCount(&T::updateUnreadThickThreadsInNotifsStorage) == 2, + "Expected updateUnreadThickThreadsInNotifsStorage(...) to have 2 parameters"); + + return bridging::callFromJs( + rt, &T::updateUnreadThickThreadsInNotifsStorage, jsInvoker_, instance_, std::move(unreadThickThreadIDs)); + } + jsi::Value getUnreadThickThreadIDsFromNotifsStorage(jsi::Runtime &rt) override { + static_assert( + bridging::getParameterCount(&T::getUnreadThickThreadIDsFromNotifsStorage) == 1, + "Expected getUnreadThickThreadIDsFromNotifsStorage(...) to have 1 parameters"); + + return bridging::callFromJs( + rt, &T::getUnreadThickThreadIDsFromNotifsStorage, jsInvoker_, instance_); + } jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, std::optional oneTimeKey, jsi::String deviceID) override { static_assert( bridging::getParameterCount(&T::initializeContentOutboundSession) == 6, diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -83,6 +83,12 @@ +getKeyserverDataFromNotifStorage: ( keyserverIDs: $ReadOnlyArray, ) => Promise<$ReadOnlyArray<{ +id: string, +unreadCount: number }>>; + +updateUnreadThickThreadsInNotifsStorage: ( + unreadThickThreadIDs: $ReadOnlyArray, + ) => Promise; + +getUnreadThickThreadIDsFromNotifsStorage: () => Promise< + $ReadOnlyArray, + >; +initializeContentOutboundSession: ( identityKeys: string, prekey: string,