-
Notifications
You must be signed in to change notification settings - Fork 369
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 onSuccess
callback invoking for setting email or SMS
#1555
Conversation
96fde2f
to
e4fbe24
Compare
One test fail, looks unrelated but rerunning tests to confirm:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @emawby, @Jeasmine, and @nan-li)
OneSignalSDK/onesignal/src/main/java/com/onesignal/UserStatePushSynchronizer.java, line 232 at r1 (raw file):
@Override protected void onSuccessfulSync(JSONObject jsonFields) { if (jsonFields.has(EMAIL_KEY))
Love it when just deleting code fixes the issue 😄
OneSignalSDK/onesignal/src/main/java/com/onesignal/UserStatePushSynchronizer.java, line 233 at r1 (raw file):
protected void onSuccessfulSync(JSONObject jsonFields) { // Previously, the onSuccess callbacks for setEmail and setSMSNumber were triggered here if applicable. // However, this is too early to call these callbacks as those players may not be created or set yet in the SDK.
I would add a comment that UserStateSecondaryChannelSynchronizer
already fires the successful callback somehwhere in your comment here.
OneSignalSDK/unittest/src/test/java/com/test/onesignal/SynchronizerIntegrationTests.java, line 2084 at r1 (raw file):
// 5. Make sure lastExternalUserIdResponse has push and email with success : true // The order of the JSONObject is email first then push
The order of JSON keys isn't reliable way to test something, as the order isn't meaningful in JSON.
Instead of checking success we should be checking we have a correct value for something. This could be we sent the correct data in the REST API calls or the order of the callbacks fired correctly.
- Don't call the `onSuccess` callbacks for `setEmail` and `setSMSNumber` within the push synchronizer. - Previously, this callback may be triggered before the email or sms player is actually created or saved to the SDK through calls to `saveChannelId` (ie `saveEmailId` or `saveSMSId`) - The UserStateEmailSynchronizer or UserStateSMSSynchronizer will call these `onSuccess` callbacks later. - For the unhappy path for the failure callbacks, leave that as it is.
- These tests call setExternalUserId in the onSuccess callback of setEmail or setSMSNumber - By the time this onSuccess callback is invoked, setting the EUID should update the email player or sms player - Implicitly tests that the email or sms player is set successfully by the time their onSuccess callback is invoked - Previously, by the time this callback is invoked, the channel IDs for email or sms has not been set yet, and then calling setExternalUserId does not update those players.
e4fbe24
to
1223b0d
Compare
I updated the unit tests to check for the external ID request being sent for email and SMS. Previously, the request was only being sent for the push player. I opted for this instead of looking at the order of callbacks firing because that seems more involved to implement, as well as being able to actually pass without the changes in this PR (the order of callbacks fired wouldn't actually be affected). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @emawby and @Jeasmine)
Description
One Line Summary
Don't call the
onSuccess
callback for setting email and SMS too early, which can be before those players have been successfully created and set their channels in the SDK.Details
Motivation
These changes are investigated and made after a customer report needing to set external user ID after setting email and SMS, and wanting all the players to be updated with the EUID. Time has to pass after a call to
setEmail
orsetSMSNumber
, beforesetExternalUserId
can successfully update all players.To work around this, the customer was recommended to make a call to
setExternalUserId
within theonSuccess
callback ofsetEmail
orsetSMSNumber
. However, this did not work as intended either since at the time the callback is invoked, the email or SMS player may not have been created or had the channel ID saved to the SDK, and setting external user ID only makes the request for the push channel, as a result.Implementation Details
Previously,
UserStatePushSynchronizer. onSuccessfulSync()
would fire the email and SMS successful callbacks if the request sent has "sms_number" or "email" in it, but this is too early to fire those since this is only for the push player sync. The /players endpoint is then called later for the SMS or email player. In the dashboard, the email or SMS player is created a few seconds after the push player.Instead, let the
UserStateEmailSynchronizer
andUserStateSMSSynchronizer
call these successful callbacks in their ownonSuccessfulSync
, which will happen after the requests for the email player or SMS player is successful.Did not make any changes to the failure callback.
Scope
This change affects the invoking of the successful callbacks and doesn't affect other OneSignal logic around setting email or SMS.
Testing
Unit testing
Added two test handlers that call
setExternalUserId
in the callback:Added two unit tests to reproduce the customer's reported behavior (these failed before the changes in this PR)
Manual testing
App build with Android Studio 2020.3 using the OneSignal example app on a Pixel 5 API 30:
I made multiple calls to combinations of
setEmail
andsetSMS
with a callback set. This callback makes a call tosetExternalUserId
-> and then checked the callback is invoked correctly every time, and that all the players are updated with the EUID.Affected code checklist
Checklist
Overview
PR
Testing
Final pass
This change is