import { useEffect, useRef, useState, forwardRef, memo } from 'react'; import { MessageBox } from 'react-chat-elements'; import { App, Button } from 'antd'; import { DownOutlined, LoadingOutlined } from '@ant-design/icons'; import { useShallow } from 'zustand/react/shallow'; import useConversationStore from '@/stores/ConversationStore'; import { groupBy, isEmpty, } from '@/utils/commons'; import BubbleEmail from './Components/BubbleEmail'; import BubbleIM from './Components/BubbleIM'; const MessagesList = ({ messages, handlePreview, reference, longListLoading, getMoreMessages, shouldScrollBottom, loadNextPage, handleContactClick, setNewChatModalVisible, setNewChatFormValues, ...listProps }) => { // const messagesEndRef = useRef(null); const messageRefs = useRef([]); const [focusMsg, setFocusMsg] = useState(''); useEffect(() => { setTimeout(() => { setFocusMsg(''); }, 3500); return () => ''; }, [focusMsg]) const scrollToBottom = (force = false) => { if (reference.current && (shouldScrollBottom || force)) { reference.current.scrollTop = reference.current.scrollHeight; } }; const scrollToMessage = (id, index) => { const _i = index || messages.findIndex((msg) => msg.id === id); if (_i >= 0) { messageRefs.current[_i].scrollIntoView({ behavior: 'smooth', block: 'start' }); setFocusMsg(id); } }; useEffect(scrollToBottom, [messages]); const onLoadMore = async () => { await getMoreMessages(); }; // eslint-disable-next-line react/display-name const MessageBoxWithRef = forwardRef((props, ref) => (