From ca172baba83398ef0b9ab65d1314ace6f60f3ea2 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 11 Nov 2020 08:52:57 +0100 Subject: [PATCH 1/2] MOBILE-3507 push: Fix click push with no site --- src/core/pushnotifications/providers/delegate.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/pushnotifications/providers/delegate.ts b/src/core/pushnotifications/providers/delegate.ts index 94297132c..6f4683590 100644 --- a/src/core/pushnotifications/providers/delegate.ts +++ b/src/core/pushnotifications/providers/delegate.ts @@ -124,7 +124,10 @@ export class CorePushNotificationsDelegate { * @return Promise resolved with boolean: whether the handler feature is disabled. */ protected isFeatureDisabled(handler: CorePushNotificationsClickHandler, siteId: string): Promise { - if (handler.featureName) { + if (!siteId) { + // Notification doesn't belong to a site. Assume all handlers are enabled. + return Promise.resolve(false); + } else if (handler.featureName) { // Check if the feature is disabled. return this.sitesProvider.isFeatureDisabled(handler.featureName, siteId); } else { From e46aab5ed09a3d711a144104756e0be59b6e68bd Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 11 Nov 2020 12:05:38 +0100 Subject: [PATCH 2/2] MOBILE-3507 push: Support notifications without component --- src/addon/notifications/providers/push-click-handler.ts | 7 ++++++- src/core/courses/providers/enrol-push-click-handler.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/addon/notifications/providers/push-click-handler.ts b/src/addon/notifications/providers/push-click-handler.ts index b6504debd..e95c9440d 100644 --- a/src/addon/notifications/providers/push-click-handler.ts +++ b/src/addon/notifications/providers/push-click-handler.ts @@ -39,6 +39,11 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications * @return Whether the notification click is handled by this handler */ handles(notification: any): boolean | Promise { + if (!notification.moodlecomponent) { + // The notification doesn't come from Moodle. Handle it. + return true; + } + if (this.utils.isTrueOrOne(notification.notif)) { // Notification clicked, mark as read. Don't block for this. const notifId = notification.savedmessageid || notification.id; @@ -74,7 +79,7 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications // Try to handle the appurl. if (notification.customdata && notification.customdata.appurl) { switch (notification.customdata.appurlopenin) { - case 'inappbrowser': + case 'inapp': this.utils.openInApp(notification.customdata.appurl); return; diff --git a/src/core/courses/providers/enrol-push-click-handler.ts b/src/core/courses/providers/enrol-push-click-handler.ts index 635a776e5..17539a81a 100644 --- a/src/core/courses/providers/enrol-push-click-handler.ts +++ b/src/core/courses/providers/enrol-push-click-handler.ts @@ -37,8 +37,8 @@ export class CoreCoursesEnrolPushClickHandler implements CorePushNotificationsCl * @return Whether the notification click is handled by this handler */ handles(notification: any): boolean | Promise { - return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent.indexOf('enrol_') === 0 && - notification.name == 'expiry_notification'; + return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent && + notification.moodlecomponent.indexOf('enrol_') === 0 && notification.name == 'expiry_notification'; } /**