From d120b522dbd7a8bf5aa1e1c044f2deb247346b9d Mon Sep 17 00:00:00 2001 From: Nan Date: Sat, 28 Jun 2025 14:26:42 -0700 Subject: [PATCH] Don't manually remove the push subscription * When the SDK hydrates users, it will trigger the subscription model store's `replaceAll` method. This will remove the current push subscription model and immediately add a new push subscription model. The Subscription Manager was removing the current push subscription and then adding a new push subscription that it manages. When the new one is added, the old one is removed and any observers are transferred over. * However, because the old one was already removed by the time the new one is added, observers are lost. The [onModelAdded] already triggers an add and remove, so we should not remove in the [onModelRemoved] event. * These 2 events are always together. There is no current usage where only [onModelRemoved] is called for a push subscription model. Even on 404s, push subscription models are not removed. --- .../internal/subscriptions/impl/SubscriptionManager.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/subscriptions/impl/SubscriptionManager.kt b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/subscriptions/impl/SubscriptionManager.kt index 57bc9f175b..ee869cafb2 100644 --- a/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/subscriptions/impl/SubscriptionManager.kt +++ b/OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/subscriptions/impl/SubscriptionManager.kt @@ -190,6 +190,14 @@ internal class SubscriptionManager( model: SubscriptionModel, tag: String, ) { + // Do not remove the push subscription: we need to keep the existing push subscription and its observers + // This push subscription will immediately be replaced by the new one in the [onModelAdded] event + // The [onModelRemoved] event for a push subscription model should always be followed by a [onModelAdded] + // event with a new push subscription model. On 404s, no push subscription models are removed. + if (model.type == SubscriptionType.PUSH) { + return + } + val subscription = subscriptions.collection.firstOrNull { it.id == model.id } if (subscription != null) {