@@ -22,7 +22,8 @@ struct OfflineRequestProcessor: RequestProcessorProtocol {
2222 self . deviceMetadata = deviceMetadata
2323 self . taskScheduler = taskScheduler
2424 self . taskRunner = taskRunner
25- notificationListener = NotificationListener ( notificationCenter: notificationCenter)
25+ notificationListener = NotificationListener ( notificationCenter: notificationCenter,
26+ authManager: authManager)
2627 }
2728
2829 var autoRetry : Bool {
@@ -423,16 +424,21 @@ struct OfflineRequestProcessor: RequestProcessorProtocol {
423424 }
424425
425426 private class NotificationListener : NSObject {
426- init ( notificationCenter: NotificationCenterProtocol ) {
427+ init ( notificationCenter: NotificationCenterProtocol ,
428+ authManager: IterableAuthManagerProtocol ? = nil ) {
427429 ITBInfo ( " OfflineRequestProcessor.NotificationListener.init() " )
428430 self . notificationCenter = notificationCenter
431+ self . authManager = authManager
429432 super. init ( )
430433 self . notificationCenter. addObserver ( self ,
431434 selector: #selector( onTaskFinishedWithSuccess ( notification: ) ) ,
432435 name: . iterableTaskFinishedWithSuccess, object: nil )
433436 self . notificationCenter. addObserver ( self ,
434437 selector: #selector( onTaskFinishedWithNoRetry ( notification: ) ) ,
435438 name: . iterableTaskFinishedWithNoRetry, object: nil )
439+ self . notificationCenter. addObserver ( self ,
440+ selector: #selector( onTaskFinishedWithRetry ( notification: ) ) ,
441+ name: . iterableTaskFinishedWithRetry, object: nil )
436442 }
437443
438444 deinit {
@@ -464,6 +470,18 @@ struct OfflineRequestProcessor: RequestProcessorProtocol {
464470 ITBError ( " Could not find taskId for notification " )
465471 }
466472 }
473+
474+ @objc
475+ private func onTaskFinishedWithRetry( notification: Notification ) {
476+ ITBInfo ( )
477+ if let taskSendRequestError = IterableNotificationUtil . notificationToTaskSendRequestError ( notification) {
478+ let error = taskSendRequestError. sendRequestError
479+ if error. httpStatusCode == 401 , RequestProcessorUtil . matchesJWTErrorCode ( error. iterableCode) {
480+ ITBInfo ( " JWT auth failure in offline task, invalidating auth token state " )
481+ authManager? . setIsLastAuthTokenValid ( false )
482+ }
483+ }
484+ }
467485
468486 private func addPendingTask( taskId: String ) -> Pending < SendRequestValue , SendRequestError > {
469487 let result = Fulfill < SendRequestValue , SendRequestError > ( )
@@ -501,6 +519,7 @@ struct OfflineRequestProcessor: RequestProcessorProtocol {
501519 }
502520
503521 private let notificationCenter : NotificationCenterProtocol
522+ private weak var authManager : IterableAuthManagerProtocol ?
504523 private var pendingTasksMap = [ String : Fulfill < SendRequestValue , SendRequestError > ] ( )
505524 private var pendingTasksQueue = DispatchQueue ( label: " pendingTasks " )
506525 }
0 commit comments