MOBILE-3218 forum: Discussions link only works from notifications

main
Pau Ferrer Ocaña 2019-11-29 13:48:12 +01:00
parent ce602321ff
commit 22ab48800e
2 changed files with 31 additions and 8 deletions

View File

@ -191,8 +191,8 @@ export class AddonModForumDiscussionPage implements OnDestroy {
}); });
this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => { this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => {
if ((this.forum && this.forum.id === data.forumId) || data.cmId === this.cmId) { if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) {
this.forumProvider.invalidateDiscussionsList(this.forum.id).finally(() => { this.forumProvider.invalidateDiscussionsList(this.forumId).finally(() => {
if (typeof data.locked != 'undefined') { if (typeof data.locked != 'undefined') {
this.discussion.locked = data.locked; this.discussion.locked = data.locked;
} }
@ -350,7 +350,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
const promises = []; const promises = [];
promises.push(this.forumProvider.getAccessInformation(this.forum.id).then((accessInfo) => { promises.push(this.forumProvider.getAccessInformation(this.forumId).then((accessInfo) => {
this.accessInfo = accessInfo; this.accessInfo = accessInfo;
// Disallow replying if cut-off date is reached and the user has not the capability to override it. // 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. // Fetch the discussion if not passed as parameter.
if (!this.discussion) { if (!this.discussion) {
promises.push(this.forumHelper.getDiscussionById(forum.id, this.discussionId).then((discussion) => { promises.push(this.loadDiscussion(this.forumId, this.discussionId));
this.discussion = discussion;
}).catch(() => {
// Ignore errors.
}));
} }
return Promise.all(promises); 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<void> {
// 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. * Tries to synchronize the posts discussion.
* *

View File

@ -45,6 +45,12 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
data = data || {}; data = data || {};
if (!data.instance) {
// Without the forumId discussions cannot be loaded (from link).
return [];
}
return [{ return [{
action: (siteId, navCtrl?): void => { action: (siteId, navCtrl?): void => {
const pageParams: any = { const pageParams: any = {