diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index 6d47d6db9..bbeca74e6 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -191,8 +191,8 @@ export class AddonModForumDiscussionPage implements OnDestroy { }); this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => { - if ((this.forum && this.forum.id === data.forumId) || data.cmId === this.cmId) { - this.forumProvider.invalidateDiscussionsList(this.forum.id).finally(() => { + if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) { + this.forumProvider.invalidateDiscussionsList(this.forumId).finally(() => { if (typeof data.locked != 'undefined') { this.discussion.locked = data.locked; } @@ -350,7 +350,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { const promises = []; - promises.push(this.forumProvider.getAccessInformation(this.forum.id).then((accessInfo) => { + promises.push(this.forumProvider.getAccessInformation(this.forumId).then((accessInfo) => { this.accessInfo = accessInfo; // Disallow replying if cut-off date is reached and the user has not the capability to override it. @@ -364,11 +364,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { // Fetch the discussion if not passed as parameter. if (!this.discussion) { - promises.push(this.forumHelper.getDiscussionById(forum.id, this.discussionId).then((discussion) => { - this.discussion = discussion; - }).catch(() => { - // Ignore errors. - })); + promises.push(this.loadDiscussion(this.forumId, this.discussionId)); } return Promise.all(promises); @@ -434,6 +430,27 @@ export class AddonModForumDiscussionPage implements OnDestroy { }); } + /** + * Convenience function to load discussion. + * + * @param forumId Forum ID. + * @param discussionId Discussion ID. + * @return Promise resolved when done. + */ + protected loadDiscussion(forumId: number, discussionId: number): Promise { + // Fetch the discussion if not passed as parameter. + if (!this.discussion && forumId) { + return this.forumHelper.getDiscussionById(forumId, discussionId).then((discussion) => { + this.discussion = discussion; + this.discussionId = this.discussion.discussion; + }).catch(() => { + // Ignore errors. + }); + } + + return Promise.resolve(); + } + /** * Tries to synchronize the posts discussion. * diff --git a/src/addon/mod/forum/providers/discussion-link-handler.ts b/src/addon/mod/forum/providers/discussion-link-handler.ts index 243a1d09d..67e87c4cd 100644 --- a/src/addon/mod/forum/providers/discussion-link-handler.ts +++ b/src/addon/mod/forum/providers/discussion-link-handler.ts @@ -45,6 +45,12 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB CoreContentLinksAction[] | Promise { data = data || {}; + if (!data.instance) { + // Without the forumId discussions cannot be loaded (from link). + + return []; + } + return [{ action: (siteId, navCtrl?): void => { const pageParams: any = {