import React from "react";
import { ChatMessage } from "../database.d";
import { formatSeconds } from "../format";
import { proxyYT3 as proxyURL } from "../util";
export type ChatMessageRenderProps = {
message: ChatMessage;
};
const regexEmoji = /(:[^:]+:)/g;
const ChatMessageRender = React.memo((props: ChatMessageRenderProps) => {
const msg = props.message;
const generateMessageContent = (msg: ChatMessage) => {
if (!msg.emotes) return msg.message;
// Process emotes
const tokens = msg.message.split(regexEmoji);
return tokens.map((token) => {
if (!token.startsWith(":")) return token;
let images = msg.emotes.find((emote) => emote.name === token)?.images;
if (!images)
images = msg.emotes.find((emote) => emote.shortcuts.includes(token))
?.images;
if (!images) return token;
const emoteURL =
images.find((image) => image.id === "source")?.url || images[0]?.url;
if (!emoteURL) return token;
return (
);
});
};
switch (msg.message_type) {
case "paid_message":
return (