Skip to content

Commit c0bde45

Browse files
committed
Add isDisabledInternally to SubscriptionModel for IV logout
When Identity Verification is ON and logout is called, the SDK now sets isDisabledInternally=true instead of optedIn=false. This preserves the real opt-in preference while telling the backend the subscription is disabled. On the next login, UserSwitcher creates a fresh SubscriptionModel that defaults isDisabledInternally=false, restoring the real state automatically. Made-with: Cursor
1 parent 684db4c commit c0bde45

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/LogoutHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LogoutHelper(
2323
if (configModel.useIdentityVerification == true) {
2424
configModel.pushSubscriptionId?.let { pushSubId ->
2525
subscriptionModelStore.get(pushSubId)
26-
?.setBooleanProperty("optedIn", false)
26+
?.let { it.isDisabledInternally = true }
2727
}
2828

2929
userSwitcher.createAndSwitchToNewUser(suppressBackendOperation = true)

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/listeners/SubscriptionModelStoreListener.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ internal class SubscriptionModelStoreListener(
6666

6767
companion object {
6868
fun getSubscriptionEnabledAndStatus(model: SubscriptionModel): Pair<Boolean, SubscriptionStatus> {
69+
if (model.isDisabledInternally) {
70+
return Pair(false, SubscriptionStatus.UNSUBSCRIBE)
71+
}
72+
6973
val status: SubscriptionStatus
7074
val enabled: Boolean
7175

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/subscriptions/SubscriptionModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ class SubscriptionModel : Model() {
9292
setBooleanProperty(::optedIn.name, value)
9393
}
9494

95+
/**
96+
* Set to true by the SDK when logout is called with Identity Verification enabled.
97+
* The real [optedIn] and [status] remain unchanged to preserve the user's preference.
98+
* When a subscription update is built, this flag causes enabled=false and
99+
* status=UNSUBSCRIBE to be sent to the backend instead of the real values.
100+
* On the next login, [UserSwitcher.createAndSwitchToNewUser] creates a fresh model
101+
* that does not carry this flag (defaults to false), restoring the real state.
102+
*/
103+
var isDisabledInternally: Boolean
104+
get() = getBooleanProperty(::isDisabledInternally.name) { false }
105+
set(value) {
106+
setBooleanProperty(::isDisabledInternally.name, value)
107+
}
108+
95109
var type: SubscriptionType
96110
get() = getEnumProperty(::type.name)
97111
set(value) {

0 commit comments

Comments
 (0)