MOBILE-4522 forum: Don't calculate unread number if tracking disabled
parent
99dcbd9590
commit
e84a2ee78c
|
@ -2134,3 +2134,12 @@ export type AddonModForumMarkReadData = {
|
||||||
courseId: number;
|
courseId: number;
|
||||||
moduleId: number;
|
moduleId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracking options.
|
||||||
|
*/
|
||||||
|
export const enum AddonModForumTracking {
|
||||||
|
OFF = 0,
|
||||||
|
OPTIONAL = 1,
|
||||||
|
FORCED = 2,
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable, Type } from '@angular/core';
|
import { Injectable, Type } from '@angular/core';
|
||||||
import { AddonModForum, AddonModForumProvider } from '../forum';
|
import { AddonModForum, AddonModForumProvider, AddonModForumTracking } from '../forum';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
|
@ -21,6 +21,8 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/
|
||||||
import { CoreConstants, ModPurpose } from '@/core/constants';
|
import { CoreConstants, ModPurpose } from '@/core/constants';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
||||||
import { CoreCourseModuleData } from '@features/course/services/course-helper';
|
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.
|
* Handler to support forum modules.
|
||||||
|
@ -55,6 +57,29 @@ export class AddonModForumModuleHandlerService extends CoreModuleHandlerBase imp
|
||||||
async getData(module: CoreCourseModuleData, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
async getData(module: CoreCourseModuleData, courseId: number): Promise<CoreCourseModuleHandlerData> {
|
||||||
const data = await super.getData(module, courseId);
|
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) {
|
if ('afterlink' in module && !!module.afterlink) {
|
||||||
const match = />(\d+)[^<]+/.exec(module.afterlink);
|
const match = />(\d+)[^<]+/.exec(module.afterlink);
|
||||||
data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
|
data.extraBadge = match ? Translate.instant('addon.mod_forum.unreadpostsnumber', { $a : match[1] }) : '';
|
||||||
|
|
|
@ -966,6 +966,7 @@ export type CoreUserData = {
|
||||||
theme?: string; // Theme name such as "standard", must exist on server.
|
theme?: string; // Theme name such as "standard", must exist on server.
|
||||||
timezone?: string; // Timezone code such as Australia/Perth, or 99 for default.
|
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.
|
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.
|
description?: string; // User profile description.
|
||||||
descriptionformat?: number; // Int format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
|
descriptionformat?: number; // Int format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
|
||||||
city?: string; // Home city of the user.
|
city?: string; // Home city of the user.
|
||||||
|
|
Loading…
Reference in New Issue