diff --git a/src/addon/notifications/components/actions/actions.ts b/src/addon/notifications/components/actions/actions.ts index 7835d3829..2d56bc768 100644 --- a/src/addon/notifications/components/actions/actions.ts +++ b/src/addon/notifications/components/actions/actions.ts @@ -37,12 +37,29 @@ export class AddonNotificationsActionsComponent implements OnInit { * Component being initialized. */ ngOnInit(): void { - if (!this.contextUrl) { - // No contexturl, nothing to do. + if (!this.contextUrl && (!this.data || !this.data.appurl)) { + // No URL, nothing to do. return; } - this.contentLinksDelegate.getActionsFor(this.contextUrl, this.courseId, undefined, this.data).then((actions) => { + let promise; + + // Treat appurl first if any. + if (this.data && this.data.appurl) { + promise = this.contentLinksDelegate.getActionsFor(this.data.appurl, this.courseId, undefined, this.data); + } else { + promise = Promise.resolve([]); + } + + promise.then((actions) => { + if (!actions.length && this.contextUrl) { + // No appurl or cannot handle it. Try with contextUrl. + return this.contentLinksDelegate.getActionsFor(this.contextUrl, this.courseId, undefined, this.data); + } + + return actions; + }).then((actions) => { + if (!actions.length) { // URL is not supported. Add an action to open it in browser. actions.push({ @@ -63,6 +80,8 @@ export class AddonNotificationsActionsComponent implements OnInit { * @param {NavController} [navCtrl] NavController. */ protected defaultAction(siteId: string, navCtrl?: NavController): void { - this.sitesProvider.getCurrentSite().openInBrowserWithAutoLogin(this.contextUrl); + const url = (this.data && this.data.appurl) || this.contextUrl; + + this.sitesProvider.getCurrentSite().openInBrowserWithAutoLogin(url); } } diff --git a/src/addon/notifications/providers/push-click-handler.ts b/src/addon/notifications/providers/push-click-handler.ts index 11450bb23..54178d1bf 100644 --- a/src/addon/notifications/providers/push-click-handler.ts +++ b/src/addon/notifications/providers/push-click-handler.ts @@ -61,10 +61,37 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications * @return {Promise} Promise resolved when done. */ handleClick(notification: any): Promise { - return this.notificationsProvider.invalidateNotificationsList(notification.site).catch(() => { - // Ignore errors. - }).then(() => { - return this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site); + let promise; + + // Try to handle the appurl first. + if (notification.customdata && notification.customdata.appurl) { + promise = this.linkHelper.handleLink(notification.customdata.appurl); + } else { + promise = Promise.resolve(false); + } + + return promise.then((treated) => { + + if (!treated) { + // No link or cannot be handled by the app. Try to handle the contexturl now. + if (notification.contexturl) { + return this.linkHelper.handleLink(notification.contexturl); + } else { + return false; + } + } + + return true; + }).then((treated) => { + + if (!treated) { + // No link or cannot be handled by the app. Open the notifications page. + return this.notificationsProvider.invalidateNotificationsList(notification.site).catch(() => { + // Ignore errors. + }).then(() => { + return this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site); + }); + } }); } }