MOBILE-2927 notifications: Make push simulation use new delegate
parent
1146eea0fa
commit
b9aa0e0a90
|
@ -20,13 +20,11 @@ import { AddonNotificationsSettingsHandler } from './providers/settings-handler'
|
||||||
import { AddonNotificationsCronHandler } from './providers/cron-handler';
|
import { AddonNotificationsCronHandler } from './providers/cron-handler';
|
||||||
import { AddonNotificationsPushClickHandler } from './providers/push-click-handler';
|
import { AddonNotificationsPushClickHandler } from './providers/push-click-handler';
|
||||||
import { CoreAppProvider } from '@providers/app';
|
import { CoreAppProvider } from '@providers/app';
|
||||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
import { CoreInitDelegate } from '@providers/init';
|
||||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||||
import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
|
import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
|
||||||
import { CoreCronDelegate } from '@providers/cron';
|
import { CoreCronDelegate } from '@providers/cron';
|
||||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
|
||||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||||
|
|
||||||
// List of providers (without handlers).
|
// List of providers (without handlers).
|
||||||
|
@ -53,9 +51,8 @@ export class AddonNotificationsModule {
|
||||||
constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: AddonNotificationsMainMenuHandler,
|
constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: AddonNotificationsMainMenuHandler,
|
||||||
settingsDelegate: CoreSettingsDelegate, settingsHandler: AddonNotificationsSettingsHandler,
|
settingsDelegate: CoreSettingsDelegate, settingsHandler: AddonNotificationsSettingsHandler,
|
||||||
cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone,
|
cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone,
|
||||||
appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider,
|
appProvider: CoreAppProvider, localNotifications: CoreLocalNotificationsProvider,
|
||||||
notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider,
|
initDelegate: CoreInitDelegate, pushNotificationsDelegate: CorePushNotificationsDelegate,
|
||||||
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: CorePushNotificationsDelegate,
|
|
||||||
pushClickHandler: AddonNotificationsPushClickHandler) {
|
pushClickHandler: AddonNotificationsPushClickHandler) {
|
||||||
|
|
||||||
mainMenuDelegate.registerHandler(mainMenuHandler);
|
mainMenuDelegate.registerHandler(mainMenuHandler);
|
||||||
|
@ -63,22 +60,13 @@ export class AddonNotificationsModule {
|
||||||
cronDelegate.register(cronHandler);
|
cronDelegate.register(cronHandler);
|
||||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||||
|
|
||||||
const notificationClicked = (notification: any): void => {
|
|
||||||
sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => {
|
|
||||||
if (disabled) {
|
|
||||||
// Notifications are disabled, stop.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
notificationsProvider.invalidateNotificationsList().finally(() => {
|
|
||||||
linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (appProvider.isDesktop()) {
|
if (appProvider.isDesktop()) {
|
||||||
// Listen for clicks in simulated push notifications.
|
// Listen for clicks in simulated push notifications.
|
||||||
localNotifications.registerClick(AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notificationClicked);
|
localNotifications.registerClick(AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, (notification) => {
|
||||||
|
initDelegate.ready().then(() => {
|
||||||
|
pushNotificationsDelegate.clicked(notification);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ export class AddonNotificationsCronHandler implements CoreCronHandler {
|
||||||
*/
|
*/
|
||||||
protected getTitleAndText(notification: any): Promise<any> {
|
protected getTitleAndText(notification: any): Promise<any> {
|
||||||
const data = {
|
const data = {
|
||||||
title: notification.userfromfullname,
|
title: notification.subject || notification.userfromfullname,
|
||||||
text: notification.mobiletext.replace(/-{4,}/ig, '')
|
text: notification.mobiletext.replace(/-{4,}/ig, '')
|
||||||
};
|
};
|
||||||
data.text = this.textUtils.replaceNewLines(data.text, '<br>');
|
data.text = this.textUtils.replaceNewLines(data.text, '<br>');
|
||||||
|
|
|
@ -73,7 +73,9 @@ export class AddonNotificationsProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.moodlecomponent = notification.component;
|
||||||
notification.notification = 1;
|
notification.notification = 1;
|
||||||
|
notification.notif = 1;
|
||||||
if (typeof read != 'undefined') {
|
if (typeof read != 'undefined') {
|
||||||
notification.read = read;
|
notification.read = read;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications
|
||||||
handles(notification: any): boolean | Promise<boolean> {
|
handles(notification: any): boolean | Promise<boolean> {
|
||||||
if (this.utils.isTrueOrOne(notification.notif)) {
|
if (this.utils.isTrueOrOne(notification.notif)) {
|
||||||
// Notification clicked, mark as read. Don't block for this.
|
// Notification clicked, mark as read. Don't block for this.
|
||||||
this.notificationsProvider.markNotificationRead(notification.savedmessageid, notification.site).then(() => {
|
const notifId = notification.savedmessageid || notification.id;
|
||||||
|
|
||||||
|
this.notificationsProvider.markNotificationRead(notifId, notification.site).then(() => {
|
||||||
this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, notification.site);
|
this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, notification.site);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
|
|
Loading…
Reference in New Issue