From 2dabb6e1b2403b90acf305d5add639bcaab5c5d2 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 27 Nov 2020 11:38:32 +0100 Subject: [PATCH] MOBILE-3523 tags: Fix click tags in forum --- src/addon/mod/forum/providers/forum.ts | 36 ++++++++++++++----- .../tag/components/list/core-tag-list.html | 2 +- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/addon/mod/forum/providers/forum.ts b/src/addon/mod/forum/providers/forum.ts index a758f22f2..a9d92f53a 100644 --- a/src/addon/mod/forum/providers/forum.ts +++ b/src/addon/mod/forum/providers/forum.ts @@ -25,6 +25,7 @@ import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper'; import { AddonModForumOfflineProvider } from './offline'; import { CoreRatingInfo } from '@core/rating/providers/rating'; import { CoreCourseCommonModWSOptions } from '@core/course/providers/course'; +import { CoreUrlUtils } from '@providers/utils/url'; /** * Service that provides some features for forums. @@ -539,15 +540,7 @@ export class AddonModForumProvider { unread: !post.postread, isprivatereply: !!post.isprivatereply, - tags: (post.tags || []).map((tag) => { - return { - id: tag.taginstanceid, - tagid: tag.id, - isstandard: tag.isstandard, - displayname: tag.rawname, - flag: !!tag.flag, - }; - }), + tags: post.tags, }; if (post.groupname) { @@ -557,6 +550,29 @@ export class AddonModForumProvider { return newPost; }); }; + // For some reason, the new WS doesn't use the tags exporter so it returns a different format than other WebServices. + // Convert the new format to the exporter one so it's the same as in other WebServices. + const translateTagsFormatToLegacy = (posts: any[]): any[] => { + posts.forEach((post) => { + post.tags = post.tags.map((tag) => { + const viewUrl = (tag.urls && tag.urls.view) || ''; + const params = CoreUrlUtils.instance.extractUrlParams(viewUrl); + + return { + id: tag.tagid, + taginstanceid: tag.id, + flag: tag.flag ? 1 : 0, + isstandard: tag.isstandard, + rawname: tag.displayname, + name: tag.displayname, + tagcollid: params.tc ? Number(params.tc) : undefined, + taginstancecontextid: params.from ? Number(params.from) : undefined, + }; + }); + }); + + return posts; + }; const params = { discussionid: discussionId, @@ -577,6 +593,8 @@ export class AddonModForumProvider { if (wsName == 'mod_forum_get_forum_discussion_posts') { response.posts = translateLegacyPostsFormat(response.posts); + } else { + response.posts = translateTagsFormatToLegacy(response.posts); } this.storeUserData(response.posts); diff --git a/src/core/tag/components/list/core-tag-list.html b/src/core/tag/components/list/core-tag-list.html index 60035d009..7e6372e20 100644 --- a/src/core/tag/components/list/core-tag-list.html +++ b/src/core/tag/components/list/core-tag-list.html @@ -1,3 +1,3 @@ - {{ tag.displayname }} + {{ tag.rawname }}