Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 1 | import StatesExtraInfoService from './states.js'; |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 2 | |
| 3 | export 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ínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 13 | const endPendingStateTimestampMicros = thread?.['2']?.['39']; |
| 14 | const [pendingStateInfo, pendingTooltip] = |
| 15 | StatesExtraInfoService.getPendingStateChip( |
| 16 | endPendingStateTimestampMicros); |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 17 | if (pendingStateInfo) chips.push(pendingStateInfo); |
| 18 | if (pendingTooltip) tooltips.push(pendingTooltip); |
| 19 | |
| 20 | chips.push(...this.getTrendingChips(thread)); |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 21 | |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 22 | const itemMetadata = thread?.['2']?.['12']; |
| 23 | chips.push(...StatesExtraInfoService.getMetadataChips(itemMetadata)); |
| 24 | |
| 25 | const liveReviewStatus = thread?.['2']?.['38']; |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 26 | const [liveReviewInfo, liveReviewTooltip] = |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 27 | StatesExtraInfoService.getLiveReviewStatusChip(liveReviewStatus); |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 28 | if (liveReviewInfo) chips.push(liveReviewInfo); |
| 29 | if (liveReviewTooltip) tooltips.push(liveReviewTooltip); |
| 30 | |
| 31 | return [chips, tooltips]; |
| 32 | } |
| 33 | |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 34 | 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ínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 49 | 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 | } |