From b9aa0e0a9081ea0d7d13b5965868a0c71a93539f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 26 Mar 2019 11:20:44 +0100 Subject: [PATCH] MOBILE-2927 notifications: Make push simulation use new delegate --- .../notifications/notifications.module.ts | 28 ++++++------------- .../notifications/providers/cron-handler.ts | 2 +- .../notifications/providers/notifications.ts | 2 ++ .../providers/push-click-handler.ts | 4 ++- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/addon/notifications/notifications.module.ts b/src/addon/notifications/notifications.module.ts index d5042b001..2a2b94021 100644 --- a/src/addon/notifications/notifications.module.ts +++ b/src/addon/notifications/notifications.module.ts @@ -20,13 +20,11 @@ import { AddonNotificationsSettingsHandler } from './providers/settings-handler' import { AddonNotificationsCronHandler } from './providers/cron-handler'; import { AddonNotificationsPushClickHandler } from './providers/push-click-handler'; 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 { CoreSettingsDelegate } from '@core/settings/providers/delegate'; import { CoreCronDelegate } from '@providers/cron'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; -import { CoreSitesProvider } from '@providers/sites'; -import { CoreUtilsProvider } from '@providers/utils/utils'; import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; // List of providers (without handlers). @@ -53,9 +51,8 @@ export class AddonNotificationsModule { constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: AddonNotificationsMainMenuHandler, settingsDelegate: CoreSettingsDelegate, settingsHandler: AddonNotificationsSettingsHandler, cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone, - appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider, - notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider, - linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: CorePushNotificationsDelegate, + appProvider: CoreAppProvider, localNotifications: CoreLocalNotificationsProvider, + initDelegate: CoreInitDelegate, pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonNotificationsPushClickHandler) { mainMenuDelegate.registerHandler(mainMenuHandler); @@ -63,22 +60,13 @@ export class AddonNotificationsModule { cronDelegate.register(cronHandler); 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()) { // 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); + }); + }); } } } diff --git a/src/addon/notifications/providers/cron-handler.ts b/src/addon/notifications/providers/cron-handler.ts index 687b970e9..e16ed9a1f 100644 --- a/src/addon/notifications/providers/cron-handler.ts +++ b/src/addon/notifications/providers/cron-handler.ts @@ -105,7 +105,7 @@ export class AddonNotificationsCronHandler implements CoreCronHandler { */ protected getTitleAndText(notification: any): Promise { const data = { - title: notification.userfromfullname, + title: notification.subject || notification.userfromfullname, text: notification.mobiletext.replace(/-{4,}/ig, '') }; data.text = this.textUtils.replaceNewLines(data.text, '
'); diff --git a/src/addon/notifications/providers/notifications.ts b/src/addon/notifications/providers/notifications.ts index b52578a53..d268cff1a 100644 --- a/src/addon/notifications/providers/notifications.ts +++ b/src/addon/notifications/providers/notifications.ts @@ -73,7 +73,9 @@ export class AddonNotificationsProvider { }); } + notification.moodlecomponent = notification.component; notification.notification = 1; + notification.notif = 1; if (typeof read != 'undefined') { notification.read = read; } diff --git a/src/addon/notifications/providers/push-click-handler.ts b/src/addon/notifications/providers/push-click-handler.ts index 4d8d2f382..11450bb23 100644 --- a/src/addon/notifications/providers/push-click-handler.ts +++ b/src/addon/notifications/providers/push-click-handler.ts @@ -40,7 +40,9 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications handles(notification: any): boolean | Promise { if (this.utils.isTrueOrOne(notification.notif)) { // 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); }).catch(() => { // Ignore errors.