Closed nan-li closed 6 months ago
Followup PR https://github.com/OneSignal/OneSignal-iOS-SDK/pull/1430 testing user switching is also testing these changes.
Note CodeQL is broken after push to start live activities merged to main, its autobuild action no longer works.
Description
One Line Summary
Fix processing of Identify User response when the user has changed since, so that pending updates will still be sent and transfer subscription happens only in correct situations.
Details
Note that this bug only manifests if multiple logins to different users are called one after another, or the requests are not able to succeed (server is down, or there is no internet connection during which time multiple logins are called). This PR tests and addresses those scenarios.
Motivation
Consider the scenario Anon -> Login User A (Identify User) -> Login User B (Create User)
Anon -> Login User A (Identify User) -> Login User B (Create User) -> Transfer Subscription to User A
This PR also fixes the bugs mentioned under Manual Testing section for https://github.com/OneSignal/OneSignal-iOS-SDK/pull/1418
User State Change Observer
⚠️ The User Observer was never triggered for the 409'd middle user. That is still the case after this PR, as we never hydrate its
onesignal_id
.Scope
Testing
Unit testing
Manual testing
Tested on iPhone 13 with iOS 17.4
✅ Scenario 1:
<some_existing_euid>
by way of external_id[OneSignal initialize: withLaunchOptions:launchOptions];
[OneSignal login:]; // returns 409
[OneSignal.User addTagWithKey:@"a" value:@"a"];
[OneSignal login:];
✅ Scenario 3:
[OneSignal initialize: withLaunchOptions:launchOptions];
[OneSignal.User addTagWithKey:@"a" value:@"a"]; [OneSignal.User setLanguage:@"fr"]; [OneSignal.User addAliasWithLabel:@"a" id:@"a"]; [OneSignal.User addEmail:@"a@example.com"];
[OneSignal login:];
[OneSignal.User addAliasWithLabel:@"existing" id:@"existing"];
[OneSignal.User addTagWithKey:@"existing" value:@"existing"];
[OneSignal.User setLanguage:@"zh"];
[OneSignal.User addEmail:@"existing@example.com"];
// Don't logout or login to another user
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is