/* eslint-disable react/no-danger */ import { useEffect, useState } from 'react'; import { Highlight } from 'react-highlighter-ts'; import he from 'he'; import cn from 'classnames'; import { Tooltip } from 'antd'; import { LinkOutlined } from '@ant-design/icons'; import s from './ChatUserMessage.module.scss'; import { formatTimestamp } from './messageFmt'; import { ChatMessage } from '../../../interfaces/chat-message.model'; import ChatModerationActionMenu from '../ChatModerationActionMenu/ChatModerationActionMenu'; import ChatUserBadge from '../ChatUserBadge/ChatUserBadge'; interface Props { message: ChatMessage; showModeratorMenu: boolean; highlightString: string; sentBySelf: boolean; sameUserAsLast: boolean; isAuthorModerator: boolean; isAuthorAuthenticated: boolean; } export default function ChatUserMessage({ message, highlightString, showModeratorMenu, sentBySelf, // Move the border to the right and render a background sameUserAsLast, isAuthorModerator, isAuthorAuthenticated, }: Props) { const { id: messageId, body, user, timestamp } = message; const { id: userId, displayName, displayColor } = user; const color = `var(--theme-color-users-${displayColor})`; const formattedTimestamp = `Sent ${formatTimestamp(timestamp)}`; const [formattedMessage, setFormattedMessage] = useState(body); const badgeNodes = []; if (isAuthorModerator) { badgeNodes.push(); } if (isAuthorAuthenticated) { badgeNodes.push( } userColor={displayColor} />, ); } useEffect(() => { setFormattedMessage(he.decode(body)); }, [message]); return (
{!sameUserAsLast && (
{displayName} {badgeNodes}
)}
{showModeratorMenu && (
)}
); }