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] optIn() not prompting if called before push subscription is created on backend #2037

Merged
merged 2 commits into from
Mar 29, 2024

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Mar 28, 2024

Description

One Line Summary

Fix optIn() not prompting if called before push subscription is created on backend .

Details

Motivation

It's common for developers to call OneSignal.User.pushSubscription.optIn() and it should prompt even if the device is offline or has connection issues.

Scope

Effects internal push subscription property change events.

Testing

Unit testing

Created a new unit test to cover this case.

  • Ensured it failed before my change, then passes after my change.

Manual testing

Tested on a real Samsung S21 with Android 14 (security patch level Feb 1, 2024). Clean installed example app while the device was in airplane mode, ensuring calling optIn() now prompts. Also tested adding an email and sms when the device was offline and then when I turn back on network connect it successfully created all the subscriptions as expected.

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
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • 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.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

It's weird that the push subscription id was compared to the model id the whole time. I guess the subscription id is updated to its model's id at some point so we didn't see this happening all the time.

@@ -157,7 +157,10 @@ internal class SubscriptionManager(
args: ModelChangedArgs,
tag: String,
) {
val subscription = subscriptions.collection.firstOrNull { it.id == args.model.id }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, to use id as a getter, it would have to compare it.model.id == args.model.id

Copy link
Member Author

@jkasten2 jkasten2 Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, since the Susbcription.id returns "" if it starts with local- it was not finding it, using model always gives us the id value

@jkasten2 jkasten2 force-pushed the fix/limit_some_rest_calls_to_foreground branch from 94fe2a8 to 3b85296 Compare March 28, 2024 23:05
@jkasten2 jkasten2 force-pushed the fix/optIn-not-prompting-if-called-before-sub-created branch from 3c10617 to 57e8025 Compare March 28, 2024 23:09
This is a common case where updates (such as optedIn) should
still propagate even if we haven't sent the POST /users create
call yet. Motivation for this test was a bug was discovered
where calling OneSignal.User.pushSubscription.optIn() was not
prompting for notification permission if it was called before
the create User network call finished.
This is a common case where updates (such as optedIn) should
still propagate even if we haven't sent the POST /users create
call yet. Motivation for this test was a bug was discovered
where calling OneSignal.User.pushSubscription.optIn() was not
prompting for notification permission if it was called before
the create User network call finished.
@jkasten2 jkasten2 force-pushed the fix/optIn-not-prompting-if-called-before-sub-created branch from 57e8025 to a92bcee Compare March 28, 2024 23:22
Base automatically changed from fix/limit_some_rest_calls_to_foreground to main March 29, 2024 17:27
@jkasten2 jkasten2 merged commit e58090b into main Mar 29, 2024
2 checks passed
@jkasten2 jkasten2 deleted the fix/optIn-not-prompting-if-called-before-sub-created branch March 29, 2024 17:30
@jkasten2 jkasten2 mentioned this pull request Mar 29, 2024
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.

4 participants