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. |      * Component being initialized. | ||||||
|      */ |      */ | ||||||
|     ngOnInit(): void { |     ngOnInit(): void { | ||||||
|         if (!this.contextUrl) { |         if (!this.contextUrl && (!this.data || !this.data.appurl)) { | ||||||
|             // No contexturl, nothing to do.
 |             // No URL, nothing to do.
 | ||||||
|             return; |             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) { |             if (!actions.length) { | ||||||
|                 // URL is not supported. Add an action to open it in browser.
 |                 // URL is not supported. Add an action to open it in browser.
 | ||||||
|                 actions.push({ |                 actions.push({ | ||||||
| @ -63,6 +80,8 @@ export class AddonNotificationsActionsComponent implements OnInit { | |||||||
|      * @param {NavController} [navCtrl] NavController. |      * @param {NavController} [navCtrl] NavController. | ||||||
|      */ |      */ | ||||||
|     protected defaultAction(siteId: string, navCtrl?: NavController): void { |     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. |      * @return {Promise<any>} Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     handleClick(notification: any): Promise<any> { |     handleClick(notification: any): Promise<any> { | ||||||
|         return this.notificationsProvider.invalidateNotificationsList(notification.site).catch(() => { |         let promise; | ||||||
|             // Ignore errors.
 | 
 | ||||||
|         }).then(() => { |         // Try to handle the appurl first.
 | ||||||
|             return this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site); |         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