import { memo } from "react"; import { Box, Text } from "../../../../ui"; import { hoverBg } from "../../../../theme/colors"; import { useThemeColors } from "../../../../theme/theme-context"; import { t } from "../../../../i18n"; import { useAppLanguage } from "../../../../i18n/react"; import { MESSAGE_ACTION_WIDTH, normalizeInlinePreview } from "../layout"; import { Button } from "../../../../components/ui"; import { ResponsiveTickerBadgeText } from "./inline-tokens"; import { getChatMessageRenderState } from "./render-state"; import type { ChatMessageBaseProps } from "./types"; const DESKTOP_MESSAGE_RIGHT_PADDING = 2; export const DesktopChatMessage = memo(function DesktopChatMessage({ msg, index, messages, selectedIdx, hoveredIdx, canSend, catalog, userByUsername, openTicker, onUserHover, onUserHoverEnd, beginReplyTo, beginEditMessage, jumpToMessage, latestEditableMessageId, registerMessageElement, }: ChatMessageBaseProps & { registerMessageElement: (messageId: string, node: unknown | null) => void; }) { useAppLanguage(); const themeColors = useThemeColors(); const state = getChatMessageRenderState({ msg, index, messages, selectedIdx, hoveredIdx, canSend }); const canEditMessage = msg.id === latestEditableMessageId; const showInlineReplyAction = !state.grouped && canSend; const showInlineEditAction = !state.grouped && canSend && canEditMessage; const showGroupedReplyAction = state.grouped && canSend; const showGroupedEditAction = state.grouped && canSend && canEditMessage; const authorLabel = msg.user.username ?? "anon"; const groupedActionWidth = MESSAGE_ACTION_WIDTH * Number(showGroupedReplyAction) + MESSAGE_ACTION_WIDTH * Number(showGroupedEditAction); const rowProps = { width: "100%", paddingRight: DESKTOP_MESSAGE_RIGHT_PADDING, backgroundColor: state.bgColor, "data-gloom-role": "chat-message-row", "data-selected": state.isSelected ? "true" : "false", style: { minWidth: 0 }, }; return ( registerMessageElement(msg.id, node)} width="100%" flexDirection="column" data-gloom-role="chat-message" data-gloom-chat-message-id={msg.id} data-selected={state.isSelected ? "true" : "false"} style={{ "--chat-hover-bg": hoverBg(themeColors), minWidth: 0 }} > {msg.replyTo && ( { if (msg.replyToId) jumpToMessage(msg.replyToId); }} style={{ minWidth: 0, alignItems: "flex-start", cursor: "pointer", overflow: "hidden" }} > {/* One line: the quoted text ends in an ellipsis, the whole message is a click away. */} reply {`${msg.replyTo.user.username}: `} {normalizeInlinePreview(msg.replyTo.content)} )} {!state.grouped && ( onUserHover(msg.user)} onMouseMove={() => onUserHover(msg.user)} onMouseOut={onUserHoverEnd} style={{ cursor: "pointer" }} > {authorLabel} {state.headerStatus} {(showInlineReplyAction || showInlineEditAction) && ( <> {showInlineReplyAction && (