fix: Chat 獲取 avatar 邏輯錯誤

This commit is contained in:
CrescentLeaf
2025-09-21 02:16:48 +08:00
parent 7686a9b7d1
commit 71e6d24d6e
2 changed files with 9 additions and 4 deletions

View File

@@ -41,8 +41,8 @@ export default class ChatApi extends BaseApi {
msg: "成功",
data: {
type: chat.bean.type,
title: chat.getTitleForPrivate(mine),
avatar: chat.bean.avatar_file_hash ? "uploaded_files/" + chat.bean.avatar_file_hash : chat.bean.avatar_file_hash
title: chat.getTitle(mine),
avatar: chat.getAvatarFileHash(mine) ? "uploaded_files/" + chat.getAvatarFileHash(mine) : undefined
}
}
}

View File

@@ -90,7 +90,12 @@ export default class Chat {
return null
}
getTitleForPrivate(userMySelf: User) {
return this.getAnotherUserForPrivate(userMySelf)?.getNickName() || "未知對話"
getTitle(userMySelf?: User) {
if (this.bean.type == 'group') return this.bean.title
if (this.bean.type == 'private') return this.getAnotherUserForPrivate(userMySelf as User)?.getNickName()
}
getAvatarFileHash(userMySelf?: User) {
if (this.bean.type == 'group') return this.bean.avatar_file_hash
if (this.bean.type == 'private') return this.getAnotherUserForPrivate(userMySelf as User)?.getAvatarFileHash()
}
}