-
Notifications
You must be signed in to change notification settings - Fork 263
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
[Feat] Use only OneSignal ID for requests #1464
Conversation
* The SDK will longer make Transfer Subscription calls now that requests via external ID are removed, and all requests are expected to use OneSignal ID. * The Transfer Subscription request was previously used in an Identify User 409 conflict to transfer the push subscription to that External ID. * Instead these will translate to Create User which will contain the External ID and the push subscription in the payload. * Deprecate this request class but keep a skeleton in order to uncache them
* The initializer for the Request has optional PropertiesModel and optional SubscriptionModel * This use case will send an external ID in the payload to retrieve the OneSignal ID.
* After a successful `CreateUser` or `IdentifyUser` without conflict, fetch the user for hydration via OneSignal ID instead of External ID.
* On Identify User 409 conflict response, no longer fetch user by External ID nor transfer subscription. * Instead, make a call to CreateUser with the push subscription in the payload. * If the user has changed since then, make a CreateUser call with just the Identity Model to hydrate the OneSignal ID for any pending updates that need to be sent for the past user. * Nit: remove an extraneous error log. The SDK already logs that it handles the 409 response. And the Client will already log this error as well.
* On Identify User successful, the SDK was only hydrating the OneSignal ID for past users (not the current user) and fetching the current user (which means OneSignal ID will be missing locally until that response) * Let's hydrate both OneSignal ID and External ID for all cases so that the local state can be up to date (instead of relying on the Fetch User to hydrate back the OneSignal and External IDs)
All user-update related requests will also only use OneSignal ID in the path * OSRequestUpdateProperties * OSRequestIdentifyUser * OSRequestAddAliases * OSRequestRemoveAlias * OSRequestCreateSubscription
* Now that requests will always use OneSignal ID, remove the concept of a primary alias for an Identity Model (ie: OneSignal ID or External ID)
* No more transfer subscription * All requests using EUID previously now use OSID * After a 409 conflict, there can be a follow-up CreateUser request (whose purpose is to retrieve the OneSignal ID) and a Fetch User request
*/ | ||
static func createUser(identityModel: OSIdentityModel) { | ||
guard identityModel.externalId != nil else { | ||
OneSignalLog.onesignalLog(.LL_ERROR, message: "createUser(identityModel) called with missing external ID") |
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.
If we hit this case what happens? Will we try again in the same session?
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.
The purpose of this version of ceateUser()
is to get an OSID for an EUID. The EUID must exist because the only usage of this method is after an Identify User 409 conflict, in which case we would have the EUID. The guard and error log is more for noticing that we do something wrong such as using this method inappropriately down the line.
Thinking about this again, it may be clearer to make EUID a parameter instead of it being implicit.
No, it won't ever retry, which means any pending updates for a previous user who experienced this particular flow will get updates dropped.
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.
Ya it should probably require it as a param. Would it retry next session?
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.
I edited my response after to talk about retrying. This call would be made if the user has changed since, so this would be for a previous user. It won't retry since no EUID, no way to get its OSID. That means if there are pending requests for this previous user, they will effectively be dropped.
* The 2nd use of create user is passing an external ID to hydrate the OSID. Let's make it explicit by using the alias as a parameter and creating an additional initializer for the Create User Request. * Here I also removed encoding and decoding of the `path` property. This should not be decoded as it may not be encoded yet. The `prepareForExecution` will always generate the path. Other requests follow this pattern already.
* After a Create User is successful, we should fetch the user for hydration. There was a bug introduced in an earlier commit that checked the request payload for the OSID, when it should be retrieved from the server response
/** | ||
Set either `onesignal_id` or `external_id`, representing the alias that will be used in requests. | ||
*/ | ||
var primaryAliasLabel: OSDefaultAlias = .onesignal_id |
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.
We will probably want to use this concept for JWT, since we will make requests with external_id
when it is enabled. I am still ok with removing this code in this PR to if you want to, just making a note in-case this didn't come up.
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.
@jkasten2 I thought about JWT before removing this. The issue with the primaryAliasLabel
as it exists here is that every Identity Model needs to manage it. Therefore, when the SDK first detects JWT is on, it needs to go and update every Identity Model. Instead, some flag can be centralized.
The reason this primaryAliasLabel
existed on the Identity Models is that some models can use external ID instead of onesignal ID.
Description
One Line Summary
Use only OneSignal ID for requests, no longer using any External ID for requests.
Details
Motivation
Move away from using External ID in request URLs, only using OneSignal ID.
Scope
Making requests
Testing
Unit testing
Manual testing
Device: iPhone 13 on iOS
17.5.1
Identify User with success (external ID applied successfully)
Identify User with 409 conflict
SDK Upgrade: There is a cached Transfer Subscription for the current user
main
by login to an existing EUIDSDK Upgrade: There is a cached Transfer Subscription for a previous user
main
by login to an existing EUIDuserA
userB
, which enqueues a CreateUser requestuserB
.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is