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; // 持久化消息