Skip to content

Commit 7e4a714

Browse files
committed
Add code for setRead/removeMessage callbacks
1 parent fe72db1 commit 7e4a714

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

swift-sdk/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public enum IterableCustomActionName: String, CaseIterable {
381381

382382
public typealias ITEActionBlock = (String?) -> Void
383383
public typealias ITBURLCallback = (URL?) -> Void
384+
public typealias OnCompletionHandler = (Bool) -> Void
384385
public typealias OnSuccessHandler = (_ data: [AnyHashable: Any]?) -> Void
385386
public typealias OnFailureHandler = (_ reason: String?, _ data: Data?) -> Void
386387
public typealias UrlHandler = (URL) -> Bool

swift-sdk/Internal/InAppManager.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
121121
}
122122
}
123123

124-
func remove(message: IterableInAppMessage, location: InAppLocation) {
124+
func remove(message: IterableInAppMessage, location: InAppLocation, onCompletion: OnCompletionHandler?) {
125125
ITBInfo()
126-
126+
self.completionHandler = onCompletion
127127
removePrivate(message: message, location: location)
128128
}
129129

130-
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource) {
130+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, onCompletion: OnCompletionHandler?) {
131131
ITBInfo()
132-
132+
self.completionHandler = onCompletion
133133
removePrivate(message: message, location: location, source: source)
134134
}
135135

@@ -139,11 +139,15 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
139139
removePrivate(message: message, location: location, source: source, inboxSessionId: inboxSessionId)
140140
}
141141

142-
func set(read: Bool, forMessage message: IterableInAppMessage) {
142+
func set(read: Bool, forMessage message: IterableInAppMessage, onCompletion: OnCompletionHandler?) {
143+
self.completionHandler = onCompletion
143144
updateMessage(message, read: read).onSuccess { [weak self] _ in
145+
self?.completionHandler?(true)
144146
self?.callbackQueue.async { [weak self] in
145147
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
146148
}
149+
}.onError { [weak self] _ in
150+
self?.completionHandler?(false)
147151
}
148152
}
149153

@@ -183,7 +187,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
183187
}
184188
}
185189

186-
func remove(message: IterableInAppMessage) {
190+
func remove(message: IterableInAppMessage, onCompletion: OnCompletionHandler?) {
187191
ITBInfo()
188192

189193
removePrivate(message: message)
@@ -470,8 +474,12 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
470474
location: location,
471475
source: source,
472476
inboxSessionId: inboxSessionId,
473-
onSuccess: nil,
474-
onFailure: nil)
477+
onSuccess: { (_ data: [AnyHashable: Any]?) in
478+
self.completionHandler?(true)
479+
},
480+
onFailure: { (_ reason: String?, _ data: Data?) in
481+
self.completionHandler?(false)
482+
})
475483
callbackQueue.async { [weak self] in
476484
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
477485
}
@@ -533,6 +541,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
533541
private var lastSyncTime: Date?
534542
private var moveToForegroundSyncInterval: Double = 1.0 * 60.0 // don't sync within sixty seconds
535543
private var autoDisplayPaused = false
544+
private var completionHandler: OnCompletionHandler? = nil
536545
}
537546

538547
extension InAppManager: InAppNotifiable {

swift-sdk/IterableInAppManagerProtocol.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ import Foundation
2929
@objc(showMessage:consume:callbackBlock:) func show(message: IterableInAppMessage, consume: Bool, callback: ITBURLCallback?)
3030

3131
/// - parameter message: The message to remove.
32-
@objc(removeMessage:) func remove(message: IterableInAppMessage)
32+
/// - parameter onCompletion: The callback which returns `success` or `failure`.
33+
@objc(removeMessage:onCompletion:) func remove(message: IterableInAppMessage, onCompletion: OnCompletionHandler?)
3334

3435
/// - parameter message: The message to remove.
3536
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
36-
@objc(removeMessage:location:) func remove(message: IterableInAppMessage, location: InAppLocation)
37+
/// - parameter onCompletion: The callback which returns `success` or `failure`.
38+
@objc(removeMessage:location:onCompletion:) func remove(message: IterableInAppMessage, location: InAppLocation, onCompletion: OnCompletionHandler?)
3739

3840
/// - parameter message: The message to remove.
3941
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
4042
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
41-
@objc(removeMessage:location:source:) func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource)
43+
/// - parameter onCompletion: The callback which returns `success` or `failure`.
44+
@objc(removeMessage:location:source:onCompletion:) func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, onCompletion: OnCompletionHandler?)
4245

4346
/// - parameter read: Whether this inbox message was read
4447
/// - parameter message: The inbox message
45-
@objc(setRead:forMessage:) func set(read: Bool, forMessage message: IterableInAppMessage)
48+
/// - parameter onCompletion: The callback which returns `success` or `failure`.
49+
@objc(setRead:forMessage:onCompletion:) func set(read: Bool, forMessage message: IterableInAppMessage, onCompletion: OnCompletionHandler?)
4650

4751
/// - parameter id: The id of the message
4852
/// - returns: IterableInAppMessage with the id, if it exists.

0 commit comments

Comments
 (0)