From 38e18cf4b8219f15d1aa5c949a7265e0703ed194 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 4 Mar 2024 10:46:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BC=9A=E8=AF=9D:=20?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/ConversationStore.js | 2 +- .../Components/ConversationsList.jsx | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 0d7f74e..5fd1855 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -185,7 +185,7 @@ const conversationSlice = (set, get) => ({ unread_msg_count: 0, }) : null; - return set({ totalNotify: totalNotify - conversation.unread_msg_count, currentConversation: conversation, referenceMsg: {}, conversationsList: [...conversationsList] }); + return set({ totalNotify: totalNotify - (conversation.unread_msg_count || 0), currentConversation: conversation, referenceMsg: {}, conversationsList: [...conversationsList] }); }, }); diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 0f2adf2..5a542ac 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -40,14 +40,16 @@ const Conversations = () => { const getOrderConversationList = async (colisn) => { const { whatsapp_phone_number } = switchToC; const whatsappID = coli_guest_WhatsApp || whatsapp_phone_number || ''; - const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID }); - if (!isEmpty(data)) { - addToConversationList(data); + let findCurrent = -1; // conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); + if (!isEmpty(whatsappID)) { + const data = await fetchOrderConversationsList({ opisn: userId, colisn: colisn, whatsappid: whatsappID }); + if (!isEmpty(data)) { + addToConversationList(data); + } + findCurrent = conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); // data.findIndex((item) => item.sn === currentConversation.sn); } - let ifCurrent = data.findIndex((item) => item.sn === currentConversation.sn); - ifCurrent = ifCurrent !== -1 ? ifCurrent : conversationsList.findIndex((item) => item.coli_sn === Number(colisn)); - if (ifCurrent !== -1) { - switchConversation(conversationsList[ifCurrent === -1 ? 0 : ifCurrent]); + if (findCurrent !== -1) { + switchConversation(conversationsList[findCurrent]); } else { // reset chat window setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn });