Skip to content

Commit

Permalink
refactor: Make notification handling more consistent
Browse files Browse the repository at this point in the history
* no need for async for handlePendingNotifications
* proper name for the event handler
* handlePendingNotifications() in iOS the same as Android
  • Loading branch information
borisyankov committed Mar 31, 2018
1 parent 339e0bd commit b58ff87
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/utils/notifications.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const refreshNotificationToken = () => {
NotificationsAndroid.refreshToken();
};

export const handlePendingNotifications = async (notificationData: Object, actions: Actions) => {
export const handlePendingNotifications = (notificationData: Object, actions: Actions) => {
if (!notificationData || !notificationData.getData) {
return;
}
Expand Down
13 changes: 6 additions & 7 deletions src/utils/notifications.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const onPushRegistered = async (
};

export const addNotificationListener = (notificationHandler: (notification: Object) => void) => {
NotificationsIOS.addEventListener('notification', notificationHandler);
NotificationsIOS.addEventListener('notificationOpened', notificationHandler);
};

export const removeNotificationListener = (notificationHandler: (notification: Object) => void) => {
NotificationsIOS.removeEventListener('notification', notificationHandler);
NotificationsIOS.removeEventListener('notificationOpened', notificationHandler);
};

export const initializeNotifications = (
Expand All @@ -40,17 +40,16 @@ export const initializeNotifications = (

export const refreshNotificationToken = () => {};

export const handlePendingNotifications = async (notificationData: Object, actions: Actions) => {
config.startup.notification = notificationData;
export const handlePendingNotifications = (notificationData: Object, actions: Actions) => {
if (!notificationData || !notificationData.getData) {
return;
}

const data = notificationData.getData();
if (!data || !data.custom || !data.custom.data) {
return;
config.startup.notification = data;
if (data) {
actions.doNarrow(getNarrowFromNotificationData(data), data.zulip_message_id);
}
actions.doNarrow(getNarrowFromNotificationData(data), data.zulip_message_id);
};

export const handleInitialNotification = async (actions: Actions) => {
Expand Down

0 comments on commit b58ff87

Please sign in to comment.