Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
NotificationsAndroid.refreshToken();
// On Android, we allow for only one (global) listener per each event type.
NotificationsAndroid.setNotificationReceivedListener(notification => {
// console.log('PUSHLOG: setNotificationReceivedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationReceivedForeground(notificationData);
});
NotificationsAndroid.setNotificationOpenedListener(notification => {
// console.log('PUSHLOG: setNotificationOpenedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationOpened(notificationData);
});
PendingNotifications.getInitialNotification().then(notifications => {
// console.log('PUSHLOG: getInitialNotification', notifications);
if (notifications) {
notifications.data.forEach(notification => {
const notificationData = JSON.parse(notification.payload);
if (notification.opened) {
this.onNotificationOpened(notificationData);
} else {
this.handlePushData(notificationData);
}
});
}
});
// .catch(err => console.error('getInitialNotifiation() failed', err));
}
break;
default:
configure(options) {
this.onRegister = options.onRegister;
this.onNotification = options.onNotification;
this.onReply = options.onReply;
if (this.onRegister && this.deviceToken) {
this.onRegister({token: this.deviceToken});
}
if (options.popInitialNotification) {
PendingNotifications.getInitialNotification().
then((notification) => {
if (notification) {
const data = notification.getData();
if (data) {
ephemeralStore.appStartedFromPushNotification = true;
this.handleNotification(data, true);
}
}
}).
catch((err) => {
console.log('Android getInitialNotifiation() failed', err); //eslint-disable-line no-console
});
}
}
configure(params) {
this.onRegister = params.onRegister;
this.onNotification = params.onNotification;
NotificationsAndroid.refreshToken();
return PendingNotifications.getInitialNotification();
}
}
export const handleInitialNotification = async (dispatch: Dispatch, usersById: UserIdMap) => {
const data = await PendingNotifications.getInitialNotification();
handlePendingNotifications(data, dispatch, usersById);
};