import React, { useEffect, useRef } from 'react' import './MessageBox.css' import PhotoMessage from '../PhotoMessage/PhotoMessage' import FileMessage from '../FileMessage/FileMessage' import SystemMessage from '../SystemMessage/SystemMessage' import LocationMessage from '../LocationMessage/LocationMessage' import SpotifyMessage from '../SpotifyMessage/SpotifyMessage' import ReplyMessage from '../ReplyMessage/ReplyMessage' import MeetingMessage from '../MeetingMessage/MeetingMessage' import VideoMessage from '../VideoMessage/VideoMessage' import AudioMessage from '../AudioMessage/AudioMessage' import MeetingLink from '../MeetingLink/MeetingLink' import Avatar from '../Avatar/Avatar' import { format } from 'timeago.js' import classNames from 'classnames' import { MessageBoxType } from '../type' import { HugeiconsIcon } from '@hugeicons/react'; import { LinkForwardIcon, TickDouble02Icon, ClockIcon, Tick02Icon, MessageOutgoing01Icon, Delete02Icon, UnavailableIcon, // @ts-ignore } from '@hugeicons/core-free-icons'; const MessageBox: React.FC = ({ focus = false, notch = true, styles, ...props }) => { const prevProps = useRef(focus) const messageRef = useRef(null) var positionCls = classNames('rce-mbox', { 'rce-mbox-right': props.position === 'right' }) var thatAbsoluteTime = !/(text|video|file|meeting|audio)/g.test(props.type || 'text') && !(props.type === 'location' && props.text) const dateText = props.date && (props.dateString || format(props.date)) useEffect(() => { if (prevProps.current !== focus && focus === true) { if (messageRef) { messageRef.current?.scrollIntoView({ block: 'center', behavior: 'smooth', }) props.onMessageFocused(prevProps) } } prevProps.current = focus }, [focus, prevProps]) return (
{props.renderAddCmp instanceof Function ? props.renderAddCmp() : props.renderAddCmp} {props.type === 'system' ? ( ) : (
{!props.retracted && props.forwarded === true && (
)} {!props.retracted && props.replyButton === true && (
)} {!props.retracted && props.removeButton === true && (
)} {(props.title || props.avatar) && (
{props.avatar && } {props.title && {props.title}}
)} {props.forwardedMessageText ? (
{props.forwardedMessageText}
) : null} {!props.forwardedMessageText && props.reply ? ( ) : null} {props.type === 'text' && (
{props.retracted && } {props.text}
)} {props.type === 'location' && } {props.type === 'photo' && } {props.type === 'video' && } {props.type === 'file' && } {props.type === 'spotify' && } {props.type === 'meeting' && } {props.type === 'audio' && } {props.type === 'meetingLink' && ( )}
{props.copiableDate && props.date && (props.dateString || format(props.date))} {props.status && ( {props.status === 'waiting' && } {props.status === 'sent' && } {props.status === 'received' && } {props.status === 'read' && } )}
{notch && (props.position === 'right' ? ( ) : (
))}
)}
) } export default MessageBox