Skip to content

Commit

Permalink
Merge pull request #3991 from dpalou/MOBILE-4522
Browse files Browse the repository at this point in the history
Mobile 4522
  • Loading branch information
alfonso-salces authored Mar 26, 2024
2 parents 7aac07a + e84a2ee commit a8b4a00
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/addons/mod/forum/pages/discussion/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
});
}

if (!this.courseId || !this.cmId) {
if (!this.courseId || !this.cmId || !this.trackPosts) {
return;
}

Expand Down
9 changes: 9 additions & 0 deletions src/addons/mod/forum/services/forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2134,3 +2134,12 @@ export type AddonModForumMarkReadData = {
courseId: number;
moduleId: number;
};

/**
* Tracking options.
*/
export const enum AddonModForumTracking {
OFF = 0,
OPTIONAL = 1,
FORCED = 2,
}
27 changes: 26 additions & 1 deletion src/addons/mod/forum/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
// limitations under the License.

import { Injectable, Type } from '@angular/core';
import { AddonModForum, AddonModForumProvider } from '../forum';
import { AddonModForum, AddonModForumProvider, AddonModForumTracking } from '../forum';
import { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
import { CoreConstants, ModPurpose } from '@/core/constants';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUser } from '@features/user/services/user';

/**
* Handler to support forum modules.
Expand Down Expand Up @@ -55,6 +57,29 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
async getData(module: CoreCourseModuleData, courseId: number): Promise<CoreCourseModuleHandlerData> {
const data = await super.getData(module, courseId);

const customData = module.customdata ?
CoreTextUtils.parseJSON<{ trackingtype?: string | number } | ''>(module.customdata, {}) : {};
const trackingType = typeof customData !== 'string' && customData.trackingtype !== undefined ?
Number(customData.trackingtype) : undefined;

if (trackingType === AddonModForumTracking.OFF) {
// Tracking is disabled in forum.
data.extraBadge = '';

return data;
}

if (trackingType === AddonModForumTracking.OPTIONAL) {
// Forum has tracking optional, check if user has tracking enabled.
const user = await CoreUser.getProfile(CoreSites.getCurrentSiteUserId());

if (user.trackforums === 0) {
data.extraBadge = '';

return data;
}
}

if ('afterlink' in module && !!module.afterlink) {
const match = />(\d+)[^<]+/.exec(module.afterlink);
data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
Expand Down
1 change: 1 addition & 0 deletions src/core/features/user/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ export type CoreUserData = {
theme?: string; // Theme name such as "standard", must exist on server.
timezone?: string; // Timezone code such as Australia/Perth, or 99 for default.
mailformat?: number; // Mail format code is 0 for plain text, 1 for HTML etc.
trackforums?: number; // @since 4.4. Whether the user is tracking forums.
description?: string; // User profile description.
descriptionformat?: number; // Int format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
city?: string; // Home city of the user.
Expand Down

0 comments on commit a8b4a00

Please sign in to comment.