会话列表: 搜索会话

dev/chat
Lei OT 1 year ago
parent db774fec09
commit 671cbc7881

@ -36,11 +36,19 @@ export const fetchOrderConversationsList = async (params) => {
return list; return list;
}; };
/**
*
* @param {object} body { opisn, conversationid }
* @returns
*/
export const fetchConversationItemClose = async (body) => { export const fetchConversationItemClose = async (body) => {
const { result } = await fetchJSON(`${API_HOST}/closeconversation`, body); const { result } = await fetchJSON(`${API_HOST}/closeconversation`, body);
return result; return result;
}; };
/**
* @param {object} params { opisn, whatsappid }
*/
export const fetchCleanUnreadMsgCount = async (params) => { export const fetchCleanUnreadMsgCount = async (params) => {
const { errcode, result } = await fetchJSON(`${API_HOST}/clean_unread_msg_count`, params); const { errcode, result } = await fetchJSON(`${API_HOST}/clean_unread_msg_count`, params);
return errcode !== 0 ? {} : result; return errcode !== 0 ? {} : result;

@ -298,10 +298,14 @@ export const useConversationStore = create(
setInitial(true); setInitial(true);
for (const chatItem of conversationsList) { const autoGetMsgs = conversationsList.length > 5 ? 5 : conversationsList.length;
for (let index = 0; index < autoGetMsgs; index++) {
const chatItem = conversationsList[index];
const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number }); const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number });
receivedMessageList(chatItem.sn, msgData); receivedMessageList(chatItem.sn, msgData);
} }
// for (const chatItem of conversationsList) {
// }
}, },
})) }))
); );

@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { Button, Dropdown, Input } from 'antd'; import { Button, Dropdown, Input } from 'antd';
import { MoreOutlined } from '@ant-design/icons'; import { MoreOutlined } from '@ant-design/icons';
import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions'; import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages, fetchCleanUnreadMsgCount } from '@/actions/ConversationActions';
import { ChatList, ChatItem } from 'react-chat-elements'; import { ChatList, ChatItem } from 'react-chat-elements';
import { isEmpty } from '@/utils/utils'; import { isEmpty } from '@/utils/utils';
import useConversationStore from '@/stores/ConversationStore'; import useConversationStore from '@/stores/ConversationStore';
@ -28,6 +28,10 @@ const Conversations = () => {
const setMsgLoading = useConversationStore((state) => state.setMsgLoading); const setMsgLoading = useConversationStore((state) => state.setMsgLoading);
const [dataSource, setDataSource] = useState(conversationsList); const [dataSource, setDataSource] = useState(conversationsList);
useEffect(() => {
setDataSource(conversationsList);
return () => {};
}, [conversationsList]);
const [switchToC, setSwitchToC] = useState({}); const [switchToC, setSwitchToC] = useState({});
const [shouldFetchCList, setShouldFetchCList] = useState(true); const [shouldFetchCList, setShouldFetchCList] = useState(true);
@ -65,9 +69,10 @@ const Conversations = () => {
receivedMessageList(item.sn, data); receivedMessageList(item.sn, data);
}; };
const switchConversation = async (item) => { const switchConversation = async (item) => {
fetchCleanUnreadMsgCount({ opisn: item.opi_sn, whatsappid: item.whatsapp_phone_number });
const messagesList = activeConversations[`${item.sn}`] || []; const messagesList = activeConversations[`${item.sn}`] || [];
if (messagesList.length < 20) { if (messagesList.length < 20) {
await getMessages(item); getMessages(item);
} }
if (String(item.sn) === String(currentConversation.sn)) { if (String(item.sn) === String(currentConversation.sn)) {
return false; return false;
@ -75,7 +80,7 @@ const Conversations = () => {
setCurrentConversation(item); setCurrentConversation(item);
}; };
const onSwitchConversation = (item) => { const onSwitchConversation = async (item) => {
if (!isEmpty(item.coli_sn)) { if (!isEmpty(item.coli_sn)) {
setSwitchToC(item); setSwitchToC(item);
setShouldFetchCList(false); setShouldFetchCList(false);
@ -100,7 +105,7 @@ const Conversations = () => {
if (val.toLowerCase().trim() !== '') { if (val.toLowerCase().trim() !== '') {
const res = conversationsList.filter( const res = conversationsList.filter(
(item) => (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim()) (item) => (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim())
|| (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim()) || (item.whatsapp_phone_number.toLowerCase()).includes(val.toLowerCase().trim())
|| (item.coli_id.toLowerCase()).includes(val.toLowerCase().trim()) || (item.coli_id.toLowerCase()).includes(val.toLowerCase().trim())
); );
setDataSource(res); setDataSource(res);
@ -122,6 +127,12 @@ const Conversations = () => {
setSearchContent(e.target.value); setSearchContent(e.target.value);
handleSearchConversations(e.target.value); handleSearchConversations(e.target.value);
}} }}
onPressEnter={(e) => {
handleSearchConversations(e.target.value);
searchInputRef.current.blur();
onSwitchConversation(dataSource[0]);
return false;
}}
placeholder='搜索名称' placeholder='搜索名称'
/> />
</div> </div>

Loading…
Cancel
Save