Skip to content

Commit

Permalink
Avoid undefined payloads
Browse files Browse the repository at this point in the history
* Avoid undefined payloads

* Check for null instead of relying on try/catch

* Remove redundant null check

* Wrap in try/catch instead of null checks
  • Loading branch information
CarlyHarly authored and DanielEliraz committed May 22, 2023
1 parent 102d64f commit 574d3f3
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,32 @@ protected int createNotificationId(Notification notification) {
}

private void notifyReceivedToJS() {
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
try {
Bundle bundle = mNotificationProps.asBundle();
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_EVENT_NAME, bundle, mAppLifecycleFacade.getRunningReactContext());
} catch (NullPointerException ex) {
Log.e(LOGTAG, "notifyReceivedToJS: Null pointer exception");
}
}

private void notifyReceivedBackgroundToJS() {
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME, mNotificationProps.asBundle(), mAppLifecycleFacade.getRunningReactContext());
try {
Bundle bundle = mNotificationProps.asBundle();
mJsIOHelper.sendEventToJS(NOTIFICATION_RECEIVED_BACKGROUND_EVENT_NAME, bundle, mAppLifecycleFacade.getRunningReactContext());
} catch (NullPointerException ex) {
Log.e(LOGTAG, "notifyReceivedBackgroundToJS: Null pointer exception");
}
}

private void notifyOpenedToJS() {
Bundle response = new Bundle();
response.putBundle("notification", mNotificationProps.asBundle());

mJsIOHelper.sendEventToJS(NOTIFICATION_OPENED_EVENT_NAME, response, mAppLifecycleFacade.getRunningReactContext());
try {
response.putBundle("notification", mNotificationProps.asBundle());
mJsIOHelper.sendEventToJS(NOTIFICATION_OPENED_EVENT_NAME, response, mAppLifecycleFacade.getRunningReactContext());
} catch (NullPointerException ex) {
Log.e(LOGTAG, "notifyOpenedToJS: Null pointer exception");
}
}

protected void launchOrResumeApp() {
Expand Down

0 comments on commit 574d3f3

Please sign in to comment.