blob: 2ba911cba05b4b4644cb4a7f8eb5619343c4d9dd [file] [log] [blame]
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +01001import {kAbuseCategories, kAbuseViolationCategories, kAbuseViolationCategoriesI18n, kAbuseViolationTypes} from '../consts.js';
2
3import BaseExtraInfoInjection from './base.js';
4
5export default class ProfileAbuseExtraInfoInjection extends
6 BaseExtraInfoInjection {
7 constructor(infoHandler, optionsWatcher) {
8 super(infoHandler, optionsWatcher);
9 this.unifiedUserView = undefined;
10 }
11
12 inject(profileInfo, injectionDetails) {
13 this.unifiedUserView = profileInfo.body?.['1'];
14 const chips = this.getChips();
15 this.addExtraInfoChips(
16 chips, injectionDetails.card, /* withContainer = */ true);
17 }
18
19 getChips() {
20 const chips = [
21 this.getGeneralAbuseViolationCategoryChip(),
22 ...this.getProfileAbuseChips(),
23 this.getAppealCountChip(),
24 ];
25
26 return chips.filter(chip => chip !== null);
27 }
28
29 getGeneralAbuseViolationCategoryChip() {
30 const abuseViolationCategory = this.unifiedUserView?.['6'];
31 if (!abuseViolationCategory) return null;
32 return this.getAbuseViolationCategoryChipContent(abuseViolationCategory);
33 }
34
35 getProfileAbuseChips() {
36 return kAbuseCategories
37 .map(category => {
38 return this.getProfileAbuseCategoryChip(category);
39 })
40 .filter(chip => chip !== null);
41 }
42
43 getAppealCountChip() {
44 const profileAbuse = this.unifiedUserView?.['1']?.['8'];
45 const appealCount = profileAbuse?.['4'];
46 if (appealCount === undefined) return null;
47
48 return chrome.i18n.getMessage(
49 'inject_extrainfo_profile_appealsnum', [appealCount]);
50 }
51
52 getAbuseViolationCategoryChipContent(abuseViolationCategory) {
53 const content = document.createElement('span');
54
55 const categoryI18nKey = 'inject_extrainfo_profile_abusecategory_' +
56 kAbuseViolationCategoriesI18n[abuseViolationCategory];
57 const categoryLocalized =
58 chrome.i18n.getMessage(categoryI18nKey) ?? abuseViolationCategory;
59 content.textContent = chrome.i18n.getMessage(
60 'inject_extrainfo_profile_abusecategory', [categoryLocalized]);
61
62 content.title = kAbuseViolationCategories[abuseViolationCategory] ??
63 abuseViolationCategory;
64
65 return content;
66 }
67
68 getProfileAbuseCategoryChip(abuseCategory) {
69 const [protoIndex, category] = abuseCategory;
70 const profileAbuse = this.unifiedUserView?.['1']?.['8'];
71 const violation = profileAbuse?.[protoIndex]?.['1']?.['1'];
72 if (!violation) return null;
73
74 return chrome.i18n.getMessage(
75 'inject_extrainfo_profile_abuse_' + category,
76 [kAbuseViolationTypes[violation]]);
77 }
78}