更新了一些功能(媒体预览有bug)

This commit is contained in:
2025-07-03 17:02:08 +08:00
parent bcee1e7cc6
commit 90d6f01b50
12 changed files with 1618 additions and 386 deletions

View File

@@ -84,6 +84,15 @@ export const useChatStore = defineStore("chat", () => {
}
}
// 设置当前好友 - 新增方法
const setCurrentFriend = (friend) => {
currentFriend.value = friend
// 清除未读消息计数
if (friend) {
friend.unreadCount = 0
}
}
// 切换当前聊天好友
const switchFriend = async (friend, currentUserId) => {
currentFriend.value = friend
@@ -101,27 +110,6 @@ export const useChatStore = defineStore("chat", () => {
messages.value = []
}
}
// 切换当前聊天好友
const setCurrentFriend = async (friend, currentUserId) => {
currentFriend.value = friend
// 清空未读消息计数
friend.unreadCount = 0
await chatDB.clearUnreadCount(friend.id)
// 加载聊天记录
try {
const chatHistory = await chatDB.getChatHistory(currentUserId, friend.id)
console.log("chatHistory:", chatHistory)
console.log("currentUserId:", currentUserId)
console.log("friend.id:", friend.id)
messages.value = chatHistory.sort((a, b) => a.timestamp - b.timestamp)
console.log("messages.value:", messages.value)
} catch (error) {
console.error("加载聊天记录失败:", error)
messages.value = []
}
}
// 添加消息
const addMessage = async (message, currentUserId) => {
@@ -215,8 +203,8 @@ export const useChatStore = defineStore("chat", () => {
connectionStatusIcon,
initDB,
loadFriends,
switchFriend,
setCurrentFriend,
switchFriend,
addMessage,
handleIncomingMessage,
}