MOBILE-2927 emulator: Adapt push simulation to new behaviour
parent
44a39fd763
commit
c982017029
|
@ -21,6 +21,7 @@ import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||||
import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper';
|
import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper';
|
||||||
import { AddonNotificationsProvider } from './notifications';
|
import { AddonNotificationsProvider } from './notifications';
|
||||||
|
import { AddonNotificationsHelperProvider } from './helper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifications cron handler.
|
* Notifications cron handler.
|
||||||
|
@ -32,7 +33,7 @@ export class AddonNotificationsCronHandler implements CoreCronHandler {
|
||||||
constructor(private appProvider: CoreAppProvider, private eventsProvider: CoreEventsProvider,
|
constructor(private appProvider: CoreAppProvider, private eventsProvider: CoreEventsProvider,
|
||||||
private sitesProvider: CoreSitesProvider, private localNotifications: CoreLocalNotificationsProvider,
|
private sitesProvider: CoreSitesProvider, private localNotifications: CoreLocalNotificationsProvider,
|
||||||
private notificationsProvider: AddonNotificationsProvider, private textUtils: CoreTextUtilsProvider,
|
private notificationsProvider: AddonNotificationsProvider, private textUtils: CoreTextUtilsProvider,
|
||||||
private emulatorHelper: CoreEmulatorHelperProvider) {}
|
private emulatorHelper: CoreEmulatorHelperProvider, private notificationsHelper: AddonNotificationsHelperProvider) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time between consecutive executions.
|
* Get the time between consecutive executions.
|
||||||
|
@ -91,7 +92,9 @@ export class AddonNotificationsCronHandler implements CoreCronHandler {
|
||||||
* @return {Promise<any[]>} Promise resolved with the notifications.
|
* @return {Promise<any[]>} Promise resolved with the notifications.
|
||||||
*/
|
*/
|
||||||
protected fetchNotifications(siteId: string): Promise<any[]> {
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -161,17 +161,15 @@ export class CoreEmulatorHelperProvider implements CoreInitHandler {
|
||||||
|
|
||||||
// There is a new notification, show it.
|
// There is a new notification, show it.
|
||||||
return getDataFn(notification).then((titleAndText) => {
|
return getDataFn(notification).then((titleAndText) => {
|
||||||
|
// Set some calculated data.
|
||||||
|
notification.site = siteId;
|
||||||
|
notification.name = notification.name || notification.eventtype;
|
||||||
|
|
||||||
const localNotif: ILocalNotification = {
|
const localNotif: ILocalNotification = {
|
||||||
id: 1,
|
id: 1,
|
||||||
trigger: {
|
|
||||||
at: new Date()
|
|
||||||
},
|
|
||||||
title: titleAndText.title,
|
title: titleAndText.title,
|
||||||
text: titleAndText.text,
|
text: titleAndText.text,
|
||||||
data: {
|
data: notification
|
||||||
notif: notification,
|
|
||||||
site: siteId
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.localNotifProvider.schedule(localNotif, component, siteId);
|
return this.localNotifProvider.schedule(localNotif, component, siteId);
|
||||||
|
|
|
@ -630,7 +630,7 @@ export class LocalNotificationsMock extends LocalNotifications {
|
||||||
* @return {number} Trigger time.
|
* @return {number} Trigger time.
|
||||||
*/
|
*/
|
||||||
protected getNotificationTriggerAt(notification: ILocalNotification): number {
|
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') {
|
if (typeof triggerAt != 'number') {
|
||||||
return triggerAt.getTime();
|
return triggerAt.getTime();
|
||||||
|
|
Loading…
Reference in New Issue