MOBILE-3519 forum: Use forumid and courseid from WS

main
Pau Ferrer Ocaña 2020-08-31 12:28:03 +02:00
parent 4d8697a601
commit 6c894a8abe
2 changed files with 9 additions and 6 deletions

View File

@ -331,6 +331,8 @@ export class AddonModForumDiscussionPage implements OnDestroy {
return this.forumProvider.getDiscussionPosts(this.discussionId, this.cmId).then((response) => {
onlinePosts = response.posts;
ratingInfo = response.ratinginfo;
this.courseId = response.courseid;
this.forumId = response.forumid;
}).then(() => {
// Check if there are responses stored in offline.
return this.forumOffline.getDiscussionReplies(this.discussionId).then((replies) => {
@ -371,17 +373,13 @@ export class AddonModForumDiscussionPage implements OnDestroy {
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 (this.sort == 'nested') {
// Sort first by creation date to make format tree work.
this.forumProvider.sortDiscussionPosts(posts, 'ASC');
posts = this.utils.formatTree(posts, 'parent', 'id', this.discussion.id);
posts = this.utils.formatTree(posts, 'parent', 'id', this.discussion ? this.discussion.id : startingPost.id);
} else {
// Set default reply subject.
const direction = this.sort == 'flat-newest' ? 'DESC' : 'ASC';
@ -424,6 +422,10 @@ export class AddonModForumDiscussionPage implements OnDestroy {
}).catch(() => {
// Ignore errors.
}).then(() => {
if (startingPost) {
// Update discussion data from first post.
this.discussion = Object.assign(this.discussion || {}, startingPost);
}
if (!this.discussion) {
// The discussion object was not passed as parameter and there is no starting post. Should not happen.

View File

@ -496,7 +496,8 @@ export class AddonModForumProvider {
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved with forum posts and rating info.
*/
getDiscussionPosts(discussionId: number, cmId: number, siteId?: string): Promise<{posts: any[], ratinginfo?: CoreRatingInfo}> {
getDiscussionPosts(discussionId: number, cmId: number, siteId?: string): Promise<{posts: any[], courseid?: number,
forumid?: number, ratinginfo?: CoreRatingInfo}> {
const params = {
discussionid: discussionId
};