Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 1 | import {MDCTooltip} from '@material/tooltip'; |
| 2 | |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 3 | import {shouldImplement} from '../../../../common/commonUtils.js'; |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 4 | import ThreadModel from '../../../../models/Thread.js'; |
| 5 | import MessageExtraInfoService from '../services/message.js'; |
| 6 | |
| 7 | import BaseExtraInfoInjection from './base.js'; |
| 8 | |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 9 | export default class BaseThreadMessageExtraInfoInjection extends |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 10 | BaseExtraInfoInjection { |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 11 | /** |
| 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ínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 26 | inject(threadInfo, injectionDetails) { |
| 27 | const messageNode = injectionDetails.messageNode; |
Adrià Vilanova Martínez | 4b2582d | 2023-11-16 01:56:04 +0100 | [diff] [blame] | 28 | const message = this.#getMessage(threadInfo.messages, messageNode); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 29 | 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ínez | 4b2582d | 2023-11-16 01:56:04 +0100 | [diff] [blame] | 34 | #getMessage(messagesList, messageNode) { |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 35 | const messageId = MessageExtraInfoService.getMessageIdFromNode(messageNode); |
Adrià Vilanova Martínez | 4b2582d | 2023-11-16 01:56:04 +0100 | [diff] [blame] | 36 | return MessageExtraInfoService.getMessageFromList(messageId, messagesList); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | #injectChips(chips, messageNode) { |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 40 | const interactionsElement = |
| 41 | messageNode.querySelector('.' + this.getInteractionsRootClass()); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 42 | 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ínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 52 | interactionsElement.classList.add(this.getInteractionsRootNonEmptyClass()); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 53 | } |
| 54 | } |