MOBILE-3643 forum: Fix discussion-link handler
parent
5d39d8efc9
commit
05ae8ada14
|
@ -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<Discussio
|
|||
protected getItemPath(discussion: DiscussionItem): string {
|
||||
const getRelativePath = () => {
|
||||
if (this.isOnlineDiscussion(discussion)) {
|
||||
return discussion.id;
|
||||
return discussion.discussion;
|
||||
}
|
||||
|
||||
if (this.isOfflineDiscussion(discussion)) {
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
],
|
||||
|
|
|
@ -163,12 +163,17 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
|
|||
/**
|
||||
* User entered the page that contains the component.
|
||||
*/
|
||||
ionViewDidEnter(): void {
|
||||
async ionViewDidEnter(): Promise<void> {
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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 },
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue