blob: e203e9ebb5f24eac0a51701faff1cca94152bd40 [file] [log] [blame]
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +01001import {MDCTooltip} from '@material/tooltip';
2
3import ThreadModel from '../../../../models/Thread.js';
4import MessageExtraInfoService from '../services/message.js';
5
6import BaseExtraInfoInjection from './base.js';
7
8export default class ThreadMessageExtraInfoInjection extends
9 BaseExtraInfoInjection {
10 inject(threadInfo, injectionDetails) {
11 const messageNode = injectionDetails.messageNode;
12 const message = this.#getMessage(threadInfo, messageNode);
13 const [chips, tooltips] = MessageExtraInfoService.getMessageChips(message);
14 this.#injectChips(chips, messageNode);
15 for (const tooltip of tooltips) new MDCTooltip(tooltip);
16 }
17
18 #getMessage(threadInfo, messageNode) {
19 const thread = new ThreadModel(threadInfo.body?.[1]);
20 const messageId = MessageExtraInfoService.getMessageIdFromNode(messageNode);
21 return MessageExtraInfoService.getMessageFromThreadModel(messageId, thread);
22 }
23
24 #injectChips(chips, messageNode) {
25 const interactionsElement = messageNode.querySelector(
26 '.scTailwindThreadMessageMessageinteractionsroot');
27 if (interactionsElement === null)
28 throw new Error(`Couldn't find interactions element.`);
29
30 this.#indicateInteractionsElementIsNonEmpty(interactionsElement);
31
32 this.addExtraInfoChips(
33 chips, interactionsElement, /* withContainer = */ true);
34 }
35
36 #indicateInteractionsElementIsNonEmpty(interactionsElement) {
37 interactionsElement.classList.add(
38 'scTailwindThreadMessageMessageinteractionsinteractions');
39 }
40}