|
|
|
@ -35,40 +35,40 @@ export default defineStore('chatStore', { |
|
|
|
}, |
|
|
|
actions: { |
|
|
|
cleanOfflineChats() { |
|
|
|
const friendStore = useFriendStore(); |
|
|
|
const onlineFriendIds = friendStore.onlineFriendIds || []; |
|
|
|
// 获取当前会话列表
|
|
|
|
let chats = this.findChats(); |
|
|
|
let removedCount = 0; |
|
|
|
const friendStore = useFriendStore(); |
|
|
|
const onlineFriendIds = friendStore.onlineFriendIds || []; |
|
|
|
// 获取当前会话列表
|
|
|
|
let chats = this.findChats(); |
|
|
|
let removedCount = 0; |
|
|
|
|
|
|
|
// 从后往前遍历,避免删除时索引错乱
|
|
|
|
for (let idx = chats.length - 1; idx >= 0; idx--) { |
|
|
|
const chat = chats[idx]; |
|
|
|
// 从后往前遍历,避免删除时索引错乱
|
|
|
|
for (let idx = chats.length - 1; idx >= 0; idx--) { |
|
|
|
const chat = chats[idx]; |
|
|
|
|
|
|
|
// 只处理私聊会话
|
|
|
|
if (chat.type === 'PRIVATE') { |
|
|
|
const isOnline = onlineFriendIds.includes(chat.targetId); |
|
|
|
// 只处理私聊会话
|
|
|
|
if (chat.type === 'PRIVATE') { |
|
|
|
const isOnline = onlineFriendIds.includes(chat.targetId); |
|
|
|
|
|
|
|
|
|
|
|
if (!isOnline) { |
|
|
|
// 标记为删除
|
|
|
|
chat.delete = true; |
|
|
|
chat.stored = false; |
|
|
|
removedCount++; |
|
|
|
if (!isOnline) { |
|
|
|
// 标记为删除
|
|
|
|
chat.delete = true; |
|
|
|
chat.stored = false; |
|
|
|
removedCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清理已删除的会话
|
|
|
|
this.chats = this.chats.filter(chat => !chat.delete); |
|
|
|
// 清理已删除的会话
|
|
|
|
this.chats = this.chats.filter(chat => !chat.delete); |
|
|
|
|
|
|
|
// 保存到存储
|
|
|
|
this.saveToStorage(true); |
|
|
|
// 保存到存储
|
|
|
|
this.saveToStorage(true); |
|
|
|
|
|
|
|
console.log(`清理完成: 删除了 ${removedCount} 个离线会话,剩余 ${this.chats.length} 个会话`); |
|
|
|
console.log(`清理完成: 删除了 ${removedCount} 个离线会话,剩余 ${this.chats.length} 个会话`); |
|
|
|
|
|
|
|
return removedCount; |
|
|
|
}, |
|
|
|
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') { |
|
|
|
|