From c5d2332a0ea7d3a3e6a24d1beafd3eb7e0484412 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 15 Mar 2024 16:33:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B6=E5=88=B0=E6=96=B0=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E6=B6=88=E6=81=AF.=20=E5=BD=93=E5=89=8D=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=A2=9E=E5=8A=A0=E6=96=B0=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?.=20=E5=8C=85=E6=8B=AC=E5=8F=91=E5=87=BA=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/msgUtils.js | 2 ++ src/stores/ConversationStore.js | 43 ++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index 38b57cf..853bc96 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -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': { diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 8d13508..aa6428c 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -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);