MOBILE-3643 forum: Fix discussion-link handler

main
Noel De Martin 2021-03-01 17:07:57 +01:00
parent 5d39d8efc9
commit 05ae8ada14
4 changed files with 24 additions and 13 deletions

View File

@ -49,6 +49,7 @@ import { AddonModForumSortOrderSelectorComponent } from '../sort-order-selector/
import { CoreScreen } from '@services/screen'; import { CoreScreen } from '@services/screen';
import { CoreArray } from '@singletons/array'; import { CoreArray } from '@singletons/array';
import { AddonModForumPrefetchHandler } from '../../services/handlers/prefetch'; import { AddonModForumPrefetchHandler } from '../../services/handlers/prefetch';
import { AddonModForumModuleHandlerService } from '../../services/handlers/module';
/** /**
* Component that displays a forum entry page. * Component that displays a forum entry page.
@ -101,7 +102,7 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
this.discussions = new AddonModForumDiscussionsManager( this.discussions = new AddonModForumDiscussionsManager(
route.component, route.component,
this, this,
courseContentsPage ? 'mod_forum/' : '', courseContentsPage ? `${AddonModForumModuleHandlerService.PAGE_NAME}/` : '',
); );
} }
@ -784,7 +785,7 @@ class AddonModForumDiscussionsManager extends CorePageItemsListManager<Discussio
protected getItemPath(discussion: DiscussionItem): string { protected getItemPath(discussion: DiscussionItem): string {
const getRelativePath = () => { const getRelativePath = () => {
if (this.isOnlineDiscussion(discussion)) { if (this.isOnlineDiscussion(discussion)) {
return discussion.id; return discussion.discussion;
} }
if (this.isOfflineDiscussion(discussion)) { if (this.isOfflineDiscussion(discussion)) {

View File

@ -40,6 +40,10 @@ import { CorePushNotificationsDelegate } from '@features/pushnotifications/servi
import { AddonModForumPushClickHandler } from './services/handlers/push-click'; import { AddonModForumPushClickHandler } from './services/handlers/push-click';
const mainMenuRoutes: Routes = [ const mainMenuRoutes: Routes = [
{
path: `${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/:discussionId`,
loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule),
},
{ {
path: AddonModForumModuleHandlerService.PAGE_NAME, path: AddonModForumModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./forum-lazy.module').then(m => m.AddonModForumLazyModule), loadChildren: () => import('./forum-lazy.module').then(m => m.AddonModForumLazyModule),
@ -47,12 +51,12 @@ const mainMenuRoutes: Routes = [
...conditionalRoutes( ...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') loadChildren: () => import('./pages/new-discussion/new-discussion.module')
.then(m => m.AddonForumNewDiscussionPageModule), .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), loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule),
}, },
], ],
@ -63,12 +67,12 @@ const mainMenuRoutes: Routes = [
const courseContentsRoutes: Routes = conditionalRoutes( const courseContentsRoutes: Routes = conditionalRoutes(
[ [
{ {
path: 'mod_forum/new/:timeCreated', path: `${AddonModForumModuleHandlerService.PAGE_NAME}/new/:timeCreated`,
loadChildren: () => import('./pages/new-discussion/new-discussion.module') loadChildren: () => import('./pages/new-discussion/new-discussion.module')
.then(m => m.AddonForumNewDiscussionPageModule), .then(m => m.AddonForumNewDiscussionPageModule),
}, },
{ {
path: 'mod_forum/:discussionId', path: `${AddonModForumModuleHandlerService.PAGE_NAME}/:discussionId`,
loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule), loadChildren: () => import('./pages/discussion/discussion.module').then(m => m.AddonForumDiscussionPageModule),
}, },
], ],

View File

@ -163,12 +163,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
/** /**
* User entered the page that contains the component. * User entered the page that contains the component.
*/ */
ionViewDidEnter(): void { async ionViewDidEnter(): Promise<void> {
if (this.syncObserver) { if (this.syncObserver) {
// Already setup. // Already setup.
return; 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. // Refresh data if this discussion is synchronized automatically.
this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => { this.syncObserver = CoreEvents.on(AddonModForumSyncProvider.AUTO_SYNCED, data => {
if (data.forumId == this.forumId && this.discussionId == data.discussionId 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) { if (!this.discussion) {
promises.push(this.loadDiscussion(this.forumId, this.cmId, this.discussionId)); promises.push(this.loadDiscussion(this.forumId, this.cmId, this.discussionId));
} }

View File

@ -54,11 +54,12 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
return [{ return [{
action: (siteId): void => { action: (siteId): void => {
const cmId = data.cmid && parseInt(data.cmid, 10);
const discussionId = parseInt(params.d, 10); const discussionId = parseInt(params.d, 10);
const pageParams: Params = { forumId: data.instance && parseInt(data.instance, 10) }; const pageParams: Params = {
forumId: data.instance && parseInt(data.instance, 10),
courseId = courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10); cmId: data.cmid && parseInt(data.cmid, 10),
courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10),
};
if (data.postid || params.urlHash) { if (data.postid || params.urlHash) {
pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', '')); pageParams.postId = parseInt(data.postid || params.urlHash.replace('p', ''));
@ -69,7 +70,7 @@ export class AddonModForumDiscussionLinkHandlerService extends CoreContentLinksH
} }
CoreNavigator.instance.navigateToSitePath( CoreNavigator.instance.navigateToSitePath(
`${AddonModForumModuleHandlerService.PAGE_NAME}/${courseId}/${cmId}/${discussionId}`, `${AddonModForumModuleHandlerService.PAGE_NAME}/discussion/${discussionId}`,
{ siteId, params: pageParams }, { siteId, params: pageParams },
); );
}, },