blob: 268fea509ab09b363003113595dd9a5e5f3702fd [file] [log] [blame]
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +01001import StatesExtraInfoService from './states.js';
2
3export default class MessageExtraInfoService {
4 static getMessageIdFromNode(messageNode) {
Adrià Vilanova Martínez80f1c732023-11-16 00:52:56 +01005 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ínez19f6a652023-11-15 19:38:50 +010012 if (id === undefined)
13 throw new Error(`Couldn't retrieve message id from node.`);
14 return id;
15 }
16
Adrià Vilanova Martínez4b2582d2023-11-16 01:56:04 +010017 static getMessageFromList(messageId, messagesList) {
18 for (const message of messagesList) {
19 if (message.getId() == messageId) return message;
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010020 }
Adrià Vilanova Martínez4b2582d2023-11-16 01:56:04 +010021 throw new Error(`Couldn't find message ${messageId} in the message list.`);
Adrià Vilanova Martínez19f6a652023-11-15 19:38:50 +010022 }
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}