@@ -61,10 +61,32 @@ class OSUserExecutor {
6161 }
6262 }
6363
64- static func parseCreateUserResponse( _ response: [ AnyHashable : Any ] ) {
65- let subscriptionObject = parseSubscriptionObjectResponse ( response)
66- let identityObject = parseIdentityObjectResponse ( response)
67- let propertiesObject = parsePropertiesObjectResponse ( response)
64+ static func parseCreateUserResponse( response: [ AnyHashable : Any ] , request: OSRequestCreateUser ) {
65+ // On success, check if the current user is the same as the one in the request
66+ // If user has changed, don't hydrate, except for push subscription
67+ let modelInStore = OneSignalUserManagerImpl . sharedInstance. identityModelStore. getModel ( key: OS_IDENTITY_MODEL_KEY)
68+
69+ guard modelInStore? . modelId == request. identityModel. modelId else {
70+ return
71+ }
72+ if let identityObject = parseIdentityObjectResponse ( response) {
73+ OneSignalUserManagerImpl . sharedInstance. user. identityModel. hydrate ( identityObject)
74+ }
75+ if let subscriptionObject = parseSubscriptionObjectResponse ( response) {
76+ for subModel in subscriptionObject {
77+ if let subType = subModel [ " type " ] as? String {
78+ if subType == " iOSPush " {
79+ OneSignalUserManagerImpl . sharedInstance. user. pushSubscriptionModel. hydrate ( subModel)
80+ if let subId = subModel [ " id " ] as? String {
81+ OSNotificationsManager . setPushSubscriptionId ( subId)
82+ }
83+ }
84+ }
85+ }
86+ }
87+ if let propertiesObject = parsePropertiesObjectResponse ( response) {
88+ OneSignalUserManagerImpl . sharedInstance. user. propertiesModel. hydrate ( propertiesObject)
89+ }
6890 }
6991
7092 static func parseSubscriptionObjectResponse( _ response: [ AnyHashable : Any ] ? ) -> [ [ String : Any ] ] ? {
@@ -88,34 +110,9 @@ class OSUserExecutor {
88110 return
89111 }
90112 OneSignalClient . shared ( ) . execute ( request) { response in
91- // On success, check if the current user is the same as the one in the request
92- // If user has changed, don't hydrate, except for push subscription
93- let modelInStore = OneSignalUserManagerImpl . sharedInstance. identityModelStore. getModel ( key: OS_IDENTITY_MODEL_KEY)
94-
95- guard modelInStore? . modelId == request. identityModel. modelId else {
96- return
97- }
98- if let identityObject = parseIdentityObjectResponse ( response) {
99- OneSignalUserManagerImpl . sharedInstance. user. identityModel. hydrate ( identityObject)
100- }
101- if let subscriptionObject = parseSubscriptionObjectResponse ( response) {
102- for subModel in subscriptionObject {
103- if let subType = subModel [ " type " ] as? String {
104- if subType == " iOSPush " {
105- OneSignalUserManagerImpl . sharedInstance. user. pushSubscriptionModel. hydrate ( subModel)
106- if let subId = subModel [ " id " ] as? String {
107- OSNotificationsManager . setPushSubscriptionId ( subId)
108- }
109- }
110- }
111- }
112- }
113- if let propertiesObject = parsePropertiesObjectResponse ( response) {
114- OneSignalUserManagerImpl . sharedInstance. user. propertiesModel. hydrate ( propertiesObject)
113+ if let response = response {
114+ parseCreateUserResponse ( response: response, request: request)
115115 }
116-
117- // hydrate identity, properties, subscriptions
118-
119116 executePendingRequests ( )
120117 } onFailure: { error in
121118 print ( " ECM test + \( error. debugDescription) " )
0 commit comments