fix: 收到新会话消息. 当前客户端增加新会话. 包括发出的

dev/chat
Lei OT 2 years ago
parent 3a120f7932
commit c5d2332a0e

@ -235,6 +235,8 @@ export const receivedMsgTypeMapped = {
id: msgcontent.wamid,
status: msgStatusRenderMapped[(msgcontent?.status || 'failed')],
conversationid: msgcontent.actionId.split('.')[0], // msgcontent.conversation.sn,
date: msgcontent.createTime,
sender: 'me',
}),
},
'error': {

@ -8,6 +8,18 @@ import { WS_URL } from '@/config';
// const WS_URL = 'ws://202.103.68.144:8888/whatever/';
// const WS_URL = 'ws://120.79.9.217:10022/whatever/';
const conversationRow = {
sn: '',
opi_sn: '',
coli_sn: '',
coli_id: '',
last_received_time: '',
last_send_time: '',
unread_msg_count: '',
whatsapp_name: '',
customer_name: '',
whatsapp_phone_number: '',
};
const initialConversationState = {
// websocket: null,
@ -217,7 +229,7 @@ const messageSlice = (set, get) => ({
// msgUpdate
console.log('UPDATE_SENT_MESSAGE_ITEM-----------------------------------------------------------------');
// 更新会话中的消息
const { activeConversations, conversationsList } = get();
const { activeConversations, conversationsList, currentConversation } = get();
const targetId = message.conversationid;
const targetMsgs = (activeConversations[String(targetId)] || []).map((ele) => {
// 更新状态
@ -236,18 +248,32 @@ const messageSlice = (set, get) => ({
targetMsgs.push(message);
}
// 更新列表的时间
if (message.status === 'received') { // 'delivered'
const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
let newConversations = [];
if (targetIndex !== -1 && message.status === 'received') { // 'delivered'
// 更新列表的时间
conversationsList.splice(targetIndex, 1, {
...conversationsList[targetIndex],
last_received_time: message.deliverTime, // todo: 需要+8 hours
});
} else if (targetIndex === -1) {
// 当前客户端不存在的会话 todo: 设置为当前(在WhatsApp返回号码不一致时)
newConversations = [{
...conversationRow,
...message,
sn: targetId,
opi_sn: currentConversation.opi_sn, // todo: coli sn
last_received_time: message.date,
unread_msg_count: 0,
whatsapp_name: message?.senderName || message?.sender || '',
customer_name: message?.senderName || message?.sender || '',
whatsapp_phone_number: message.from,
}];
}
return set({
activeConversations: { ...activeConversations, [String(targetId)]: targetMsgs },
conversationsList: [...conversationsList],
conversationsList: [...newConversations, ...conversationsList],
});
},
sentOrReceivedNewMessage: (targetId, message) => {
@ -257,7 +283,7 @@ const messageSlice = (set, get) => ({
const targetIndex = conversationsList.findIndex((ele) => String(ele.sn) === String(targetId));
const lastReceivedTime = message.type !== 'system' && message.sender !== 'me' ? message.date : null;
const newConversation =
targetId !== -1
targetIndex !== -1
? {
...conversationsList[targetIndex],
last_received_time: lastReceivedTime || conversationsList[targetIndex].last_received_time,
@ -267,10 +293,15 @@ const messageSlice = (set, get) => ({
: conversationsList[targetIndex].unread_msg_count,
}
: {
...conversationRow,
...message,
sn: targetId,
opi_sn: currentConversation.opi_sn, // todo: coli sn
last_received_time: message.date,
unread_msg_count: message.sender === 'me' ? 0 : 1,
whatsapp_name: message?.senderName || message?.sender || '',
customer_name: message?.senderName || message?.sender || '',
whatsapp_phone_number: message.from,
};
conversationsList.splice(targetIndex, 1);
conversationsList.unshift(newConversation);

Loading…
Cancel
Save