Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Method optIn() not working after optOut() has been called #1957

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class RefreshUserOperationExecutor(
SubscriptionType.PUSH
}
}
subscriptionModel.optedIn = subscriptionModel.status != SubscriptionStatus.UNSUBSCRIBE
subscriptionModel.optedIn = subscriptionModel.status != SubscriptionStatus.UNSUBSCRIBE && subscriptionModel.status != SubscriptionStatus.DISABLED_FROM_REST_API_DEFAULT_REASON
subscriptionModel.sdk = subscription.sdk ?: ""
subscriptionModel.deviceOS = subscription.deviceOS ?: ""
subscriptionModel.carrier = subscription.carrier ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ enum class SubscriptionStatus(val value: Int) {
/** The subscription is not enabled due to an FCM authentication failed IOException */
FIREBASE_FCM_ERROR_IOEXCEPTION_AUTHENTICATION_FAILED(-29),

/** The subscription is not enabled because the app has disabled the subscription via API */
DISABLED_FROM_REST_API_DEFAULT_REASON(-30),

/** The subscription is not enabled due to some other (unknown locally) error */
ERROR(9999),
;
Expand All @@ -79,6 +82,10 @@ enum class SubscriptionStatus(val value: Int) {
}

class SubscriptionModel : Model() {
/**
* Reflects user preference only, defaults true.
* The public API for [IPushSubscription.optedIn] considers this value AND permission.
*/
var optedIn: Boolean
get() = getBooleanProperty(::optedIn.name)
set(value) {
Expand All @@ -97,6 +104,13 @@ class SubscriptionModel : Model() {
setStringProperty(::address.name, value)
}

/**
* This reflects the "device-level" subscription status.
*
* For example, if [IPushSubscription.optOut] is called, the SDK sends UNSUBSCRIBE(-2) to the server.
* However, locally on the model, we still keep the existing status.
* It is necessary when [IPushSubscription.optIn] is called again to know the true device status.
*/
var status: SubscriptionStatus
get() {
if (!hasProperty(::status.name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ open class SubscriptionModelStore(prefs: IPreferencesService) : SimpleModelStore
model.deviceOS = existingPushModel.deviceOS
model.carrier = existingPushModel.carrier
model.appVersion = existingPushModel.appVersion
model.status = existingPushModel.status
}
break
}
Expand Down
Loading