From 7e20ca48cf728fbe0998cf6e44acb30484c3a853 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 8 Jul 2025 10:30:15 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=9C=A8=E7=BA=BF=E8=81=8A=E5=A4=A9:?= =?UTF-8?q?=20=E4=BC=9A=E8=AF=9D=E6=90=9C=E7=B4=A2:=20=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=8A=8A=E5=BD=93=E5=89=8D=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=94=BE=E9=A1=B6=E9=83=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/ConversationStore.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index f4aa7e7..f8e463c 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -1,6 +1,6 @@ import { create } from 'zustand'; import { RealTimeAPI } from '@/channel/realTimeAPI'; -import { olog, isEmpty, groupBy, sortArrayByOrder, pick, sortKeys, omit, sortObjectsByKeysMap } from '@/utils/commons'; +import { olog, isEmpty, groupBy, sortArrayByOrder, pick, sortKeys, omit, sortObjectsByKeysMap, merge } from '@/utils/commons'; import { logWebsocket, clean7DaysWebsocketLog } from '@/utils/indexedDB' import { receivedMsgTypeMapped, handleNotification } from '@/channel/bubbleMsgUtils'; import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK, fetchTags } from '@/actions/ConversationActions'; @@ -278,13 +278,17 @@ const conversationSlice = (set, get) => ({ // 让当前会话显示在页面上 let _tmpCurrentMsgs = []; if (currentConversation.sn) { - _tmpCurrentMsgs = activeConversations[currentConversation.sn]; + // _tmpCurrentMsgs = activeConversations[currentConversation.sn]; } const conversationsMapped = conversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); - if (currentConversation.sn) { - const hasCurrent = Object.keys(conversationsMapped).findIndex(sn => Number(sn) === Number(currentConversation.sn)) !== -1; - conversationsMapped[currentConversation.sn] = _tmpCurrentMsgs; - const _len = hasCurrent ? 0 : conversationsList.unshift(currentConversation); + const indexCurrent = currentConversation.sn ? conversationsList.findIndex(ele => Number(ele.sn) === Number(currentConversation.sn)) : -1; + if (indexCurrent !== -1) { + const [currentElement] = conversationsList.splice(indexCurrent, 1); + conversationsList.unshift(currentElement); // Add to top + // const hasCurrent = Object.keys(conversationsMapped).findIndex(sn => Number(sn) === Number(currentConversation.sn)) !== -1; + // conversationsMapped[currentConversation.sn] = _tmpCurrentMsgs; + // conversationsList.unshift(hasCurrent ? ) + // hasCurrent ? 0 : conversationsList.unshift(currentConversation); } const { topList, pageList } = sortConversationList(conversationsList); @@ -320,9 +324,11 @@ const conversationSlice = (set, get) => ({ const needUpdateCurrent = -1 !== newList.findIndex(row => Number(row.sn) === Number(currentConversation.sn)); const updateCurrent = needUpdateCurrent ? { currentConversation: newList.find(row => Number(row.sn) === Number(currentConversation.sn)) } : {}; // 让当前会话显示在页面上 - if (currentConversation.sn) { - const hasCurrent = -1 !== Object.keys(mergedListMsgs).findIndex(sn => Number(sn) === Number(currentConversation.sn)); - hasCurrent ? 0 : mergedList.unshift(currentConversation); + const indexCurrent = currentConversation.sn ? mergedList.findIndex(ele => Number(ele.sn) === Number(currentConversation.sn)) : -1; + if (indexCurrent !== -1 ) { + const [currentElement] = mergedList.splice(indexCurrent, 1); + mergedList.unshift(currentElement); // Add to top + // hasCurrent ? 0 : mergedList.unshift(currentConversation); } const refreshTotalNotify = mergedList.reduce((r, c) => r+(c.unread_msg_count === UNREAD_MARK ? 0 : c.unread_msg_count), 0);