Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions android/src/main/java/com/intercom/reactnative/IntercomModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ public String getName() {

public static boolean isIntercomPush(RemoteMessage remoteMessage) {
try {
if (remoteMessage == null) {
Log.w(NAME, "isIntercomPush: null remoteMessage");
return false;
}
Map message = remoteMessage.getData();
if (message == null) {
Log.w(NAME, "isIntercomPush: null message data");
return false;
}
return intercomPushClient.isIntercomPush(message);
} catch (Exception err) {
Log.e(NAME, "isIntercomPush error:");
Expand All @@ -68,7 +76,15 @@ public static boolean isIntercomPush(RemoteMessage remoteMessage) {
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage
remoteMessage) {
try {
if (application == null || remoteMessage == null) {
Log.w(NAME, "handleRemotePushMessage: null application or remoteMessage");
return;
}
Map message = remoteMessage.getData();
if (message == null) {
Log.w(NAME, "handleRemotePushMessage: null message data");
return;
}
intercomPushClient.handlePush(application, message);
} catch (Exception err) {
Log.e(NAME, "handleRemotePushMessage error:");
Expand All @@ -77,8 +93,17 @@ public static void handleRemotePushMessage(@NonNull Application application, Rem
}

public static void sendTokenToIntercom(Application application, @NonNull String token) {
intercomPushClient.sendTokenToIntercom(application, token);
Log.d(NAME, "sendTokenToIntercom");
try {
if (application == null || token == null || token.isEmpty()) {
Log.w(NAME, "sendTokenToIntercom: null application or invalid token");
return;
}
intercomPushClient.sendTokenToIntercom(application, token);
Log.d(NAME, "sendTokenToIntercom");
} catch (Exception err) {
Log.e(NAME, "sendTokenToIntercom error:");
Log.e(NAME, err.toString());
}
}

@ReactMethod
Expand All @@ -97,18 +122,23 @@ public void handlePushMessage(Promise promise) {
@ReactMethod
public void sendTokenToIntercom(@NonNull String token, Promise promise) {
try {
if (token == null || token.isEmpty()) {
Log.e(NAME, "sendTokenToIntercom: invalid token");
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "Invalid token");
return;
}

Activity activity = getCurrentActivity();
if (activity != null) {
if (activity != null && activity.getApplication() != null) {
intercomPushClient.sendTokenToIntercom(activity.getApplication(), token);
Log.d(NAME, "sendTokenToIntercom");
promise.resolve(true);
} else {
Log.e(NAME, "sendTokenToIntercom");
Log.e(NAME, "no current activity");
Log.e(NAME, "sendTokenToIntercom: no current activity or application");
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "No current activity");
}

} catch (
Exception err) {
} catch (Exception err) {
Log.e(NAME, "sendTokenToIntercom error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, err.toString());
Expand Down