From 05ae8ada14d2ca81c435c8cc52391dd0d93a5a3c Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 1 Mar 2021 17:07:57 +0100 Subject: [PATCH] MOBILE-3643 forum: Fix discussion-link handler --- src/addons/mod/forum/components/index/index.ts | 5 +++-- src/addons/mod/forum/forum.module.ts | 12 ++++++++---- .../mod/forum/pages/discussion/discussion.page.ts | 9 +++++++-- .../mod/forum/services/handlers/discussion-link.ts | 11 ++++++----- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/addons/mod/forum/components/index/index.ts b/src/addons/mod/forum/components/index/index.ts index cd9f4301e..9e215fdec 100644 --- a/src/addons/mod/forum/components/index/index.ts +++ b/src/addons/mod/forum/components/index/index.ts @@ -49,6 +49,7 @@ import { AddonModForumSortOrderSelectorComponent } from '../sort-order-selector/ import { CoreScreen } from '@services/screen'; import { CoreArray } from '@singletons/array'; import { AddonModForumPrefetchHandler } from '../../services/handlers/prefetch'; +import { AddonModForumModuleHandlerService } from '../../services/handlers/module'; /** * Component that displays a forum entry page. @@ -101,7 +102,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom this.discussions = new AddonModForumDiscussionsManager( route.component, this, - courseContentsPage ? 'mod_forum/' : '', + courseContentsPage ? `${AddonModForumModuleHandlerService.PAGE_NAME}/` : '', ); } @@ -784,7 +785,7 @@ class AddonModForumDiscussionsManager extends CorePageItemsListManager { if (this.isOnlineDiscussion(discussion)) { - return discussion.id; + return discussion.discussion; } if (this.isOfflineDiscussion(discussion)) { diff --git a/src/addons/mod/forum/forum.module.ts b/src/addons/mod/forum/forum.module.ts index d829982ba..a3c602250 100644 --- a/src/addons/mod/forum/forum.module.ts +++ b/src/addons/mod/forum/forum.module.ts @@ -40,6 +40,10 @@ import { CorePushNotificationsDelegate } from '@features/pushnotifications/servi import { AddonModForumPushClickHandler } from './services/handlers/push-click'; const mainMenuRoutes: Routes = [ + { + path: `${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/:discussionId`, + loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule), + }, { path: AddonModForumModuleHandlerService.PAGE_NAME, loadChildren: () => import('./forum-lazy.module').then(m => m.AddonModForumLazyModule), @@ -47,12 +51,12 @@ const mainMenuRoutes: Routes = [ ...conditionalRoutes( [ { - path: 'course/index/contents/mod_forum/new/:timeCreated', + path: `course/index/contents/${AddonModForumModuleHandlerService.PAGE_NAME}/new/:timeCreated`, loadChildren: () => import('./pages/new-discussion/new-discussion.module') .then(m => m.AddonForumNewDiscussionPageModule), }, { - path: 'course/index/contents/mod_forum/:discussionId', + path: `course/index/contents/${AddonModForumModuleHandlerService.PAGE_NAME}/:discussionId`, loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule), }, ], @@ -63,12 +67,12 @@ const mainMenuRoutes: Routes = [ const courseContentsRoutes: Routes = conditionalRoutes( [ { - path: 'mod_forum/new/:timeCreated', + path: `${AddonModForumModuleHandlerService.PAGE_NAME}/new/:timeCreated`, loadChildren: () => import('./pages/new-discussion/new-discussion.module') .then(m => m.AddonForumNewDiscussionPageModule), }, { - path: 'mod_forum/:discussionId', + path: `${AddonModForumModuleHandlerService.PAGE_NAME}/:discussionId`, loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule), }, ], diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index 23f29d6e7..16cf9a311 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -163,12 +163,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes /** * User entered the page that contains the component. */ - ionViewDidEnter(): void { + async ionViewDidEnter(): Promise { if (this.syncObserver) { // Already setup. return; } + // The discussion object was not passed as parameter. + if (!this.discussion) { + await this.loadDiscussion(this.forumId, this.cmId, this.discussionId); + } + // Refresh data if this discussion is synchronized automatically. this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => { if (data.forumId == this.forumId && this.discussionId == data.discussionId @@ -432,7 +437,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes }), ); - // The discussion object was not passed as parameter and there is no starting post. Should not happen. + // The discussion object was not passed as parameter and there is no starting post. if (!this.discussion) { promises.push(this.loadDiscussion(this.forumId, this.cmId, this.discussionId)); } diff --git a/src/addons/mod/forum/services/handlers/discussion-link.ts b/src/addons/mod/forum/services/handlers/discussion-link.ts index ee3c1682d..bc4dc5d2a 100644 --- a/src/addons/mod/forum/services/handlers/discussion-link.ts +++ b/src/addons/mod/forum/services/handlers/discussion-link.ts @@ -54,11 +54,12 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH return [{ action: (siteId): void => { - const cmId = data.cmid && parseInt(data.cmid, 10); const discussionId = parseInt(params.d, 10); - const pageParams: Params = { forumId: data.instance && parseInt(data.instance, 10) }; - - courseId = courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10); + const pageParams: Params = { + forumId: data.instance && parseInt(data.instance, 10), + cmId: data.cmid && parseInt(data.cmid, 10), + courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10), + }; if (data.postid || params.urlHash) { pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); @@ -69,7 +70,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH } CoreNavigator.instance.navigateToSitePath( - `${AddonModForumModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/${discussionId}`, + `${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/${discussionId}`, { siteId, params: pageParams }, ); },