diff --git a/src/addon/notifications/providers/cron-handler.ts b/src/addon/notifications/providers/cron-handler.ts index 78f317c41..687b970e9 100644 --- a/src/addon/notifications/providers/cron-handler.ts +++ b/src/addon/notifications/providers/cron-handler.ts @@ -21,6 +21,7 @@ import { CoreSitesProvider } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper'; import { AddonNotificationsProvider } from './notifications'; +import { AddonNotificationsHelperProvider } from './helper'; /** * Notifications cron handler. @@ -32,7 +33,7 @@ export class AddonNotificationsCronHandler implements CoreCronHandler { constructor(private appProvider: CoreAppProvider, private eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider, private localNotifications: CoreLocalNotificationsProvider, private notificationsProvider: AddonNotificationsProvider, private textUtils: CoreTextUtilsProvider, - private emulatorHelper: CoreEmulatorHelperProvider) {} + private emulatorHelper: CoreEmulatorHelperProvider, private notificationsHelper: AddonNotificationsHelperProvider) {} /** * Get the time between consecutive executions. @@ -91,7 +92,9 @@ export class AddonNotificationsCronHandler implements CoreCronHandler { * @return {Promise} Promise resolved with the notifications. */ protected fetchNotifications(siteId: string): Promise { - return this.notificationsProvider.getUnreadNotifications(0, undefined, true, false, true, siteId); + return this.notificationsHelper.getNotifications([], undefined, true, false, true, siteId).then((result) => { + return result.notifications; + }); } /** diff --git a/src/core/emulator/providers/helper.ts b/src/core/emulator/providers/helper.ts index fc10a32a2..fc64ed0eb 100644 --- a/src/core/emulator/providers/helper.ts +++ b/src/core/emulator/providers/helper.ts @@ -161,17 +161,15 @@ export class CoreEmulatorHelperProvider implements CoreInitHandler { // There is a new notification, show it. return getDataFn(notification).then((titleAndText) => { + // Set some calculated data. + notification.site = siteId; + notification.name = notification.name || notification.eventtype; + const localNotif: ILocalNotification = { id: 1, - trigger: { - at: new Date() - }, title: titleAndText.title, text: titleAndText.text, - data: { - notif: notification, - site: siteId - } + data: notification }; return this.localNotifProvider.schedule(localNotif, component, siteId); diff --git a/src/core/emulator/providers/local-notifications.ts b/src/core/emulator/providers/local-notifications.ts index 3b943aba1..73d6ebfc4 100644 --- a/src/core/emulator/providers/local-notifications.ts +++ b/src/core/emulator/providers/local-notifications.ts @@ -630,7 +630,7 @@ export class LocalNotificationsMock extends LocalNotifications { * @return {number} Trigger time. */ protected getNotificationTriggerAt(notification: ILocalNotification): number { - const triggerAt = (notification.trigger && notification.trigger.at) || 0; + const triggerAt = (notification.trigger && notification.trigger.at) || new Date(); if (typeof triggerAt != 'number') { return triggerAt.getTime();