-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MOB-6055] callback on setEmail/setUserId #629
Changes from all commits
6a14f63
2b00983
53c078f
7cc3d7b
97f22b0
8a4132c
ab62c99
9731060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
_payloadData = data | ||
} | ||
|
||
func setEmail(_ email: String?, authToken: String? = nil) { | ||
func setEmail(_ email: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) { | ||
ITBInfo() | ||
|
||
if _email == email && email != nil && authToken != nil { | ||
|
@@ -127,13 +127,15 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
|
||
_email = email | ||
_userId = nil | ||
_successCallback = successHandler | ||
_failureCallback = failureHandler | ||
|
||
storeIdentifierData() | ||
|
||
onLogin(authToken) | ||
} | ||
|
||
func setUserId(_ userId: String?, authToken: String? = nil) { | ||
func setUserId(_ userId: String?, authToken: String? = nil, successHandler: OnSuccessHandler? = nil, failureHandler: OnFailureHandler? = nil) { | ||
ITBInfo() | ||
|
||
if _userId == userId && userId != nil && authToken != nil { | ||
|
@@ -149,6 +151,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
|
||
_email = nil | ||
_userId = userId | ||
_successCallback = successHandler | ||
_failureCallback = failureHandler | ||
|
||
storeIdentifierData() | ||
|
||
|
@@ -167,6 +171,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
guard let appName = pushIntegrationName else { | ||
let errorMessage = "Not registering device token - appName must not be nil" | ||
ITBError(errorMessage) | ||
_failureCallback?(errorMessage, nil) | ||
onFailure?(errorMessage, nil) | ||
return | ||
} | ||
|
@@ -181,8 +186,15 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
sdkVersion: localStorage.sdkVersion) | ||
requestHandler.register(registerTokenInfo: registerTokenInfo, | ||
notificationStateProvider: notificationStateProvider, | ||
onSuccess: onSuccess, | ||
onFailure: onFailure) | ||
onSuccess: { (_ data: [AnyHashable: Any]?) in | ||
self._successCallback?(data) | ||
onSuccess?(data) | ||
}, | ||
onFailure: { (_ reason: String?, _ data: Data?) in | ||
self._failureCallback?(reason, data) | ||
onFailure?(reason, data) | ||
} | ||
) | ||
} | ||
|
||
@discardableResult | ||
|
@@ -428,6 +440,9 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
private var _email: String? | ||
private var _payloadData: [AnyHashable: Any]? | ||
private var _userId: String? | ||
private var _successCallback: OnSuccessHandler? = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is going to be global but only used for setting the user credentials, we might have to rename it that way. Because, we will be adding success failure callbacks to other api calls / function calls as well and they will have to pass in success and failure callbacks too. using this global variable to store that and replace whats been stored in that can cause inconsistent behaviors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like for example, updateEmail also uses success and failure callback handler to notify the state. But by not having it stored globally, it allows for good separation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ayyanchira yes we can rename it so that is identified differently, but it would be class variable because it is used from the whole different method and that is why we need to hold a reference to it |
||
private var _failureCallback: OnFailureHandler? = nil | ||
|
||
|
||
/// the hex representation of this device token | ||
private var hexToken: String? | ||
|
@@ -537,6 +552,8 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { | |
|
||
if config.autoPushRegistration { | ||
notificationStateProvider.registerForRemoteNotifications() | ||
} else { | ||
_successCallback?([:]) | ||
} | ||
|
||
_ = inAppManager.scheduleSync() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had initial thought that we might need additional functions with and without handlers as we do in Android. But looks like having optional parameters makes it modern and lets us have only one signature instead of bloating up the IterableApi class. 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ayyanchira ok so for this we are good right ?