Skip to content

Commit 0d033d4

Browse files
committed
Allow the operation repo to be paused
* If a createUser fails, let's pause the operation repo. We will still poll, but we won't flush it is paused. * After a create user request is uncached, update the `originalPushToken` property to be the push token associated with this request. Because, we update the push subscription before sending this request.
1 parent 7d7f13d commit 0d033d4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSOperationRepo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class OSOperationRepo: NSObject {
4343

4444
// TODO: This should come from a config, plist, method, remote params
4545
var pollIntervalSeconds = 5
46+
public var paused = false
4647

4748
/**
4849
Initilize this Operation Repo. Read from the cache. Executors may not be available by this time.
@@ -108,6 +109,11 @@ public class OSOperationRepo: NSObject {
108109
}
109110

110111
@objc public func flushDeltaQueue() {
112+
guard !paused else {
113+
OneSignalLog.onesignalLog(.LL_DEBUG, message: "OSOperationRepo not flushing queue due to being paused")
114+
return
115+
}
116+
111117
guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else {
112118
return
113119
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,21 @@ class OSUserExecutor {
328328
executePendingRequests()
329329
}
330330
}
331+
OSOperationRepo.sharedInstance.paused = false
331332
} onFailure: { error in
332333
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSUserExecutor create user request failed with error: \(error.debugDescription)")
333334
if let nsError = error as? NSError {
334335
let responseType = OSNetworkingUtils.getResponseStatusType(nsError.code)
335336
if responseType != .retryable {
336-
// Fail, no retry, remove from cache and queue
337-
// TODO: This leaves the SDK in a bad state, revisit why this can happen
338-
removeFromQueue(request)
337+
// A failed create user request would leave the SDK in a bad state
338+
// Don't remove the request from cache and pause the operation repo
339+
// We will retry this request on a new session
340+
OSOperationRepo.sharedInstance.paused = true
341+
request.sentToClient = false
339342
}
343+
} else {
344+
executePendingRequests()
340345
}
341-
executePendingRequests()
342346
}
343347
}
344348

@@ -600,7 +604,7 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest {
600604

601605
var identityModel: OSIdentityModel
602606
var pushSubscriptionModel: OSSubscriptionModel
603-
let originalPushToken: String?
607+
var originalPushToken: String?
604608

605609
func prepareForExecution() -> Bool {
606610
guard let appId = OneSignalConfigManager.getAppId() else {
@@ -617,6 +621,7 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest {
617621
func updatePushSubscriptionModel(_ pushSubscriptionModel: OSSubscriptionModel) {
618622
self.pushSubscriptionModel = pushSubscriptionModel
619623
self.parameters?["subscriptions"] = [pushSubscriptionModel.jsonRepresentation()]
624+
self.originalPushToken = pushSubscriptionModel.address
620625
}
621626

622627
init(identityModel: OSIdentityModel, propertiesModel: OSPropertiesModel, pushSubscriptionModel: OSSubscriptionModel, originalPushToken: String?) {

0 commit comments

Comments
 (0)