From 67622fa56547324c3a3831568f30ed5f76ddda02 Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Tue, 2 Sep 2025 15:30:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E8=BF=9E=E5=90=8E=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E9=A1=BA=E5=BA=8F=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-uniapp/store/chatStore.js | 12 ++++++------ im-web/src/store/chatStore.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index ad6bfce..16d3419 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -335,11 +335,11 @@ export default defineStore('chatStore', { } }, refreshChats() { - if (!cacheChats) return; + let chats = cacheChats || this.chats; // 更新会话免打扰状态 const friendStore = useFriendStore(); const groupStore = useGroupStore(); - cacheChats.forEach(chat => { + chats.forEach(chat => { if (chat.type == 'PRIVATE') { let friend = friendStore.findFriend(chat.targetId); if (friend) { @@ -353,17 +353,17 @@ export default defineStore('chatStore', { } }) // 排序 - cacheChats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); + chats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); // #ifndef APP-PLUS /** * 由于h5和小程序的stroge只有5m,大约只能存储2w条消息,所以可能需要清理部分历史消息 */ - this.fliterMessage(cacheChats, 5000, 1000); + this.fliterMessage(chats, 5000, 1000); // #endif // 记录热数据索引位置 - cacheChats.forEach(chat => chat.hotMinIdx = chat.messages.length); + chats.forEach(chat => chat.hotMinIdx = chat.messages.length); // 将消息一次性装载回来 - this.chats = cacheChats; + this.chats = chats; // 清空缓存,不再使用 cacheChats = null; // 消息持久化 diff --git a/im-web/src/store/chatStore.js b/im-web/src/store/chatStore.js index a910c68..046d842 100644 --- a/im-web/src/store/chatStore.js +++ b/im-web/src/store/chatStore.js @@ -333,11 +333,11 @@ export default defineStore('chatStore', { } }, refreshChats() { - if (!cacheChats) return; + let chats = cacheChats || this.chats; // 刷新免打扰状态 const friendStore = useFriendStore(); const groupStore = useGroupStore(); - cacheChats.forEach(chat => { + chats.forEach(chat => { if (chat.type == 'PRIVATE') { let friend = friendStore.findFriend(chat.targetId); if (friend) { @@ -351,18 +351,18 @@ export default defineStore('chatStore', { } }) // 排序 - cacheChats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); + chats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); /** * 由于部分浏览器不支持websql或indexdb,只能使用localstorage,而localstorage大小只有10m,可能会导致缓存空间溢出 * 解决办法:针对只能使用localstorage的浏览器,最多保留1w条消息,每个会话最多保留1000条消息 */ if (localForage.driver().includes("localStorage")) { - this.fliterMessage(cacheChats, 10000, 1000) + this.fliterMessage(chats, 10000, 1000) } // 记录热数据索引位置 - cacheChats.forEach(chat => chat.hotMinIdx = chat.messages.length); + chats.forEach(chat => chat.hotMinIdx = chat.messages.length); // 将消息一次性装载回来 - this.chats = cacheChats; + this.chats = chats; // 清空缓存 cacheChats = null; // 持久化消息