在线窗口: 获取消息: 倒序的, 更新本页的最后一条消息座位下一页的开始

dev/chat
Lei OT 1 year ago
parent 2557a19c22
commit c3d8295798

@ -35,7 +35,7 @@ export const fetchMessages = async (params) => {
pagesize: MESSAGE_PAGE_SIZE,
};
const { errcode, result } = await fetchJSON(`${API_HOST}/getcusmessages`, {...defaultParams, ...params});
return errcode !== 0 ? [] : parseRenderMessageList(result.reverse() || []);
return errcode !== 0 ? [] : parseRenderMessageList((result || []).reverse());
}
/**

@ -76,7 +76,7 @@ const Conversations = () => {
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number, lasttime: '' });
setMsgLoading(false);
receivedMessageList(item.sn, data);
const thisLastTime = data.length > 0 ? data[data.length - 1].orgmsgtime : '';
const thisLastTime = data.length > 0 ? data[0].orgmsgtime : '';
const loadNextPage = !(data.length === 0 || data.length < MESSAGE_PAGE_SIZE);
updateCurrentConversation({ lasttime: thisLastTime, loadNextPage });
};

@ -11,7 +11,6 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
// const messagesEndRef = useRef(null);
const messageRefs = useRef([]);
const prevProps = useRef(props)
const scrollToBottom = (force = false) => {
if (reference.current && (shouldScrollBottom || force)) {
@ -74,7 +73,7 @@ const MessagesList = ({ messages, handlePreview, reference, longListLoading, get
return (
<div className='relative h-full overflow-y-auto overflow-x-hidden flex flex-1'>
<div ref={reference} className='relative overflow-y-auto overflow-x-hidden block flex-1'>
{loadNextPage && (
{loadNextPage && messages.length>0 && (
<div className='text-center pt-3 mb-3 h-8 leading-8 '>
{!longListLoading ? <Button onClick={onLoadMore} type={'dashed'}>loading more</Button> : <LoadingOutlined className='text-primary' />}
</div>

@ -28,7 +28,7 @@ const MessagesWrapper = () => {
const data = await fetchMessages({ opisn: currentConversation.opi_sn, whatsappid: currentConversation.whatsapp_phone_number, lasttime: currentConversation?.lasttime || '' });
setLongListLoading(false);
setLongList(prevValue => data.concat(prevValue));
const thisLastTime = data.length > 0 ? data[data.length - 1].orgmsgtime : '';
const thisLastTime = data.length > 0 ? data[0].orgmsgtime : '';
const loadNextPage = !(data.length === 0 || data.length < MESSAGE_PAGE_SIZE);
updateCurrentConversation({ lasttime: thisLastTime, loadNextPage });
return data.length;

Loading…
Cancel
Save