@@ -140,15 +140,19 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
140140 return pushSubscriptionStateChangesObserver
141141 }
142142
143- // has Identity, Properties, and Subscription Model Stores
143+ // has Identity, Properties, Subscription, and Push Subscription Model Stores
144144 let identityModelStore = OSModelStore < OSIdentityModel > ( changeSubscription: OSEventProducer ( ) , storeKey: OS_IDENTITY_MODEL_STORE_KEY)
145145 let propertiesModelStore = OSModelStore < OSPropertiesModel > ( changeSubscription: OSEventProducer ( ) , storeKey: OS_PROPERTIES_MODEL_STORE_KEY)
146+ // Holds email and sms subscription models
146147 let subscriptionModelStore = OSModelStore < OSSubscriptionModel > ( changeSubscription: OSEventProducer ( ) , storeKey: OS_SUBSCRIPTION_MODEL_STORE_KEY)
148+ // Holds a single push subscription model
149+ let pushSubscriptionModelStore = OSModelStore < OSSubscriptionModel > ( changeSubscription: OSEventProducer ( ) , storeKey: OS_PUSH_SUBSCRIPTION_MODEL_STORE_KEY)
147150
148151 // These must be initialized in init()
149152 let identityModelStoreListener : OSIdentityModelStoreListener
150153 let propertiesModelStoreListener : OSPropertiesModelStoreListener
151154 let subscriptionModelStoreListener : OSSubscriptionModelStoreListener
155+ let pushSubscriptionModelStoreListener : OSSubscriptionModelStoreListener
152156
153157 // has Property and Identity operation executors
154158 let propertyExecutor = OSPropertyOperationExecutor ( )
@@ -159,6 +163,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
159163 self . identityModelStoreListener = OSIdentityModelStoreListener ( store: identityModelStore)
160164 self . propertiesModelStoreListener = OSPropertiesModelStoreListener ( store: propertiesModelStore)
161165 self . subscriptionModelStoreListener = OSSubscriptionModelStoreListener ( store: subscriptionModelStore)
166+ self . pushSubscriptionModelStoreListener = OSSubscriptionModelStoreListener ( store: pushSubscriptionModelStore)
162167 }
163168
164169 // TODO: This method is called A LOT, check if all calls are needed.
@@ -180,7 +185,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
180185 // Corrupted state if any of these models exist without the others
181186 if let identityModel = identityModelStore. getModels ( ) [ OS_IDENTITY_MODEL_KEY] ,
182187 let propertiesModel = propertiesModelStore. getModels ( ) [ OS_PROPERTIES_MODEL_KEY] ,
183- let pushSubscription = subscriptionModelStore . getModels ( ) [ OS_PUSH_SUBSCRIPTION_MODEL_KEY] {
188+ let pushSubscription = pushSubscriptionModelStore . getModels ( ) [ OS_PUSH_SUBSCRIPTION_MODEL_KEY] {
184189 _user = OSUserInternalImpl ( identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscription)
185190 }
186191
@@ -191,6 +196,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
191196 identityModelStoreListener. start ( )
192197 propertiesModelStoreListener. start ( )
193198 subscriptionModelStoreListener. start ( )
199+ pushSubscriptionModelStoreListener. start ( )
194200
195201 // Setup the executors
196202 OSUserExecutor . start ( )
@@ -226,7 +232,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
226232 }
227233 }
228234
229- let pushSubscriptionModel = subscriptionModelStore . getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)
235+ let pushSubscriptionModel = pushSubscriptionModelStore . getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)
230236 prepareForNewUser ( )
231237
232238 let newUser = setNewInternalUser ( externalId: externalId, pushSubscriptionModel: pushSubscriptionModel)
@@ -251,7 +257,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
251257 let identityModelToIdentify = currentUser. identityModel
252258
253259 // Immediately drop the old user and set a new user in the SDK
254- let pushSubscriptionModel = subscriptionModelStore . getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)
260+ let pushSubscriptionModel = pushSubscriptionModelStore . getModel ( key: OS_PUSH_SUBSCRIPTION_MODEL_KEY)
255261 prepareForNewUser ( )
256262 let newUser = setNewInternalUser ( externalId: externalId, pushSubscriptionModel: pushSubscriptionModel)
257263
@@ -313,7 +319,7 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
313319 NotificationCenter . default. post ( name: Notification . Name ( OS_ON_USER_WILL_CHANGE) , object: nil )
314320
315321 // This store MUST be cleared, Identity and Properties do not.
316- subscriptionModelStore. clearModelsFromStore ( modelToKeepId : OS_PUSH_SUBSCRIPTION_MODEL_KEY )
322+ subscriptionModelStore. clearModelsFromStore ( )
317323 }
318324
319325 /**
@@ -338,8 +344,8 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
338344 let pushSubscription = pushSubscriptionModel ?? createDefaultPushSubscription ( )
339345
340346 // Add pushSubscription to store if not present
341- if ( !subscriptionModelStore . getModels ( ) . keys. contains ( OS_PUSH_SUBSCRIPTION_MODEL_KEY) ) {
342- subscriptionModelStore . add ( id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription)
347+ if ( !pushSubscriptionModelStore . getModels ( ) . keys. contains ( OS_PUSH_SUBSCRIPTION_MODEL_KEY) ) {
348+ pushSubscriptionModelStore . add ( id: OS_PUSH_SUBSCRIPTION_MODEL_KEY, model: pushSubscription)
343349 }
344350
345351 _user = OSUserInternalImpl ( identityModel: identityModel, propertiesModel: propertiesModel, pushSubscriptionModel: pushSubscription)
0 commit comments