From d64145a3fbf09e8f220ac8efd04babb03e9648a1 Mon Sep 17 00:00:00 2001 From: "[yxf]" <[1524240689@qq.com]> Date: Mon, 27 Apr 2026 17:08:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=A2=E6=9C=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=AD=9B=E9=80=89=E6=8D=A2=E4=B8=AA=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/account/AccountSwitchMenu.vue | 2 +- im-web/src/store/chatStore.js | 70 +++++++++++-------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/im-web/src/components/account/AccountSwitchMenu.vue b/im-web/src/components/account/AccountSwitchMenu.vue index a025e09..8f50dd1 100644 --- a/im-web/src/components/account/AccountSwitchMenu.vue +++ b/im-web/src/components/account/AccountSwitchMenu.vue @@ -55,7 +55,7 @@ {{ account.nickName }}
@{{ account.userName }}
-
ID: {{ account.id }}
+
= 0; idx--) { - const chat = chats[idx]; + const friendStore = useFriendStore(); + const onlineFriendIds = friendStore.onlineFriendIds || []; + // 获取当前会话列表 + let chats = this.findChats(); + let removedCount = 0; - // 只处理私聊会话 - if (chat.type === 'PRIVATE') { - const isOnline = onlineFriendIds.includes(chat.targetId); - + // 从后往前遍历,避免删除时索引错乱 + for (let idx = chats.length - 1; idx >= 0; idx--) { + const chat = chats[idx]; - if (!isOnline) { - // 标记为删除 - chat.delete = true; - chat.stored = false; - removedCount++; + // 只处理私聊会话 + if (chat.type === 'PRIVATE') { + const isOnline = onlineFriendIds.includes(chat.targetId); + + + if (!isOnline) { + // 标记为删除 + chat.delete = true; + chat.stored = false; + removedCount++; + } } } - } - - // 清理已删除的会话 - this.chats = this.chats.filter(chat => !chat.delete); - - // 保存到存储 - this.saveToStorage(true); - - console.log(`清理完成: 删除了 ${removedCount} 个离线会话,剩余 ${this.chats.length} 个会话`); - - return removedCount; - }, + + // 清理已删除的会话 + this.chats = this.chats.filter(chat => !chat.delete); + + // 保存到存储 + this.saveToStorage(true); + + console.log(`清理完成: 删除了 ${removedCount} 个离线会话,剩余 ${this.chats.length} 个会话`); + + return removedCount; + }, initChats(chatsData) { this.chats = []; this.privateMsgMaxId = chatsData.privateMsgMaxId || 0; @@ -373,6 +373,16 @@ export default defineStore('chatStore', { let chats = cacheChats || this.chats; // 刷新免打扰状态 const friendStore = useFriendStore(); + const onlineFriendIds = friendStore.onlineFriendIds || []; + chats = chats.filter(chat => { + // 保留群聊 + if (chat.type === 'GROUP') return true; + // 私聊只保留在线好友的 + if (chat.type === 'PRIVATE') { + return onlineFriendIds.includes(chat.targetId); + } + return true; + }); const groupStore = useGroupStore(); chats.forEach(chat => { if (chat.type == 'PRIVATE') {