fix(extra-info): show extra info in the RCE thread page

The extra info feature worked with the old thread pages. This CL brings
support to the new RCE thread pages.

Bug: twpowertools:93
Change-Id: I47e4235afa4f7ec441f5a92edfcc28b1cb5f0419
diff --git a/src/contentScripts/communityConsole/extraInfo/services/message.js b/src/contentScripts/communityConsole/extraInfo/services/message.js
new file mode 100644
index 0000000..3b43403
--- /dev/null
+++ b/src/contentScripts/communityConsole/extraInfo/services/message.js
@@ -0,0 +1,56 @@
+import MessageModel from '../../../../models/Message.js';
+
+import StatesExtraInfoService from './states.js';
+
+export default class MessageExtraInfoService {
+  static getMessageIdFromNode(messageNode) {
+    const id =
+        messageNode.querySelector('.scTailwindThreadMessageMessagecardcontent')
+            ?.getAttribute?.('data-stats-id');
+    if (id === undefined)
+      throw new Error(`Couldn't retrieve message id from node.`);
+    return id;
+  }
+
+  static getMessageFromThreadModel(messageId, threadModel) {
+    for (const messageOrGap of threadModel.getMessageOrGapModels()) {
+      if (!(messageOrGap instanceof MessageModel)) continue;
+      if (messageOrGap.getId() == messageId) {
+        return messageOrGap;
+      } else {
+        for (const subMessageOrGap of messageOrGap.getCommentsAndGaps()) {
+          if (!(subMessageOrGap instanceof MessageModel)) continue;
+          if (subMessageOrGap.getId() == messageId) {
+            return subMessageOrGap;
+          }
+        }
+      }
+    }
+
+    throw new Error(`Couldn't find message ${messageId} in thread.`);
+  }
+
+  static getMessageChips(messageModel) {
+    const chips = [];
+    const tooltips = [];
+
+    const endPendingStateTimestampMicros =
+        messageModel.getEndPendingStateTimestampMicros();
+    const [pendingStateChip, pendingStateTooltip] =
+        StatesExtraInfoService.getPendingStateChip(
+            endPendingStateTimestampMicros);
+    if (pendingStateChip) chips.push(pendingStateChip);
+    if (pendingStateTooltip) tooltips.push(pendingStateTooltip);
+
+    const itemMetadata = messageModel.data?.[1]?.[5];
+    chips.push(...StatesExtraInfoService.getMetadataChips(itemMetadata));
+
+    const liveReviewStatus = messageModel.data?.[1]?.[36];
+    const [liveReviewChip, liveReviewTooltip] =
+        StatesExtraInfoService.getLiveReviewStatusChip(liveReviewStatus);
+    if (liveReviewChip) chips.push(liveReviewChip);
+    if (liveReviewTooltip) tooltips.push(liveReviewTooltip);
+
+    return [chips, tooltips];
+  }
+}