Adrià Vilanova MartÃnez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 1 | import MessageModel from '../../../../models/Message.js'; |
| 2 | |
| 3 | import StatesExtraInfoService from './states.js'; |
| 4 | |
| 5 | export default class MessageExtraInfoService { |
| 6 | static getMessageIdFromNode(messageNode) { |
| 7 | const id = |
| 8 | messageNode.querySelector('.scTailwindThreadMessageMessagecardcontent') |
| 9 | ?.getAttribute?.('data-stats-id'); |
| 10 | if (id === undefined) |
| 11 | throw new Error(`Couldn't retrieve message id from node.`); |
| 12 | return id; |
| 13 | } |
| 14 | |
| 15 | static getMessageFromThreadModel(messageId, threadModel) { |
| 16 | for (const messageOrGap of threadModel.getMessageOrGapModels()) { |
| 17 | if (!(messageOrGap instanceof MessageModel)) continue; |
| 18 | if (messageOrGap.getId() == messageId) { |
| 19 | return messageOrGap; |
| 20 | } else { |
| 21 | for (const subMessageOrGap of messageOrGap.getCommentsAndGaps()) { |
| 22 | if (!(subMessageOrGap instanceof MessageModel)) continue; |
| 23 | if (subMessageOrGap.getId() == messageId) { |
| 24 | return subMessageOrGap; |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | throw new Error(`Couldn't find message ${messageId} in thread.`); |
| 31 | } |
| 32 | |
| 33 | static getMessageChips(messageModel) { |
| 34 | const chips = []; |
| 35 | const tooltips = []; |
| 36 | |
| 37 | const endPendingStateTimestampMicros = |
| 38 | messageModel.getEndPendingStateTimestampMicros(); |
| 39 | const [pendingStateChip, pendingStateTooltip] = |
| 40 | StatesExtraInfoService.getPendingStateChip( |
| 41 | endPendingStateTimestampMicros); |
| 42 | if (pendingStateChip) chips.push(pendingStateChip); |
| 43 | if (pendingStateTooltip) tooltips.push(pendingStateTooltip); |
| 44 | |
| 45 | const itemMetadata = messageModel.data?.[1]?.[5]; |
| 46 | chips.push(...StatesExtraInfoService.getMetadataChips(itemMetadata)); |
| 47 | |
| 48 | const liveReviewStatus = messageModel.data?.[1]?.[36]; |
| 49 | const [liveReviewChip, liveReviewTooltip] = |
| 50 | StatesExtraInfoService.getLiveReviewStatusChip(liveReviewStatus); |
| 51 | if (liveReviewChip) chips.push(liveReviewChip); |
| 52 | if (liveReviewTooltip) tooltips.push(liveReviewTooltip); |
| 53 | |
| 54 | return [chips, tooltips]; |
| 55 | } |
| 56 | } |