Adrià Vilanova MartÃnez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 1 | import {MDCTooltip} from '@material/tooltip'; |
| 2 | |
| 3 | import ThreadModel from '../../../../models/Thread.js'; |
| 4 | import MessageExtraInfoService from '../services/message.js'; |
| 5 | |
| 6 | import BaseExtraInfoInjection from './base.js'; |
| 7 | |
| 8 | export 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 | } |