Skip to content

Commit db78c39

Browse files
committed
calling logout disable push subscription
1 parent 3083eae commit db78c39

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import com.onesignal.user.internal.identity.IdentityModelStore
4848
import com.onesignal.user.internal.operations.LoginUserFromSubscriptionOperation
4949
import com.onesignal.user.internal.operations.LoginUserOperation
5050
import com.onesignal.user.internal.operations.TransferSubscriptionOperation
51+
import com.onesignal.user.internal.operations.UpdateSubscriptionOperation
5152
import com.onesignal.user.internal.properties.PropertiesModel
5253
import com.onesignal.user.internal.properties.PropertiesModelStore
5354
import com.onesignal.user.internal.subscriptions.SubscriptionModel
@@ -426,13 +427,22 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
426427

427428
// calling createAndSwitchToNewUser() replaces model with a default empty jwt
428429
createAndSwitchToNewUser()
429-
operationRepo!!.enqueue(
430-
LoginUserOperation(
431-
configModel!!.appId,
432-
identityModelStore!!.model.onesignalId,
433-
identityModelStore!!.model.externalId,
434-
),
435-
)
430+
431+
if (useIdentityVerification) {
432+
// disable subscription if identity verification is on
433+
operationRepo!!.enqueue(
434+
UpdateSubscriptionOperation(),
435+
)
436+
} else {
437+
// login to the anonymous user if identity verification is off
438+
operationRepo!!.enqueue(
439+
LoginUserOperation(
440+
configModel!!.appId,
441+
identityModelStore!!.model.onesignalId,
442+
identityModelStore!!.model.externalId,
443+
),
444+
)
445+
}
436446
}
437447
}
438448

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class SubscriptionModelStoreListener(
1919
private val _configModelStore: ConfigModelStore,
2020
) : ModelStoreListener<SubscriptionModel>(store, opRepo) {
2121
override fun getAddOperation(model: SubscriptionModel): Operation {
22-
val enabledAndStatus = getSubscriptionEnabledAndStatus(model)
22+
val enabledAndStatus = getSubscriptionEnabledAndStatus(model, _identityModelStore, _configModelStore)
2323
return CreateSubscriptionOperation(
2424
_configModelStore.model.appId,
2525
_identityModelStore.model.onesignalId,
@@ -42,7 +42,7 @@ internal class SubscriptionModelStoreListener(
4242
oldValue: Any?,
4343
newValue: Any?,
4444
): Operation {
45-
val enabledAndStatus = getSubscriptionEnabledAndStatus(model)
45+
val enabledAndStatus = getSubscriptionEnabledAndStatus(model, _identityModelStore, _configModelStore)
4646
return UpdateSubscriptionOperation(
4747
_configModelStore.model.appId,
4848
_identityModelStore.model.onesignalId,
@@ -55,11 +55,20 @@ internal class SubscriptionModelStoreListener(
5555
}
5656

5757
companion object {
58-
fun getSubscriptionEnabledAndStatus(model: SubscriptionModel): Pair<Boolean, SubscriptionStatus> {
58+
fun getSubscriptionEnabledAndStatus(
59+
model: SubscriptionModel,
60+
identityModelStore: IdentityModelStore,
61+
configModelStore: ConfigModelStore,
62+
): Pair<Boolean, SubscriptionStatus> {
5963
val status: SubscriptionStatus
6064
val enabled: Boolean
6165

62-
if (model.optedIn && model.status == SubscriptionStatus.SUBSCRIBED && model.address.isNotEmpty()) {
66+
/*
67+
When identity verification is off, we can enable the subscription regardless of the login status.
68+
When identity verification is on, the subscription is enabled only when a user is currently logged in.
69+
*/
70+
val isUserLoggedInWhenIdentityRequired = !configModelStore.model.useIdentityVerification || !identityModelStore.model.externalId.isNullOrEmpty()
71+
if (isUserLoggedInWhenIdentityRequired && model.optedIn && model.status == SubscriptionStatus.SUBSCRIBED && model.address.isNotEmpty()) {
6372
enabled = true
6473
status = SubscriptionStatus.SUBSCRIBED
6574
} else {

0 commit comments

Comments
 (0)