|
|
|
@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef } from 'react';
|
|
|
|
|
import { useParams, useNavigate } from 'react-router-dom';
|
|
|
|
|
import { Dropdown, Input, Button, Tag, Popover, Form, Tooltip, Spin } from 'antd';
|
|
|
|
|
import { CloseCircleOutlined, MinusCircleOutlined } from '@ant-design/icons';
|
|
|
|
|
import { fetchConversationItemClose, fetchConversationsSearch, fetchConversationItemUnread, fetchConversationItemTop, postConversationTags, deleteConversationTags } from '@/actions/ConversationActions';
|
|
|
|
|
import { fetchConversationItemClose, fetchConversationsSearch, fetchConversationItemUnread, fetchConversationItemTop, postConversationTags, deleteConversationTags, fetchCleanUnreadMsgCount } from '@/actions/ConversationActions';
|
|
|
|
|
import { ChatItem } from 'react-chat-elements';
|
|
|
|
|
// import ConversationsNewItem from './ConversationsNewItem';
|
|
|
|
|
import { flush, isEmpty, isNotEmpty, stringToColour, TagColorStyle } from '@/utils/commons';
|
|
|
|
@ -76,10 +76,12 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
|
|
|
|
|
const setClosedConversationList = useConversationStore((state) => state.setClosedConversationList);
|
|
|
|
|
|
|
|
|
|
const [currentHandleChat, setCurrentHandleChat] = useState({});
|
|
|
|
|
const [handleLoading, setHandleLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
const itemTagsKeys = (item.tags || []).map(t => t.key);
|
|
|
|
|
const [tags, addTag] = useConversationStore(state => [state.tags, state.addTag]);
|
|
|
|
|
const handleConversationItemClose = async (item) => {
|
|
|
|
|
setHandleLoading(true);
|
|
|
|
|
await fetchConversationItemClose({ conversationid: item.sn, opisn: item.opi_sn });
|
|
|
|
|
delConversationitem(item);
|
|
|
|
|
if (String(order_sn) === String(item.coli_sn)) {
|
|
|
|
@ -88,31 +90,43 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
|
|
|
|
|
const _clist = await fetchConversationsSearch({ opisn: userId, session_enable: 0 });
|
|
|
|
|
setClosedConversationList(_clist);
|
|
|
|
|
setCurrentHandleChat({});
|
|
|
|
|
setHandleLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleConversationItemUnread = async (item) => {
|
|
|
|
|
await fetchConversationItemUnread({ conversationid: item.sn });
|
|
|
|
|
setHandleLoading(true);
|
|
|
|
|
if (item.unread_msg_count < 999) {
|
|
|
|
|
await fetchConversationItemUnread({ conversationid: item.sn });
|
|
|
|
|
} else {
|
|
|
|
|
await fetchCleanUnreadMsgCount({ opisn: item.opi_sn, conversationid: item.sn });
|
|
|
|
|
}
|
|
|
|
|
await refreshConversationList(item.lasttime);
|
|
|
|
|
setListUpdateFlag(Math.random());
|
|
|
|
|
setCurrentHandleChat({});
|
|
|
|
|
setHandleLoading(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleConversationItemTop = async (item) => {
|
|
|
|
|
setHandleLoading(true);
|
|
|
|
|
await fetchConversationItemTop({ conversationid: item.sn, top_state: item.top_state === 0 ? 1 : 0 });
|
|
|
|
|
await refreshConversationList(item.lasttime);
|
|
|
|
|
setListUpdateFlag(Math.random());
|
|
|
|
|
setCurrentHandleChat({});
|
|
|
|
|
setHandleLoading(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleConversationItemMuted = async (item) => {
|
|
|
|
|
setHandleLoading(true);
|
|
|
|
|
await fetchConversationItemTop({ conversationid: item.sn, top_state: item.top_state === -1 ? 0 : -1 });
|
|
|
|
|
await refreshConversationList(item.lasttime);
|
|
|
|
|
setListUpdateFlag(Math.random());
|
|
|
|
|
setCurrentHandleChat({});
|
|
|
|
|
setHandleLoading(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleConversationItemTags = async (item, tagKey, tagLabel) => {
|
|
|
|
|
const _tags = (item.tags || []).map(t => t.key);
|
|
|
|
|
setHandleLoading(true);
|
|
|
|
|
if (isNotEmpty(tagKey) && _tags.includes(Number(tagKey))) {
|
|
|
|
|
await deleteConversationTags({ conversationid: item.sn, tag_id: tagKey, opisn: userId })
|
|
|
|
|
} else {
|
|
|
|
@ -130,6 +144,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
|
|
|
|
|
setListUpdateFlag(Math.random());
|
|
|
|
|
setContextMenuOpen(false);
|
|
|
|
|
setCurrentHandleChat({});
|
|
|
|
|
setHandleLoading(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [contextMenuOpen, setContextMenuOpen] = useState(false);
|
|
|
|
@ -171,9 +186,9 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
|
|
|
|
|
onOpenChange={(nextOpen, info) => handleContextMenuOpenChange(nextOpen, info, item)}
|
|
|
|
|
menu={{
|
|
|
|
|
items: [
|
|
|
|
|
item.top_state === 1 ? { label: '取消置顶', key: 'top' } : { label: '置顶会话', key: 'top' },
|
|
|
|
|
{ label: '标记为未读', key: 'unread' },
|
|
|
|
|
item.top_state === -1 ? { label: '取消静音', key: 'mute' } : { label: '设为静音', key: 'mute' },
|
|
|
|
|
{ label: item.top_state === 1 ? '取消置顶' : '置顶会话', key: 'top' },
|
|
|
|
|
{ label: item.unread_msg_count > 998 ? '标为已读' : '标记为未读', key: 'unread' },
|
|
|
|
|
{ label: item.top_state === -1 ? '取消静音' : '设为静音', key: 'mute' },
|
|
|
|
|
{
|
|
|
|
|
label: '设置标签',
|
|
|
|
|
key: 'tags',
|
|
|
|
@ -272,7 +287,7 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
|
|
|
|
|
{/* <div className='pl-4 pt-1 text-xs text-right'>
|
|
|
|
|
{tags.map((tag) => <Tag color={tag.color} key={tag.value}>{tag.label}</Tag>)}
|
|
|
|
|
</div> */}
|
|
|
|
|
<Spin spinning={(item.sn) === (currentHandleChat?.sn) && props.conversationsListLoading} size='small'>
|
|
|
|
|
<Spin spinning={(item.sn) === (currentHandleChat?.sn) && (props.conversationsListLoading || handleLoading)} size='small'>
|
|
|
|
|
<ChatItem
|
|
|
|
|
{...item}
|
|
|
|
|
key={item.sn}
|
|
|
|
|