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

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Jan 9, 2024

Description

One Line Summary

Fix method optIn() not working after optOut() has been called, by maintaining the local push subscription status.

Details

Motivation

Existing Problem:

  • If on a previous session, optOut() was called, that means we sent notification_types of UNSUBSCRIBE(-2) to the server.
  • We will hydrate the push subscription with the status of UNSUBSCRIBE(-2) in the response on the next session.
  • However, we lose the true device-level subscription status in doing so.
  • Then, when optIn() is called, we were using UNSUBSCRIBE(-2) along with optedIn to calculate the data to send in the Update Subscription request.
  • This resulted in incorrect values being sent and reports of optIn() method not working.

Solution:

  • We can still hydrate the push subscription model's optedIn property if we see either UNSUBSCRIBE(-2) or DISABLED_FROM_REST_API_DEFAULT_REASON(-30) in the response.
  • However, we will not hydrate the model.status from the server. When the subscription model store is replacing all of the subscriptions in the refresh user operation, keep the existing push subscription status.
  • This way, when optIn() is called again, we can use this device-level status with the optedIn boolean to calculate values to send to the server.

Scope

  • Also added parsing of DISABLED_FROM_REST_API_DEFAULT_REASON(-30) from the server to update local optedIn state
  • The subscription values we send to the server are calculated by the helper method getSubscriptionEnabledAndStatus (here) so the model's own properties aren't directly sent.

Testing

Unit testing

No unit test added, can consider adding.

Manual testing

Android emulator API 33

  • tested scenarios of optIn() and optOut() with different permissions, new session, cold starts, and logging into different users

Android emulator API 30

  • tested scenarios of optIn() and optOut() with new session, cold starts, and logging into different users

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@nan-li nan-li force-pushed the fix/optIn_not_working branch 2 times, most recently from dbe29cd to 958191a Compare January 9, 2024 09:21
@nan-li nan-li force-pushed the fix/optIn_not_working branch from 958191a to 6319054 Compare January 10, 2024 00:21
@nan-li nan-li changed the base branch from dev_app/add_helper_buttons to user-model/main January 11, 2024 19:09
@nan-li nan-li changed the base branch from user-model/main to dev_app/add_helper_buttons January 11, 2024 19:09
@nan-li nan-li force-pushed the fix/optIn_not_working branch from 6319054 to e21d556 Compare January 11, 2024 19:16
@nan-li nan-li changed the base branch from dev_app/add_helper_buttons to user-model/main January 11, 2024 19:17
Existing Problem:
- If on a previous session, `optOut()` was called, we will hydrate the push subscription with the status of `UNSUBSCRIBE(-2)` on the next session.
- However, we lose the true device-level subscription status in doing so.
- Then, when `optIn()` is called, we were using `UNSUBSCRIBE(-2)` along with `optedIn` to calculate the data to send in the Update Subscription request.
- This resulted in incorrect values being sent and reports of `optIn()` method not working.

Solution:
- We can still hydrate the push subscription model's `optedIn` property if we see either UNSUBSCRIBE(-2) or DISABLED_FROM_REST_API_DEFAULT_REASON(-30).
- However, when the subscription model store is replacing all of the subscriptions in the refresh user operation, keep the existing push subscription `status`.
- This way, when `optIn()` is called again, we can use device-level status with the `optedIn` boolean to calculate values to send to the server.
@nan-li nan-li force-pushed the fix/optIn_not_working branch 2 times, most recently from 5f19168 to db99671 Compare January 11, 2024 22:57
@nan-li
Copy link
Contributor Author

nan-li commented Jan 11, 2024

Noting that our Test/build setup Android step is failing, but previous runs of this PR did succeed.
Merging while we are still investigating that fix.

@nan-li nan-li merged commit 5dfdec1 into user-model/main Jan 11, 2024
2 of 4 checks passed
@nan-li nan-li deleted the fix/optIn_not_working branch January 11, 2024 22:59
@jennantilla jennantilla mentioned this pull request Jan 11, 2024
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
Fix: Method `optIn()` not working after `optOut()` has been called
jinliu9508 pushed a commit that referenced this pull request Jan 31, 2024
Fix: Method `optIn()` not working after `optOut()` has been called
jinliu9508 pushed a commit that referenced this pull request Feb 6, 2024
Fix: Method `optIn()` not working after `optOut()` has been called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants