Skip to content

Commit ff61744

Browse files
committed
fix bug: need to update identity model even when user changed
* Noticed a bug if someone calls `login` right away upon SDK init. * The initial anonymous create user request is sent, then the model in the stores are replaced with new models when the `login` is called (which will result in an Identify User request). This request is waiting on the onesignal_id of the previous user in order to be sent. * However, when the first create user request returns, we see that the user has changed, so we weren't hydrating anything. * As a result, the identify user request could never be sent. * Instead, always hydrate the identity model in the request first. Then we can hydrate the models in the stores, if the user is the same.
1 parent 8650820 commit ff61744

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class OSUserExecutor {
6666
Used to parse Create User and Fetch User responses. The `originalPushToken` is the push token when the request was created, which may be different from the push token currently in the SDK. For example, when the request was created, there may be no push token yet, but soon after, the SDK receives a push token. This is used to determine whether or not to hydrate the push subscription.
6767
*/
6868
static func parseFetchUserResponse(response: [AnyHashable: Any], identityModel: OSIdentityModel, originalPushToken: String?) {
69+
70+
// If this was a create user, it hydrates the onesignal_id of the request's identityModel
71+
// The model in the store may be different, and it may be waiting on the onesignal_id of this previous model
72+
if let identityObject = parseIdentityObjectResponse(response) {
73+
identityModel.hydrate(identityObject)
74+
}
75+
6976
// On success, check if the current user is the same as the one in the request
7077
// If user has changed, don't hydrate, except for push subscription
7178
let modelInStore = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(key: OS_IDENTITY_MODEL_KEY)

0 commit comments

Comments
 (0)