Skip to content

Commit a0df196

Browse files
committed
Uncaching in executors will use the Identity Model Repo
* When Requests are uncached in the executors, hook them up to the same identity model instance via the Identity Model Repo
1 parent f9cf364 commit a0df196

File tree

4 files changed

+87
-75
lines changed

4 files changed

+87
-75
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSIdentityOperationExecutor.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
4040
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
4141
// Hook each uncached Delta to the model in the store
4242
for (index, delta) in deltaQueue.enumerated().reversed() {
43-
if let modelInStore = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: delta.model.modelId) {
44-
// The model exists in the store, set it to be the Delta's model
43+
if let modelInStore = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.model.modelId) {
44+
// The model exists in the repo, set it to be the Delta's model
4545
delta.model = modelInStore
4646
} else {
4747
// The model does not exist, drop this Delta
48+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor.init dropped \(delta)")
4849
deltaQueue.remove(at: index)
4950
}
5051
}
@@ -59,14 +60,15 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
5960
if var addRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestAddAliases] {
6061
// Hook each uncached Request to the model in the store
6162
for (index, request) in addRequestQueue.enumerated().reversed() {
62-
if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: request.identityModel.modelId) {
63-
// 1. The model exists in the store, so set it to be the Request's models
63+
if let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(request.identityModel.modelId) {
64+
// 1. The model exists in the repo, so set it to be the Request's models
6465
request.identityModel = identityModel
65-
} else if let identityModel = OSUserExecutor.identityModels[request.identityModel.modelId] {
66-
// 2. The model exists in the user executor
67-
request.identityModel = identityModel
68-
} else if !request.prepareForExecution() {
69-
// 3. The models do not exist AND this request cannot be sent, drop this Request
66+
} else if request.prepareForExecution() {
67+
// 2. The request can be sent, add the model to the repo
68+
OneSignalUserManagerImpl.sharedInstance.addIdentityModelToRepo(request.identityModel)
69+
} else {
70+
// 3. The model do not exist AND this request cannot be sent, drop this Request
71+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor.init dropped \(request)")
7072
addRequestQueue.remove(at: index)
7173
}
7274
}
@@ -79,14 +81,15 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
7981
if var removeRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_IDENTITY_EXECUTOR_REMOVE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestRemoveAlias] {
8082
// Hook each uncached Request to the model in the store
8183
for (index, request) in removeRequestQueue.enumerated().reversed() {
82-
if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: request.identityModel.modelId) {
83-
// 1. The model exists in the store, so set it to be the Request's model
84+
if let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(request.identityModel.modelId) {
85+
// 1. The model exists in the repo, so set it to be the Request's model
8486
request.identityModel = identityModel
85-
} else if let identityModel = OSUserExecutor.identityModels[request.identityModel.modelId] {
86-
// 2. The model exists in the user executor
87-
request.identityModel = identityModel
88-
} else if !request.prepareForExecution() {
87+
} else if request.prepareForExecution() {
88+
// 2. The request can be sent, add the model to the repo
89+
OneSignalUserManagerImpl.sharedInstance.addIdentityModelToRepo(request.identityModel)
90+
} else {
8991
// 3. The model does not exist AND this request cannot be sent, drop this Request
92+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSIdentityOperationExecutor.init dropped \(request)")
9093
removeRequestQueue.remove(at: index)
9194
}
9295
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSPropertyOperationExecutor.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
4040
// Read unfinished deltas from cache, if any...
4141
// Note that we should only have deltas for the current user as old ones are flushed..
4242
if var deltaQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_DELTA_QUEUE_KEY, defaultValue: []) as? [OSDelta] {
43-
// Hook each uncached Delta to the model in the store
4443
for (index, delta) in deltaQueue.enumerated().reversed() {
45-
if let modelInStore = OneSignalUserManagerImpl.sharedInstance.propertiesModelStore.getModel(modelId: delta.model.modelId) {
46-
// 1. The model exists in the properties model store, set it to be the Delta's model
47-
delta.model = modelInStore
48-
} else {
49-
// 2. The model does not exist, drop this Delta
44+
if OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.identityModelId) == nil {
45+
// The identity model does not exist, drop this Delta
5046
OneSignalLog.onesignalLog(.LL_WARN, message: "OSPropertyOperationExecutor.init dropped: \(delta)")
5147
deltaQueue.remove(at: index)
5248
}
@@ -61,13 +57,13 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
6157
if var updateRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_PROPERTIES_EXECUTOR_UPDATE_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestUpdateProperties] {
6258
// Hook each uncached Request to the model in the store
6359
for (index, request) in updateRequestQueue.enumerated().reversed() {
64-
if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: request.identityModel.modelId) {
65-
// 1. The identity model exist in the store, set it to be the Request's models
66-
request.identityModel = identityModel
67-
} else if let identityModel = OSUserExecutor.identityModels[request.identityModel.modelId] {
68-
// 2. The model exists in the user executor
60+
if let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(request.identityModel.modelId) {
61+
// 1. The identity model exist in the repo, set it to be the Request's model
6962
request.identityModel = identityModel
70-
} else if !request.prepareForExecution() {
63+
} else if request.prepareForExecution() {
64+
// 2. The request can be sent, add the model to the repo
65+
OneSignalUserManagerImpl.sharedInstance.addIdentityModelToRepo(request.identityModel)
66+
} else {
7167
// 3. The identitymodel do not exist AND this request cannot be sent, drop this Request
7268
OneSignalLog.onesignalLog(.LL_WARN, message: "OSPropertyOperationExecutor.init dropped: \(request)")
7369
updateRequestQueue.remove(at: index)
@@ -99,11 +95,18 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
9995
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSPropertyOperationExecutor processDeltaQueue with queue: \(self.deltaQueue)")
10096
}
10197
for delta in self.deltaQueue {
98+
guard let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.identityModelId)
99+
else {
100+
// drop this delta
101+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSPropertyOperationExecutor.processDeltaQueue dropped: \(delta)")
102+
continue
103+
}
104+
102105
let request = OSRequestUpdateProperties(
103106
properties: [delta.property: delta.value],
104107
deltas: nil,
105108
refreshDeviceMetadata: false, // Sort this out.
106-
identityModel: OneSignalUserManagerImpl.sharedInstance.user.identityModel // TODO: Make sure this is ok
109+
identityModel: identityModel
107110
)
108111
self.updateRequestQueue.append(request)
109112
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSSubscriptionOperationExecutor.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
4747
delta.model = modelInStore
4848
} else {
4949
// The model does not exist, drop this Delta
50+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor.init dropped \(delta)")
5051
deltaQueue.remove(at: index)
5152
}
5253
}
@@ -75,14 +76,15 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
7576
subscriptionModels[request.subscriptionModel.modelId] = request.subscriptionModel
7677
}
7778
// 2. Hook up the identity model
78-
if let identityModel = OneSignalUserManagerImpl.sharedInstance.identityModelStore.getModel(modelId: request.identityModel.modelId) {
79-
// a. The model exist in the store
79+
if let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(request.identityModel.modelId) {
80+
// a. The model exist in the repo
8081
request.identityModel = identityModel
81-
} else if let identityModel = OSUserExecutor.identityModels[request.identityModel.modelId] {
82-
// b. The model exist in the user executor
83-
request.identityModel = identityModel
84-
} else if !request.prepareForExecution() {
85-
// The model do not exist AND this request cannot be sent, drop this Request
82+
} else if request.prepareForExecution() {
83+
// b. The request can be sent, add the model to the repo
84+
OneSignalUserManagerImpl.sharedInstance.addIdentityModelToRepo(request.identityModel)
85+
} else {
86+
// c. The model do not exist AND this request cannot be sent, drop this Request
87+
OneSignalLog.onesignalLog(.LL_WARN, message: "OSSubscriptionOperationExecutor.init dropped: \(request)")
8688
continue
8789
}
8890
requestQueue.append(request)
@@ -104,6 +106,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
104106
request.subscriptionModel = subscriptionModel
105107
} else if !request.prepareForExecution() {
106108
// 3. The model does not exist AND this request cannot be sent, drop this Request
109+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor.init dropped \(request)")
107110
removeRequestQueue.remove(at: index)
108111
}
109112
}
@@ -124,6 +127,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
124127
request.subscriptionModel = subscriptionModel
125128
} else if !request.prepareForExecution() {
126129
// 3. The models do not exist AND this request cannot be sent, drop this Request
130+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor.init dropped \(request)")
127131
updateRequestQueue.remove(at: index)
128132
}
129133
}
@@ -161,29 +165,34 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
161165
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OSSubscriptionOperationExecutor processDeltaQueue with queue: \(deltaQueue)")
162166
}
163167
for delta in deltaQueue {
164-
guard let model = delta.model as? OSSubscriptionModel else {
165-
// Log error
168+
guard let subModel = delta.model as? OSSubscriptionModel
169+
else {
170+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor.processDeltaQueue dropped \(delta)")
166171
continue
167172
}
168173

169174
switch delta.name {
170175
case OS_ADD_SUBSCRIPTION_DELTA:
171-
let request = OSRequestCreateSubscription(
172-
subscriptionModel: model,
173-
identityModel: OneSignalUserManagerImpl.sharedInstance.user.identityModel // TODO: Make sure this is ok
174-
)
175-
addRequestQueue.append(request)
176-
176+
// Only create the request if the identity model exists
177+
if let identityModel = OneSignalUserManagerImpl.sharedInstance.getIdentityModel(delta.identityModelId) {
178+
let request = OSRequestCreateSubscription(
179+
subscriptionModel: subModel,
180+
identityModel: identityModel
181+
)
182+
addRequestQueue.append(request)
183+
} else {
184+
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSSubscriptionOperationExecutor.processDeltaQueue dropped \(delta)")
185+
}
177186
case OS_REMOVE_SUBSCRIPTION_DELTA:
178187
let request = OSRequestDeleteSubscription(
179-
subscriptionModel: model
188+
subscriptionModel: subModel
180189
)
181190
removeRequestQueue.append(request)
182191

183192
case OS_UPDATE_SUBSCRIPTION_DELTA:
184193
let request = OSRequestUpdateSubscription(
185194
subscriptionObject: [delta.property: delta.value],
186-
subscriptionModel: model
195+
subscriptionModel: subModel
187196
)
188197
updateRequestQueue.append(request)
189198

0 commit comments

Comments
 (0)