import React, { PropsWithChildren, ReactNode, useState, } from 'react'; import TencentCloudChat, { Message } from '@tencentcloud/chat'; import { MESSAGE_STATUS } from '../../constants'; import { useTUIChatActionContext } from '../../context'; import { Icon, IconTypes } from '../Icon'; import { useMessageReply } from './hooks/useMessageReply'; import { MessageProgress } from './MessageProgress'; export interface MessageBubbleProps { message?: Message, className?: string, children?: ReactNode, Context?: React.ComponentType, Plugins?: React.ComponentType | undefined, } function MessageBubbleWithContext ( props: PropsWithChildren, ):React.ReactElement { const { message, children, Context, Plugins, } = props; const [PluginsShow, setPluginsShow] = useState(false); const { messageReply, replyMessage, sender, } = useMessageReply({ message }); const { setHighlightedMessageId } = useTUIChatActionContext('MessageBubbleWithContext'); const handleLoading = () => !!(( message?.type === TencentCloudChat.TYPES.MSG_IMAGE || message?.type === TencentCloudChat.TYPES.MSG_VIDEO || message?.type === TencentCloudChat.TYPES.MSG_FILE ) && message?.status === MESSAGE_STATUS.UNSEND); const handleMouseEnter = () => { setPluginsShow(true); }; const handleMouseLeave = () => { setPluginsShow(false); }; const handleReplyMessage = () => { setHighlightedMessageId(replyMessage?.ID); }; return (
{ messageReply && (
{sender}
{Context && }
) } {children}
{ Plugins && (
{PluginsShow && }
) }
{ message?.status === MESSAGE_STATUS.FAIL && } { message?.status === MESSAGE_STATUS.UNSEND && }
); } const MemoizedMessageBubble = React.memo(MessageBubbleWithContext) as typeof MessageBubbleWithContext; export function MessageBubble(props:MessageBubbleProps):React.ReactElement { return ( ); }