Merge pull request #1896 from dpalou/MOBILE-2938

MOBILE-2938 notifications: Support appurl field
main
Juan Leyva 2019-05-08 11:59:03 +02:00 committed by GitHub
commit be5f1febc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -61,10 +61,37 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications
* @return {Promise<any>} Promise resolved when done.
*/
handleClick(notification: any): Promise<any> {
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);
});
}
});
}
}