From f4d3ab4c6c4dfe914aa2d11df431d989db2824d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Jan 2019 14:43:18 +0100 Subject: [PATCH] MOBILE-2795 notifications: Check is triggered on plugin --- src/providers/local-notifications.ts | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index 8f6d66c60..85b5e30fc 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -298,7 +298,7 @@ export class CoreLocalNotificationsProvider { return this.appDB.getRecord(this.TRIGGERED_TABLE, { id: notification.id }).then((stored) => { return stored.at === notification.at.getTime() / 1000; }).catch(() => { - return false; + return this.localNotifications.isTriggered(notification.id); }); } @@ -478,22 +478,23 @@ export class CoreLocalNotificationsProvider { protected scheduleNotification(notification: CoreILocalNotification): Promise { // Check if the notification has been triggered already. return this.isTriggered(notification).then((triggered) => { - if (!triggered) { - // Check if sound is enabled for notifications. - return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => { - if (!soundEnabled) { - notification.sound = null; - } else { - delete notification.sound; // Use default value. - } + // Cancel the current notification in case it gets scheduled twice. + return this.localNotifications.cancel(notification.id).finally(() => { + if (!triggered) { + // Check if sound is enabled for notifications. + return this.configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((soundEnabled) => { + if (!soundEnabled) { + notification.sound = null; + } else { + delete notification.sound; // Use default value. + } - // Remove from triggered, since the notification could be in there with a different time. - this.removeTriggered(notification.id); - this.localNotifications.cancel(notification.id).finally(() => { + // Remove from triggered, since the notification could be in there with a different time. + this.removeTriggered(notification.id); this.localNotifications.schedule(notification); }); - }); - } + } + }); }); }