2022-01-12 18:42:37 +00:00
|
|
|
// @ts-ignore
|
|
|
|
// TODO BUMP LIB VERSION
|
|
|
|
import { NotificationsAndroid, PendingNotifications, Notification } from 'react-native-notifications';
|
|
|
|
|
|
|
|
import { INotification } from '../../definitions/INotification';
|
|
|
|
|
|
|
|
class PushNotification {
|
|
|
|
onNotification: (notification: Notification) => void;
|
|
|
|
deviceToken: string;
|
|
|
|
constructor() {
|
|
|
|
this.onNotification = () => {};
|
|
|
|
this.deviceToken = '';
|
|
|
|
|
|
|
|
NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken: string) => {
|
|
|
|
this.deviceToken = deviceToken;
|
|
|
|
});
|
|
|
|
|
|
|
|
NotificationsAndroid.setNotificationOpenedListener((notification: Notification) => {
|
2022-01-19 20:37:06 +00:00
|
|
|
this.onNotification(notification);
|
2022-01-12 18:42:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceToken() {
|
|
|
|
return this.deviceToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
setBadgeCount = (_?: number) => {};
|
|
|
|
|
|
|
|
configure(onNotification: (notification: INotification) => void) {
|
|
|
|
this.onNotification = onNotification;
|
|
|
|
NotificationsAndroid.refreshToken();
|
|
|
|
return PendingNotifications.getInitialNotification();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new PushNotification();
|