MOBILE-2927 emulator: Adapt push simulation to new behaviour

main
Dani Palou 2019-03-22 13:08:03 +01:00
parent 44a39fd763
commit c982017029
3 changed files with 11 additions and 10 deletions

View File

@ -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<any[]>} Promise resolved with the notifications.
*/
protected fetchNotifications(siteId: string): Promise<any[]> {
return this.notificationsProvider.getUnreadNotifications(0, undefined, true, false, true, siteId);
return this.notificationsHelper.getNotifications([], undefined, true, false, true, siteId).then((result) => {
return result.notifications;
});
}
/**

View File

@ -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);

View File

@ -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();