import { RNFirebase } from '@ulangi/react-native-firebase' ; export class NotificationsAdapter { private currentReminderChannel ? : RNFirebase . notifications . NativeAndroidChannel ; private unsubscribeNotificationListener ? : ( ) => void ; private notifications : RNFirebase . notifications . Notifications ; private messaging : RNFirebase . messaging . Messaging ; private notificationsStatic : RNFirebase . notifications . NotificationsStatics ; public constructor ( notifications , messaging , notificationsStatic ) { this . notifications = notifications ; this . messaging = messaging ; this . notificationsStatic = notificationsStatic ; } public setUpReminder ( time ) { if ( typeof this . currentReminderChannel === 'undefined' ) { this . currentReminderChannel = this . createReminderNotificationChannel ( ) ; } if ( typeof this . unsubscribeNotificationListener === 'undefined' ) { this . unsubscribeNotificationListener = this . notifications . onNotification ( async ( notification ) : Promise < void > => { await this . notifications . displayNotification ( notification ) ; } ) ; } this . scheduleReminderNotification ( time ) ; } public cleanUpReminder ( ) { this . deleteReminderNotificationChannel ( ) ; if ( typeof this . unsubscribeNotificationListener !== 'undefined' ) { this . unsubscribeNotificationListener ( ) ; } this . cancelReminderNotification ( ) ; } public hasPermission ( ) { return this . messaging . hasPermission ( ) ; } public requestPermission ( ) { return this . messaging . requestPermission ( ) ; } private scheduleReminderNotification ( time ) { this . notifications . scheduleNotification ( this . buildReminderNotification ( ) , { fireDate : time , repeatInterval : 'day' , } ) ; } private cancelReminderNotification ( ) { this . notifications . cancelNotification ( 'daily-reminder' ) ; } private buildReminderNotification ( ) { return new this . notificationsStatic . Notification ( ) . setNotificationId ( 'daily-reminder' ) . setTitle ( 'Friendly Reminder' ) . setBody ( "It's time to review your flashcards." ) . setSound ( 'default' ) . android . setChannelId ( 'reminder-channel' ) . android . setAutoCancel ( true ) ; } private createReminderNotificationChannel ( ) { const channel = new this . notificationsStatic . Android . Channel ( 'reminder-channel' , 'Reminder Channel' , this . notificationsStatic . Android . Importance . High ) . setDescription ( 'Used for getting reminder notification' ) ; this . notifications . android . createChannel ( channel ) ; return channel ; } private deleteReminderNotificationChannel ( ) { if ( typeof this . currentReminderChannel !== 'undefined' ) { this . notifications . android . deleteChannel ( this . currentReminderChannel . channelId ) ; this . currentReminderChannel = undefined ; } } }