MOBILE-3213 forum: Fix discussion links when nested view is on
parent
6c47098dd8
commit
63bff7c4f8
|
@ -326,10 +326,17 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
let posts = offlineReplies.concat(onlinePosts);
|
let posts = offlineReplies.concat(onlinePosts);
|
||||||
|
|
||||||
|
const startingPost = this.forumProvider.extractStartingPost(posts);
|
||||||
|
if (startingPost) {
|
||||||
|
// Update discussion data from first post.
|
||||||
|
this.discussion = Object.assign(this.discussion || {}, startingPost);
|
||||||
|
}
|
||||||
|
|
||||||
// If sort type is nested, normal sorting is disabled and nested posts will be displayed.
|
// If sort type is nested, normal sorting is disabled and nested posts will be displayed.
|
||||||
if (this.sort == 'nested') {
|
if (this.sort == 'nested') {
|
||||||
// Sort first by creation date to make format tree work.
|
// Sort first by creation date to make format tree work.
|
||||||
this.forumProvider.sortDiscussionPosts(posts, 'ASC');
|
this.forumProvider.sortDiscussionPosts(posts, 'ASC');
|
||||||
|
|
||||||
posts = this.utils.formatTree(posts, 'parent', 'id', this.discussion.id);
|
posts = this.utils.formatTree(posts, 'parent', 'id', this.discussion.id);
|
||||||
} else {
|
} else {
|
||||||
// Set default reply subject.
|
// Set default reply subject.
|
||||||
|
@ -364,7 +371,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Fetch the discussion if not passed as parameter.
|
// The discussion object was not passed as parameter and there is no starting post. Should not happen.
|
||||||
if (!this.discussion) {
|
if (!this.discussion) {
|
||||||
promises.push(this.loadDiscussion(this.forumId, this.discussionId));
|
promises.push(this.loadDiscussion(this.forumId, this.discussionId));
|
||||||
}
|
}
|
||||||
|
@ -373,12 +380,9 @@ export class AddonModForumDiscussionPage implements OnDestroy {
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const startingPost = this.forumProvider.extractStartingPost(posts);
|
|
||||||
if (startingPost) {
|
if (!this.discussion) {
|
||||||
// Update discussion data from first post.
|
// The discussion object was not passed as parameter and there is no starting post. Should not happen.
|
||||||
this.discussion = Object.assign(this.discussion || {}, startingPost);
|
|
||||||
} else if (!this.discussion) {
|
|
||||||
// The discussion object was not passed as parameter and there is no starting post.
|
|
||||||
return Promise.reject('Invalid forum discussion.');
|
return Promise.reject('Invalid forum discussion.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB
|
||||||
return [{
|
return [{
|
||||||
action: (siteId, navCtrl?): void => {
|
action: (siteId, navCtrl?): void => {
|
||||||
const pageParams: any = {
|
const pageParams: any = {
|
||||||
courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10),
|
courseId: courseId || parseInt(params.courseid, 10) || parseInt(params.cid, 10) || undefined,
|
||||||
discussionId: parseInt(params.d, 10),
|
discussionId: parseInt(params.d, 10),
|
||||||
cmId: data.cmid && parseInt(data.cmid, 10),
|
cmId: data.cmid && parseInt(data.cmid, 10),
|
||||||
forumId: data.instance && parseInt(data.instance, 10)
|
forumId: data.instance && parseInt(data.instance, 10)
|
||||||
|
|
|
@ -278,14 +278,9 @@ export class AddonModForumProvider {
|
||||||
* @return Starting post or undefined if not found.
|
* @return Starting post or undefined if not found.
|
||||||
*/
|
*/
|
||||||
extractStartingPost(posts: any[]): any {
|
extractStartingPost(posts: any[]): any {
|
||||||
// Check the last post first, since they'll usually be ordered by create time.
|
const index = posts.findIndex((post) => post.parent == 0);
|
||||||
for (let i = posts.length - 1; i >= 0; i--) {
|
|
||||||
if (posts[i].parent == 0) {
|
|
||||||
return posts.splice(i, 1).pop(); // Remove it from the array.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
return index >= 0 ? posts.splice(index, 1).pop() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue