blob: d0cd1627ae083bc13294e0a008ba2a2f4471411b [file] [log] [blame]
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +01001import {MDCTooltip} from '@material/tooltip';
2
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +01003import {shouldImplement} from '../../../../common/commonUtils.js';
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +01004import ThreadModel from '../../../../models/Thread.js';
5import MessageExtraInfoService from '../services/message.js';
6
7import BaseExtraInfoInjection from './base.js';
8
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +01009export default class BaseThreadMessageExtraInfoInjection extends
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010010 BaseExtraInfoInjection {
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +010011 /**
12 * The class of the interactions root element.
13 */
14 getInteractionsRootClass() {
15 shouldImplement('getInteractionsRootClass');
16 }
17
18 /**
19 * The class of the interactions root element which signifies that it is
20 * non-empty.
21 */
22 getInteractionsRootNonEmptyClass() {
23 shouldImplement('getInteractionsRootNonEmptyClass');
24 }
25
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010026 inject(threadInfo, injectionDetails) {
27 const messageNode = injectionDetails.messageNode;
Adrià Vilanova Martínez4b2582d2023-11-16 01:56:04 +010028 const message = this.#getMessage(threadInfo.messages, messageNode);
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010029 const [chips, tooltips] = MessageExtraInfoService.getMessageChips(message);
30 this.#injectChips(chips, messageNode);
31 for (const tooltip of tooltips) new MDCTooltip(tooltip);
32 }
33
Adrià Vilanova Martínez4b2582d2023-11-16 01:56:04 +010034 #getMessage(messagesList, messageNode) {
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010035 const messageId = MessageExtraInfoService.getMessageIdFromNode(messageNode);
Adrià Vilanova Martínez4b2582d2023-11-16 01:56:04 +010036 return MessageExtraInfoService.getMessageFromList(messageId, messagesList);
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010037 }
38
39 #injectChips(chips, messageNode) {
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +010040 const interactionsElement =
41 messageNode.querySelector('.' + this.getInteractionsRootClass());
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010042 if (interactionsElement === null)
43 throw new Error(`Couldn't find interactions element.`);
44
45 this.#indicateInteractionsElementIsNonEmpty(interactionsElement);
46
47 this.addExtraInfoChips(
48 chips, interactionsElement, /* withContainer = */ true);
49 }
50
51 #indicateInteractionsElementIsNonEmpty(interactionsElement) {
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +010052 interactionsElement.classList.add(this.getInteractionsRootNonEmptyClass());
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010053 }
54}