@@ -24,8 +24,10 @@ import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
2424import { CoreCronDelegate } from '@providers/cron' ;
2525import { CoreLocalNotificationsProvider } from '@providers/local-notifications' ;
2626import { CoreSitesProvider } from '@providers/sites' ;
27+ import { CoreUrlUtilsProvider } from '@providers/utils/url' ;
2728import { CoreUtilsProvider } from '@providers/utils/utils' ;
2829import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate' ;
30+ import { AddonModForumProvider } from '@addon/mod/forum/providers/forum' ;
2931
3032// List of providers (without handlers).
3133export const ADDON_NOTIFICATIONS_PROVIDERS : any [ ] = [
@@ -50,12 +52,44 @@ export class AddonNotificationsModule {
5052 cronDelegate : CoreCronDelegate , cronHandler : AddonNotificationsCronHandler , zone : NgZone ,
5153 appProvider : CoreAppProvider , utils : CoreUtilsProvider , sitesProvider : CoreSitesProvider ,
5254 notificationsProvider : AddonNotificationsProvider , localNotifications : CoreLocalNotificationsProvider ,
53- linkHelper : CoreContentLinksHelperProvider , pushNotificationsDelegate : AddonPushNotificationsDelegate ) {
55+ linkHelper : CoreContentLinksHelperProvider , pushNotificationsDelegate : AddonPushNotificationsDelegate ,
56+ urlUtils : CoreUrlUtilsProvider , forumProvider : AddonModForumProvider ) {
57+
5458 mainMenuDelegate . registerHandler ( mainMenuHandler ) ;
5559 settingsDelegate . registerHandler ( settingsHandler ) ;
5660 cronDelegate . register ( cronHandler ) ;
5761
5862 const notificationClicked = ( notification : any ) : void => {
63+
64+ // Temporary fix to make forum notifications work. This will be improved in next release.
65+ if ( notification . moodlecomponent == 'mod_forum' && notification . name == 'posts' ) {
66+ sitesProvider . isFeatureDisabled ( 'CoreCourseModuleDelegate_AddonModForum' , notification . site ) . then ( ( disabled ) => {
67+ if ( disabled ) {
68+ // Forum is disabled, stop.
69+ return ;
70+ }
71+
72+ const contextUrlParams = urlUtils . extractUrlParams ( notification . contexturl ) ,
73+ pageParams : any = {
74+ courseId : Number ( notification . courseid ) ,
75+ discussionId : Number ( contextUrlParams . d ) ,
76+ } ;
77+
78+ if ( contextUrlParams . urlHash ) {
79+ pageParams . postId = Number ( contextUrlParams . urlHash . replace ( 'p' , '' ) ) ;
80+ }
81+
82+ forumProvider . invalidateDiscussionPosts ( pageParams . discussionId ) . catch ( ( ) => {
83+ // Ignore errors.
84+ } ) . then ( ( ) => {
85+ linkHelper . goInSite ( undefined , 'AddonModForumDiscussionPage' , pageParams , notification . site ) ;
86+ } ) ;
87+ } ) ;
88+ } else {
89+ goToNotifications ( notification ) ;
90+ }
91+ } ;
92+ const goToNotifications = ( notification : any ) : void => {
5993 sitesProvider . isFeatureDisabled ( 'CoreMainMenuDelegate_AddonNotifications' , notification . site ) . then ( ( disabled ) => {
6094 if ( disabled ) {
6195 // Notifications are disabled, stop.
0 commit comments