import PushNotification , { PushNotification as PushNotificationType , PushNotificationScheduleObject } from 'react-native-push-notification' ; import { notificationHooks } from './hooks' ; import { checkinNotification } from './checkin' ; import { pauseNotification } from './pause' ; import { exposureReminderNotification } from './exposure-reminder' ; import { restrictionEndNotification } from './restriction-end' ; import { caseReminderNotification } from './case-reminder' ; interface Token { os : string ; token : string ; } interface NotificationOptions extends PushNotificationScheduleObject { allowWhileIdle ? : boolean ; } export interface NotificationSpec { id : number ; storageKey ? : string ; onLoadStorage ? : ( value : string , context ? : any ) => void ; titleKey : string ; messageKey : string ; handler : ( ) => void ; options ? : Partial < NotificationOptions > ; } const notificationTypes = [ pauseNotification , checkinNotification , exposureReminderNotification , restrictionEndNotification , caseReminderNotification ] ; const getId = ( notification ) : string => { return notification . id || notification . data . id ; } ; PushNotification . configure ( { onNotification : ( notification ) => { console . log ( `Responding to notification ${ getId ( notification ) }` ) ; const notificationType = notificationTypes . find ( ( { id } ) => String ( id ) === getId ( notification ) ) ; if ( notificationType ?. handler ) { notificationType ?. handler ( ) ; } else if ( notificationHooks . handleNotification ) { notificationHooks . handleNotification ( notification ) ; } } , onRegister : ( token ) => { if ( notificationHooks . handleRegister ) { notificationHooks . handleRegister ( token ) ; } } , permissions : { alert : true , badge : true , sound : true } , popInitialNotification : true , requestPermissions : false } ) ; export { notificationHooks } ;