Skip to content

Commit

Permalink
Merge pull request #156 from Pushwoosh/feature/SDK-199-email-methods-…
Browse files Browse the repository at this point in the history
…added

[feature][SDK-199] 'setUserEmails', 'setEmails', 'getUserId' methods added
  • Loading branch information
akidisdev authored Feb 15, 2024
2 parents c0d26ce + 91e76ea commit 713630f
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
60 changes: 60 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,55 @@ class PushNotification {
PushwooshModule.onPushOpen(callback);
}

//Function: setUserEmails
//Register emails list associated to the current user.
//
//Example:
//(start code)
// Pushwoosh.setUserEmails("someUser", ["example@mail.some"],
// function(status) {
// console.warn('setUserEmails success');
// },
// function(status) {
// console.warn('setUserEmails failed');
// }
// );
//
setUserEmails(userId: string, emails: Object, success: ?Function, fail: ?Function) {
if (!success) {
success = function() {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.setUserEmails(userId, emails, success, fail);
}


//Function: setEmails
//Register emails list associated to the current user.
//
//Example:
//(start code)
// Pushwoosh.setEmails(["example@mail.some"],
// function(status) {
// console.warn('setEmails success');
// },
// function(status) {
// console.warn('setEmails failed');
// }
// );
//
setEmails(emails: Object, success: ?Function, fail: ?Function) {
if (!success) {
success = function() {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.setEmails(emails, success, fail);
}

//Function: setTags
//Call this to set tags for the device
//
Expand Down Expand Up @@ -233,6 +282,17 @@ class PushNotification {
PushwooshModule.getHwid(success);
}

//Function: getUserId
//Call this to get Pushwoosh User ID used for communications with Pushwoosh API
//
//Example:
//(start code)
// Pushwoosh.getUserId();
//(end)
getUserId(success: Function) {
PushwooshModule.getUserId(success);
}

//Function: setUserId
//[android, ios] Set User indentifier. This could be Facebook ID, username or email, or any other user ID.
//This allows data and events to be matched across multiple user devices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@ public void onPushReceived(Callback callback) {
}
}

@ReactMethod
public void setEmails(@NonNull ReadableArray emails, final Callback success, final Callback error) {
Pushwoosh.getInstance().setEmail(ConversionUtil.messageCodesArrayToArrayList(emails), new com.pushwoosh.function.Callback<Boolean, SetEmailException>() {
@Override
public void process(@NonNull Result<Boolean, SetEmailException> result) {
if (result.isSuccess()) {
if (success != null) {
success.invoke();
}
} else {
if (error != null) {
error.invoke(result.getException().getMessage());
}
}
}
});
}

@ReactMethod
public void setUserEmails(@NonNull String userId, @NonNull ReadableArray emails, final Callback success, final Callback error) {
Pushwoosh.getInstance().setUser(userId, ConversionUtil.messageCodesArrayToArrayList(emails), new com.pushwoosh.function.Callback<Boolean, SetUserException>() {
@Override
public void process(@NonNull Result<Boolean, SetUserException> result) {
if (result.isSuccess()) {
if (success != null) {
success.invoke();
}
} else {
if (error != null) {
error.invoke(result.getException().getMessage());
}
}
}
});
}

@ReactMethod
public void setTags(ReadableMap tags, final Callback success, final Callback error) {
Pushwoosh.getInstance().sendTags(ConversionUtil.convertToTagsBundle(tags), new com.pushwoosh.function.Callback<Void, PushwooshException>() {
Expand Down Expand Up @@ -232,6 +268,11 @@ public void getHwid(Callback callback) {
callback.invoke(Pushwoosh.getInstance().getHwid());
}

@ReactMethod
public void getUserId(Callback callback) {
callback.invoke(Pushwoosh.getInstance().getUserId());
}

@ReactMethod
public void setUserId(String userId) {
PushwooshInApp.getInstance().setUserId(userId);
Expand Down
30 changes: 30 additions & 0 deletions src/ios/PushwooshPlugin/Pushwoosh.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,42 @@ - (dispatch_queue_t)methodQueue {
}
}

RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback) {
if (callback) {
callback(@[ [[Pushwoosh sharedInstance] getUserId] ]);
}
}

RCT_EXPORT_METHOD(getPushToken:(RCTResponseSenderBlock)callback) {
if (callback) {
callback(@[ objectOrNull([[PushNotificationManager pushManager] getPushToken]) ]);
}
}

RCT_EXPORT_METHOD(setEmails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
[[Pushwoosh sharedInstance] setEmails:emails completion:^(NSError * _Nullable error) {
if (!error && successCallback) {
successCallback(@[]);
}

if (error && errorCallback) {
errorCallback(@[ objectOrNull([error localizedDescription]) ]);
}
}];
}

RCT_EXPORT_METHOD(setUserEmails:(NSString*)userId emails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
[[Pushwoosh sharedInstance] setUser:userId emails:emails completion:^(NSError * _Nullable error) {
if (!error && successCallback) {
successCallback(@[]);
}

if (error && errorCallback) {
errorCallback(@[ objectOrNull([error localizedDescription]) ]);
}
}];
}

RCT_EXPORT_METHOD(setTags:(NSDictionary*)tags success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
[[PushNotificationManager pushManager] setTags:tags withCompletion:^(NSError* error) {
if (!error && successCallback) {
Expand Down

0 comments on commit 713630f

Please sign in to comment.