Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 1 | import StatesExtraInfoService from './states.js'; |
| 2 | |
| 3 | export default class MessageExtraInfoService { |
| 4 | static getMessageIdFromNode(messageNode) { |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 5 | const isMainReply = |
| 6 | messageNode.tagName == 'SC-TAILWIND-THREAD-MESSAGE-MESSAGE-CARD'; |
| 7 | const cardContentClass = isMainReply ? |
| 8 | '.scTailwindThreadMessageMessagecardcontent' : |
| 9 | '.scTailwindThreadMessageCommentcardnested-reply'; |
| 10 | const id = messageNode.querySelector(cardContentClass) |
| 11 | ?.getAttribute?.('data-stats-id'); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 12 | if (id === undefined) |
| 13 | throw new Error(`Couldn't retrieve message id from node.`); |
| 14 | return id; |
| 15 | } |
| 16 | |
Adrià Vilanova Martínez | 4b2582d | 2023-11-16 01:56:04 +0100 | [diff] [blame] | 17 | static getMessageFromList(messageId, messagesList) { |
| 18 | for (const message of messagesList) { |
| 19 | if (message.getId() == messageId) return message; |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 20 | } |
Adrià Vilanova Martínez | 4b2582d | 2023-11-16 01:56:04 +0100 | [diff] [blame] | 21 | throw new Error(`Couldn't find message ${messageId} in the message list.`); |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | static getMessageChips(messageModel) { |
| 25 | const chips = []; |
| 26 | const tooltips = []; |
| 27 | |
| 28 | const endPendingStateTimestampMicros = |
| 29 | messageModel.getEndPendingStateTimestampMicros(); |
| 30 | const [pendingStateChip, pendingStateTooltip] = |
| 31 | StatesExtraInfoService.getPendingStateChip( |
| 32 | endPendingStateTimestampMicros); |
| 33 | if (pendingStateChip) chips.push(pendingStateChip); |
| 34 | if (pendingStateTooltip) tooltips.push(pendingStateTooltip); |
| 35 | |
| 36 | const itemMetadata = messageModel.data?.[1]?.[5]; |
| 37 | chips.push(...StatesExtraInfoService.getMetadataChips(itemMetadata)); |
| 38 | |
| 39 | const liveReviewStatus = messageModel.data?.[1]?.[36]; |
| 40 | const [liveReviewChip, liveReviewTooltip] = |
| 41 | StatesExtraInfoService.getLiveReviewStatusChip(liveReviewStatus); |
| 42 | if (liveReviewChip) chips.push(liveReviewChip); |
| 43 | if (liveReviewTooltip) tooltips.push(liveReviewTooltip); |
| 44 | |
| 45 | return [chips, tooltips]; |
| 46 | } |
| 47 | } |