blob: c36dfa53455cd968237dbd940a02ad3901f87dd3 [file] [log] [blame]
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +01001import StatesExtraInfoService from './states.js';
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +01002
3export default class ThreadExtraInfoService {
4 /**
5 * Get a |chipContentList| array with the chips related to the thread, and a
6 * |tooltips| array with the corresponding tooltips which should be
7 * initialized after the chips are added to the DOM.
8 */
9 static getThreadChips(thread) {
10 let chips = [];
11 let tooltips = [];
12
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010013 const endPendingStateTimestampMicros = thread?.['2']?.['39'];
14 const [pendingStateInfo, pendingTooltip] =
15 StatesExtraInfoService.getPendingStateChip(
16 endPendingStateTimestampMicros);
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010017 if (pendingStateInfo) chips.push(pendingStateInfo);
18 if (pendingTooltip) tooltips.push(pendingTooltip);
19
20 chips.push(...this.getTrendingChips(thread));
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010021
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010022 const itemMetadata = thread?.['2']?.['12'];
23 chips.push(...StatesExtraInfoService.getMetadataChips(itemMetadata));
24
25 const liveReviewStatus = thread?.['2']?.['38'];
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010026 const [liveReviewInfo, liveReviewTooltip] =
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010027 StatesExtraInfoService.getLiveReviewStatusChip(liveReviewStatus);
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010028 if (liveReviewInfo) chips.push(liveReviewInfo);
29 if (liveReviewTooltip) tooltips.push(liveReviewTooltip);
30
31 return [chips, tooltips];
32 }
33
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010034 static getTrendingChips(thread) {
35 const chips = [];
36
37 const isTrending = thread?.['2']?.['25'];
38 const isTrendingAutoMarked = thread?.['39'];
39 if (isTrendingAutoMarked)
40 chips.push(document.createTextNode(
41 chrome.i18n.getMessage('inject_extrainfo_thread_autotrending')));
42 else if (isTrending)
43 chips.push(document.createTextNode(
44 chrome.i18n.getMessage('inject_extrainfo_thread_trending')));
45
46 return chips;
47 }
48
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010049 static getThreadFromThreadList(threadList, currentThreadInfo) {
50 return threadList?.find?.(thread => {
51 const threadInfo = thread?.['2']?.['1'];
52 const threadId = threadInfo?.['1'];
53 const forumId = threadInfo?.['3'];
54 return threadId == currentThreadInfo.thread &&
55 forumId == currentThreadInfo.forum;
56 });
57 }
58}