Browse Source

fix: 重连后会话顺序异常的bug

master
xsx 7 months ago
parent
commit
67622fa565
  1. 12
      im-uniapp/store/chatStore.js
  2. 12
      im-web/src/store/chatStore.js

12
im-uniapp/store/chatStore.js

@ -335,11 +335,11 @@ export default defineStore('chatStore', {
} }
}, },
refreshChats() { refreshChats() {
if (!cacheChats) return; let chats = cacheChats || this.chats;
// 更新会话免打扰状态 // 更新会话免打扰状态
const friendStore = useFriendStore(); const friendStore = useFriendStore();
const groupStore = useGroupStore(); const groupStore = useGroupStore();
cacheChats.forEach(chat => { chats.forEach(chat => {
if (chat.type == 'PRIVATE') { if (chat.type == 'PRIVATE') {
let friend = friendStore.findFriend(chat.targetId); let friend = friendStore.findFriend(chat.targetId);
if (friend) { 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 // #ifndef APP-PLUS
/** /**
* 由于h5和小程序的stroge只有5m,大约只能存储2w条消息所以可能需要清理部分历史消息 * 由于h5和小程序的stroge只有5m,大约只能存储2w条消息所以可能需要清理部分历史消息
*/ */
this.fliterMessage(cacheChats, 5000, 1000); this.fliterMessage(chats, 5000, 1000);
// #endif // #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; cacheChats = null;
// 消息持久化 // 消息持久化

12
im-web/src/store/chatStore.js

@ -333,11 +333,11 @@ export default defineStore('chatStore', {
} }
}, },
refreshChats() { refreshChats() {
if (!cacheChats) return; let chats = cacheChats || this.chats;
// 刷新免打扰状态 // 刷新免打扰状态
const friendStore = useFriendStore(); const friendStore = useFriendStore();
const groupStore = useGroupStore(); const groupStore = useGroupStore();
cacheChats.forEach(chat => { chats.forEach(chat => {
if (chat.type == 'PRIVATE') { if (chat.type == 'PRIVATE') {
let friend = friendStore.findFriend(chat.targetId); let friend = friendStore.findFriend(chat.targetId);
if (friend) { 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,可能会导致缓存空间溢出 * 由于部分浏览器不支持websql或indexdb只能使用localstorage而localstorage大小只有10m,可能会导致缓存空间溢出
* 解决办法:针对只能使用localstorage的浏览器最多保留1w条消息,每个会话最多保留1000条消息 * 解决办法:针对只能使用localstorage的浏览器最多保留1w条消息,每个会话最多保留1000条消息
*/ */
if (localForage.driver().includes("localStorage")) { 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; cacheChats = null;
// 持久化消息 // 持久化消息

Loading…
Cancel
Save