forked from CIT/Vmeda.Online
		
	MOBILE-2919 forum: Handle forum discussion notification clicks
This commit is contained in:
		
							parent
							
								
									6e054bf6cd
								
							
						
					
					
						commit
						8b2ed818fa
					
				| @ -1,4 +1,4 @@ | |||||||
| <ion-card-header text-wrap no-padding > | <ion-card-header text-wrap no-padding id="addon-mod_forum-post-{{post.id}}"> | ||||||
|     <ion-item text-wrap> |     <ion-item text-wrap> | ||||||
|         <ion-avatar core-user-avatar [user]="post" item-start (click)="openUserProfile(post.userid)"></ion-avatar> |         <ion-avatar core-user-avatar [user]="post" item-start (click)="openUserProfile(post.userid)"></ion-avatar> | ||||||
|         <h2><span [class.core-bold]="post.parent == 0"><core-format-text [text]="post.subject"></core-format-text></span></h2> |         <h2><span [class.core-bold]="post.parent == 0"><core-format-text [text]="post.subject"></core-format-text></span></h2> | ||||||
|  | |||||||
| @ -76,6 +76,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { | |||||||
|     cmId: number; |     cmId: number; | ||||||
| 
 | 
 | ||||||
|     protected forumId: number; |     protected forumId: number; | ||||||
|  |     protected postId: number; | ||||||
|     protected onlineObserver: any; |     protected onlineObserver: any; | ||||||
|     protected syncObserver: any; |     protected syncObserver: any; | ||||||
|     protected syncManualObserver: any; |     protected syncManualObserver: any; | ||||||
| @ -107,6 +108,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { | |||||||
|         this.discussionId = navParams.get('discussionId'); |         this.discussionId = navParams.get('discussionId'); | ||||||
|         this.trackPosts = navParams.get('trackPosts'); |         this.trackPosts = navParams.get('trackPosts'); | ||||||
|         this.locked = navParams.get('locked'); |         this.locked = navParams.get('locked'); | ||||||
|  |         this.postId = navParams.get('postId'); | ||||||
| 
 | 
 | ||||||
|         this.isOnline = this.appProvider.isOnline(); |         this.isOnline = this.appProvider.isOnline(); | ||||||
|         this.onlineObserver = network.onchange().subscribe((online) => { |         this.onlineObserver = network.onchange().subscribe((online) => { | ||||||
| @ -124,7 +126,14 @@ export class AddonModForumDiscussionPage implements OnDestroy { | |||||||
|      * View loaded. |      * View loaded. | ||||||
|      */ |      */ | ||||||
|     ionViewDidLoad(): void { |     ionViewDidLoad(): void { | ||||||
|         this.fetchPosts(true, false, true); |         this.fetchPosts(true, false, true).then(() => { | ||||||
|  |             if (this.postId) { | ||||||
|  |                 // Scroll to the post.
 | ||||||
|  |                 setTimeout(() => { | ||||||
|  |                     this.domUtils.scrollToElementBySelector(this.content, '#addon-mod_forum-post-' + this.postId); | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -24,8 +24,10 @@ import { CoreSettingsDelegate } from '@core/settings/providers/delegate'; | |||||||
| import { CoreCronDelegate } from '@providers/cron'; | import { CoreCronDelegate } from '@providers/cron'; | ||||||
| import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; | import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; | ||||||
| import { CoreSitesProvider } from '@providers/sites'; | import { CoreSitesProvider } from '@providers/sites'; | ||||||
|  | import { CoreUrlUtilsProvider } from '@providers/utils/url'; | ||||||
| import { CoreUtilsProvider } from '@providers/utils/utils'; | import { CoreUtilsProvider } from '@providers/utils/utils'; | ||||||
| import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; | import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; | ||||||
|  | import { AddonModForumProvider } from '@addon/mod/forum/providers/forum'; | ||||||
| 
 | 
 | ||||||
| // List of providers (without handlers).
 | // List of providers (without handlers).
 | ||||||
| export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [ | export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [ | ||||||
| @ -50,12 +52,44 @@ export class AddonNotificationsModule { | |||||||
|             cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone, |             cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone, | ||||||
|             appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider, |             appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider, | ||||||
|             notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider, |             notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider, | ||||||
|             linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate) { |             linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate, | ||||||
|  |             urlUtils: CoreUrlUtilsProvider, forumProvider: AddonModForumProvider) { | ||||||
|  | 
 | ||||||
|         mainMenuDelegate.registerHandler(mainMenuHandler); |         mainMenuDelegate.registerHandler(mainMenuHandler); | ||||||
|         settingsDelegate.registerHandler(settingsHandler); |         settingsDelegate.registerHandler(settingsHandler); | ||||||
|         cronDelegate.register(cronHandler); |         cronDelegate.register(cronHandler); | ||||||
| 
 | 
 | ||||||
|         const notificationClicked = (notification: any): void => { |         const notificationClicked = (notification: any): void => { | ||||||
|  | 
 | ||||||
|  |             // Temporary fix to make forum notifications work. This will be improved in next release.
 | ||||||
|  |             if (notification.moodlecomponent == 'mod_forum' && notification.name == 'posts') { | ||||||
|  |                 sitesProvider.isFeatureDisabled('CoreCourseModuleDelegate_AddonModForum', notification.site).then((disabled) => { | ||||||
|  |                     if (disabled) { | ||||||
|  |                         // Forum is disabled, stop.
 | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     const contextUrlParams = urlUtils.extractUrlParams(notification.contexturl), | ||||||
|  |                         pageParams: any = { | ||||||
|  |                             courseId: Number(notification.courseid), | ||||||
|  |                             discussionId: Number(contextUrlParams.d), | ||||||
|  |                         }; | ||||||
|  | 
 | ||||||
|  |                     if (contextUrlParams.urlHash) { | ||||||
|  |                         pageParams.postId = Number(contextUrlParams.urlHash.replace('p', '')); | ||||||
|  |                     } | ||||||
|  | 
 | ||||||
|  |                     forumProvider.invalidateDiscussionPosts(pageParams.discussionId).catch(() => { | ||||||
|  |                         // Ignore errors.
 | ||||||
|  |                     }).then(() => { | ||||||
|  |                         linkHelper.goInSite(undefined, 'AddonModForumDiscussionPage', pageParams, notification.site); | ||||||
|  |                     }); | ||||||
|  |                 }); | ||||||
|  |             } else { | ||||||
|  |                 goToNotifications(notification); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|  |         const goToNotifications = (notification: any): void => { | ||||||
|             sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => { |             sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => { | ||||||
|                 if (disabled) { |                 if (disabled) { | ||||||
|                     // Notifications are disabled, stop.
 |                     // Notifications are disabled, stop.
 | ||||||
|  | |||||||
| @ -52,14 +52,23 @@ export class CoreUrlUtilsProvider { | |||||||
|      */ |      */ | ||||||
|     extractUrlParams(url: string): any { |     extractUrlParams(url: string): any { | ||||||
|         const regex = /[?&]+([^=&]+)=?([^&]*)?/gi, |         const regex = /[?&]+([^=&]+)=?([^&]*)?/gi, | ||||||
|             params = {}; |             params: any = {}, | ||||||
|  |             urlAndHash = url.split('#'); | ||||||
| 
 | 
 | ||||||
|         url.replace(regex, (match: string, key: string, value: string): string => { |         urlAndHash[0].replace(regex, (match: string, key: string, value: string): string => { | ||||||
|             params[key] = typeof value != 'undefined' ? value : ''; |             params[key] = typeof value != 'undefined' ? value : ''; | ||||||
| 
 | 
 | ||||||
|             return match; |             return match; | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|  |         if (urlAndHash.length > 1) { | ||||||
|  |             // Remove the URL from the array.
 | ||||||
|  |             urlAndHash.shift(); | ||||||
|  | 
 | ||||||
|  |             // Add the hash as a param with a special name. Use a join in case there is more than one #.
 | ||||||
|  |             params.urlHash = urlAndHash.join('#'); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         return params; |         return params; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user