import React, { PropsWithChildren, useEffect, useState } from 'react'; import TencentCloudChat, { Conversation, Group, Profile } from '@tencentcloud/chat'; import { Avatar } from '../Avatar'; import { handleDisplayAvatar } from '../untils'; import './styles/index.scss'; import { Icon, IconTypes } from '../Icon'; import { useTUIKitContext } from '../../context'; export interface TUIChatHeaderDefaultProps { title?: string, avatar?: React.ReactElement | string, isOnline?: boolean, conversation?: Conversation, pluginComponentList?: Array, } export interface TUIChatHeaderBasicProps extends TUIChatHeaderDefaultProps { isLive?: boolean, opateIcon?: React.ReactElement | string, } function TUIChatHeaderDefaultWithContext ( props: PropsWithChildren, ):React.ReactElement { const { title: propTitle = '', avatar: propAvatar, isOnline, conversation, isLive, opateIcon, } = props; const [title, setTitle] = useState(propTitle); const [avatar, setAvatar] = useState(''); useEffect(() => { setTitle(propTitle); if (propAvatar) { setAvatar(propAvatar); } switch (conversation?.type) { case TencentCloudChat.TYPES.CONV_C2C: handleC2C(conversation.userProfile, conversation?.remark); break; case TencentCloudChat.TYPES.CONV_GROUP: handleGroup(conversation.groupProfile); break; case TencentCloudChat.TYPES.CONV_SYSTEM: setTitle('System Notice'); break; default: setTitle(''); break; } }, [conversation]); const handleC2C = (userProfile: Profile, remark?: string) => { if (!title) { setTitle(remark || userProfile?.nick || userProfile?.userID); } if (!propAvatar) { setAvatar(); } }; const handleGroup = (groupProfile: Group) => { if (!title) { setTitle(groupProfile?.name || groupProfile?.groupID); } if (!propAvatar) { setAvatar(); } }; const { setTUIManageShow } = useTUIKitContext(); const openTUIManage = () => { setTUIManageShow(true); }; return (
{conversation?.type !== TencentCloudChat.TYPES.CONV_SYSTEM && avatar}

{title}

{ opateIcon || }
); } const MemoizedTUIChatHeaderDefault = React.memo(TUIChatHeaderDefaultWithContext) as typeof TUIChatHeaderDefaultWithContext; export function TUIChatHeaderDefault(props: TUIChatHeaderBasicProps) :React.ReactElement { const options = { ...props }; return ; }