2018-12-16 13:11:45 +00:00
|
|
|
import firebase from 'react-native-firebase';
|
2017-11-27 22:50:46 +00:00
|
|
|
|
|
|
|
class AlarmServiceDriver {
|
|
|
|
|
2017-11-28 00:22:38 +00:00
|
|
|
hasPersistentNotifications() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationIsSet(alarmId) {
|
|
|
|
throw new Error('Available only for non-persistent alarms');
|
|
|
|
}
|
|
|
|
|
2018-12-16 13:11:45 +00:00
|
|
|
firebaseNotificationId_(joplinNotificationId) {
|
|
|
|
return 'net.cozic.joplin-' + joplinNotificationId;
|
|
|
|
}
|
|
|
|
|
2017-11-27 22:50:46 +00:00
|
|
|
async clearNotification(id) {
|
2018-12-16 13:11:45 +00:00
|
|
|
return firebase.notifications().cancelNotification(this.firebaseNotificationId_(id))
|
2017-11-27 22:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async scheduleNotification(notification) {
|
2018-12-16 13:11:45 +00:00
|
|
|
const firebaseNotification = new firebase.notifications.Notification()
|
|
|
|
firebaseNotification.setNotificationId(this.firebaseNotificationId_(notification.id));
|
|
|
|
firebaseNotification.setTitle(notification.title)
|
|
|
|
if ('body' in notification) firebaseNotification.body = notification.body;
|
|
|
|
firebaseNotification.android.setChannelId('com.google.firebase.messaging.default_notification_channel_id');
|
|
|
|
firebaseNotification.android.setSmallIcon('ic_stat_access_alarm');
|
|
|
|
|
|
|
|
firebase.notifications().scheduleNotification(firebaseNotification, {
|
|
|
|
fireDate: notification.date.getTime(),
|
|
|
|
});
|
2017-11-27 22:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AlarmServiceDriver;
|