forked from CIT/Vmeda.Online
		
	Merge pull request #1896 from dpalou/MOBILE-2938
MOBILE-2938 notifications: Support appurl field
This commit is contained in:
		
						commit
						be5f1febc2
					
				| @ -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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -61,10 +61,37 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications | ||||
|      * @return {Promise<any>} Promise resolved when done. | ||||
|      */ | ||||
|     handleClick(notification: any): Promise<any> { | ||||
|         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); | ||||
|                 }); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user