You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Merge branch 'master' into search_engine_fts_fix
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
// Note: currently, if Play Services aren't available, notifications will not work at all
|
||||
// There won't be any warning or error message.
|
||||
|
||||
import firebase from 'react-native-firebase';
|
||||
const PushNotification = require('react-native-push-notification');
|
||||
|
||||
class AlarmServiceDriver {
|
||||
|
||||
constructor() {
|
||||
this.playServiceAvailable_ = firebase.utils().playServicesAvailability.isAvailable;
|
||||
if (!this.playServiceAvailable_) return;
|
||||
PushNotificationHandler_() {
|
||||
if (!this.PushNotification_) {
|
||||
PushNotification.configure({
|
||||
// (required) Called when a remote or local notification is opened or received
|
||||
onNotification: function(notification) {
|
||||
console.info('Notification was opened: ', notification );
|
||||
// process the notification
|
||||
},
|
||||
popInitialNotification: true,
|
||||
requestPermissions: true,
|
||||
});
|
||||
|
||||
this.channel_ = new firebase.notifications.Android.Channel('net.cozic.joplin.notification', 'Joplin Alarm',firebase.notifications.Android.Importance.Max)
|
||||
.setDescription('Displays a notification for alarms associated with to-dos.');
|
||||
firebase.notifications().android.createChannel(this.channel_);
|
||||
this.PushNotification_ = PushNotification;
|
||||
}
|
||||
|
||||
return this.PushNotification_;
|
||||
}
|
||||
|
||||
hasPersistentNotifications() {
|
||||
@@ -22,29 +28,18 @@ class AlarmServiceDriver {
|
||||
throw new Error('Available only for non-persistent alarms');
|
||||
}
|
||||
|
||||
firebaseNotificationId_(joplinNotificationId) {
|
||||
return 'net.cozic.joplin-' + joplinNotificationId;
|
||||
}
|
||||
|
||||
async clearNotification(id) {
|
||||
if (!this.playServiceAvailable_) return;
|
||||
|
||||
return firebase.notifications().cancelNotification(this.firebaseNotificationId_(id))
|
||||
return this.PushNotificationHandler_().cancelLocalNotifications({id: id+''});
|
||||
}
|
||||
|
||||
async scheduleNotification(notification) {
|
||||
if (!this.playServiceAvailable_) return;
|
||||
const config = {
|
||||
id: notification.id + '',
|
||||
message: notification.title,
|
||||
date: notification.date,
|
||||
};
|
||||
|
||||
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('net.cozic.joplin.notification');
|
||||
firebaseNotification.android.setSmallIcon('ic_stat_access_alarm');
|
||||
|
||||
await firebase.notifications().scheduleNotification(firebaseNotification, {
|
||||
fireDate: notification.date.getTime(),
|
||||
});
|
||||
this.PushNotificationHandler_().localNotificationSchedule(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user