Skip to content

Commit f68801f

Browse files
committed
fixes
1 parent 143b6fb commit f68801f

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

swift-sdk/Internal/EmptyInAppManager.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Foundation
66
import UIKit
77

88
class EmptyInAppManager: IterableInternalInAppManagerProtocol {
9+
910
func start() -> Pending<Bool, Error> {
1011
Fulfill<Bool, Error>(value: true)
1112
}
@@ -32,15 +33,15 @@ class EmptyInAppManager: IterableInternalInAppManagerProtocol {
3233

3334
func show(message _: IterableInAppMessage, consume _: Bool, callback _: ITBURLCallback?) {}
3435

35-
func remove(message _: IterableInAppMessage) {}
36+
func remove(message _: IterableInAppMessage, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
3637

37-
func remove(message _: IterableInAppMessage, location _: InAppLocation) {}
38+
func remove(message _: IterableInAppMessage, location _: InAppLocation, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
3839

39-
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource) {}
40+
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
4041

41-
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, inboxSessionId _: String?) {}
42+
func remove(message _: IterableInAppMessage, location _: InAppLocation, source _: InAppDeleteSource, inboxSessionId _: String?, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
4243

43-
func set(read _: Bool, forMessage _: IterableInAppMessage) {}
44+
func set(read _: Bool, forMessage _: IterableInAppMessage, successHandler _: OnSuccessHandler?, failureHandler _: OnFailureHandler?) {}
4445

4546
func getMessage(withId _: String) -> IterableInAppMessage? {
4647
nil

swift-sdk/Internal/InAppManager.swift

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ protocol IterableInternalInAppManagerProtocol: IterableInAppManagerProtocol, InA
2323
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
2424
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
2525
/// - parameter inboxSessionId: The ID of the inbox session that the message originates from.
26-
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String?)
26+
/// - parameter successHandler: The callback which returns `success.
27+
/// - parameter failureHandler: The callback which returns `failure.
28+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String?, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
2729
}
2830

2931
class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
32+
3033
init(requestHandler: RequestHandlerProtocol,
3134
deviceMetadata: DeviceMetadata,
3235
fetcher: InAppFetcherProtocol,
@@ -121,33 +124,31 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
121124
}
122125
}
123126

124-
func remove(message: IterableInAppMessage, location: InAppLocation, onCompletion: OnCompletionHandler?) {
127+
func remove(message: IterableInAppMessage, location: InAppLocation, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
125128
ITBInfo()
126-
self.completionHandler = onCompletion
127-
removePrivate(message: message, location: location)
129+
removePrivate(message: message, location: location, successHandler: successHandler, failureHandler: failureHandler)
128130
}
129131

130-
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, onCompletion: OnCompletionHandler?) {
132+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
131133
ITBInfo()
132-
self.completionHandler = onCompletion
133-
removePrivate(message: message, location: location, source: source)
134+
removePrivate(message: message, location: location, source: source, successHandler: successHandler, failureHandler: failureHandler)
134135
}
135136

136-
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String? = nil) {
137+
func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, inboxSessionId: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
137138
ITBInfo()
138139

139-
removePrivate(message: message, location: location, source: source, inboxSessionId: inboxSessionId)
140+
removePrivate(message: message, location: location, source: source, inboxSessionId: inboxSessionId, successHandler: successHandler, failureHandler: failureHandler)
140141
}
141142

142-
func set(read: Bool, forMessage message: IterableInAppMessage, onCompletion: OnCompletionHandler?) {
143-
self.completionHandler = onCompletion
143+
func set(read: Bool, forMessage message: IterableInAppMessage, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) {
144144
updateMessage(message, read: read).onSuccess { [weak self] _ in
145-
self?.completionHandler?(true)
145+
var successObject: [AnyHashable: Any] = [:]
146+
successHandler?(successObject)
146147
self?.callbackQueue.async { [weak self] in
147148
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
148149
}
149150
}.onError { [weak self] _ in
150-
self?.completionHandler?(false)
151+
failureHandler?(self?.description, nil)
151152
}
152153
}
153154

@@ -187,10 +188,10 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
187188
}
188189
}
189190

190-
func remove(message: IterableInAppMessage, onCompletion: OnCompletionHandler?) {
191+
func remove(message: IterableInAppMessage, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?) {
191192
ITBInfo()
192193

193-
removePrivate(message: message)
194+
removePrivate(message: message, location: .inApp, source: nil, successHandler: successHandler, failureHandler: failureHandler)
194195
}
195196

196197
// MARK: - Private/Internal
@@ -466,20 +467,17 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
466467
private func removePrivate(message: IterableInAppMessage,
467468
location: InAppLocation = .inApp,
468469
source: InAppDeleteSource? = nil,
469-
inboxSessionId: String? = nil) {
470+
inboxSessionId: String? = nil,
471+
successHandler: OnSuccessHandler? = nil,
472+
failureHandler: OnFailureHandler? = nil) {
470473
ITBInfo()
471-
472474
updateMessage(message, didProcessTrigger: true, consumed: true)
473475
requestHandler?.inAppConsume(message: message,
474476
location: location,
475477
source: source,
476478
inboxSessionId: inboxSessionId,
477-
onSuccess: { (_ data: [AnyHashable: Any]?) in
478-
self.completionHandler?(true)
479-
},
480-
onFailure: { (_ reason: String?, _ data: Data?) in
481-
self.completionHandler?(false)
482-
})
479+
onSuccess: successHandler,
480+
onFailure: failureHandler)
483481
callbackQueue.async { [weak self] in
484482
self?.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
485483
}
@@ -541,7 +539,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
541539
private var lastSyncTime: Date?
542540
private var moveToForegroundSyncInterval: Double = 1.0 * 60.0 // don't sync within sixty seconds
543541
private var autoDisplayPaused = false
544-
private var completionHandler: OnCompletionHandler? = nil
545542
}
546543

547544
extension InAppManager: InAppNotifiable {

swift-sdk/IterableInAppManagerProtocol.swift

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

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

3536
/// - parameter message: The message to remove.
3637
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
37-
/// - parameter onCompletion: The callback which returns `success` or `failure`.
38-
@objc(removeMessage:location:onCompletion:) func remove(message: IterableInAppMessage, location: InAppLocation, onCompletion: OnCompletionHandler?)
38+
/// - parameter successHandler: The callback which returns `success.
39+
/// - parameter failureHandler: The callback which returns `failure.
40+
@objc(removeMessage:location:successHandler:failureHandler:) func remove(message: IterableInAppMessage, location: InAppLocation, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
3941

4042
/// - parameter message: The message to remove.
4143
/// - parameter location: The location from where this message was shown. `inbox` or `inApp`.
4244
/// - parameter source: The source of deletion `inboxSwipe` or `deleteButton`.`
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?)
45+
/// - parameter successHandler: The callback which returns `success.
46+
/// - parameter failureHandler: The callback which returns `failure.
47+
@objc(removeMessage:location:source:successHandler:failureHandler:) func remove(message: IterableInAppMessage, location: InAppLocation, source: InAppDeleteSource, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
4548

4649
/// - parameter read: Whether this inbox message was read
4750
/// - parameter message: The inbox message
48-
/// - parameter onCompletion: The callback which returns `success` or `failure`.
49-
@objc(setRead:forMessage:onCompletion:) func set(read: Bool, forMessage message: IterableInAppMessage, onCompletion: OnCompletionHandler?)
51+
/// - parameter successHandler: The callback which returns `success.
52+
/// - parameter failureHandler: The callback which returns `failure.
53+
@objc(setRead:forMessage:successHandler:failureHandler:) func set(read: Bool, forMessage message: IterableInAppMessage, successHandler: OnSuccessHandler?, failureHandler: OnFailureHandler?)
5054

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

tests/unit-tests/InboxTests.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,20 @@ class InboxTests: XCTestCase {
196196
XCTAssertEqual(messages.count, 2)
197197

198198
let messageToRemove = messages[0]
199-
internalAPI.inAppManager.remove(messageToRemove, location: .inbox, source: .inboxSwipe) { success in
200-
XCTAssertTrue(success)
201-
let newMessages = internalAPI.inAppManager.getInboxMessages()
202-
XCTAssertEqual(newMessages.count, 1)
203-
XCTAssertFalse(newMessages.contains(messageToRemove))
204-
expectation1.fulfill()
205-
}
199+
internalAPI.inAppManager.remove(
200+
message: messageToRemove,
201+
location: .inbox,
202+
source: .inboxSwipe,
203+
successHandler: { _ in
204+
// Success handler code
205+
expectation1.fulfill()
206+
},
207+
failureHandler: { _, _ in
208+
// Failure handler code
209+
XCTFail("Failed to remove message")
210+
expectation1.fulfill()
211+
}
212+
)
206213
}
207214

208215
wait(for: [expectation1], timeout: testExpectationTimeout)

0 commit comments

Comments
 (0)