Skip to content

Commit a790ad6

Browse files
committed
replace user data with the fetch user response
* Motivation: Previously, when we hydrate after fetch user, we are adding to and updating our models, but not doing any removals if local properties are not in the response. * Instead, replace the user's data with the response, but keep the same identity and property model since it is the same user.
1 parent 61ad43c commit a790ad6

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class OSIdentityModel: OSModel {
6565
self.aliases = aliases
6666
}
6767

68+
/**
69+
Called to clear the model's data in preparation for hydration via a fetch user call.
70+
*/
71+
func clearData() {
72+
self.aliases = [:]
73+
}
74+
6875
// MARK: - Alias Methods
6976

7077
func addAliases(_ aliases: [String: String]) {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ class OSPropertiesModel: OSModel {
9292
// ... and more
9393
}
9494

95+
/**
96+
Called to clear the model's data in preparation for hydration via a fetch user call.
97+
*/
98+
func clearData() {
99+
// TODO: What about language, lat, long?
100+
self.tags = [:]
101+
}
102+
95103
// MARK: - Tag Methods
96104

97105
func addTags(_ tags: [String: String]) {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ class OSUserExecutor {
269269
}
270270

271271
OneSignalClient.shared().execute(request) { response in
272+
// Clear local data in preparation for hydration
273+
OneSignalUserManagerImpl.sharedInstance.clearUserData()
274+
272275
if let response = response {
273276
parseFetchUserResponse(response: response, identityModel: request.identityModel, originalPushToken: OneSignalUserManagerImpl.sharedInstance.token)
274277
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
283283
)
284284
}
285285

286+
/**
287+
Clears the existing user's data in preparation for hydration via a fetch user call.
288+
*/
289+
func clearUserData() {
290+
// Identity and property models should still be the same instances, but with data cleared
291+
_user?.identityModel.clearData()
292+
_user?.propertiesModel.clearData()
293+
294+
// Subscription model store should be cleared completely
295+
OneSignalUserManagerImpl.sharedInstance.subscriptionModelStore.clearModelsFromStore()
296+
}
297+
286298
private func _login(externalId: String?, token: String?) -> OSUserInternal {
287299
guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else {
288300
return _mockUser

0 commit comments

Comments
 (0)