feat: 最近对话
This commit is contained in:
@@ -207,20 +207,22 @@ export default class UserApi extends BaseApi {
|
||||
|
||||
const user = User.findById(token.author) as User
|
||||
const recentChats = user.getRecentChats()
|
||||
const recentChatsList = []
|
||||
for (const [chatId, content] of recentChats) {
|
||||
const chat = Chat.findById(chatId)
|
||||
recentChatsList.push({
|
||||
content,
|
||||
id: chatId,
|
||||
title: chat?.getTitle(user) || "未知",
|
||||
avatar: chat?.getAvatarFileHash(user) ? "uploaded_files/" + chat?.getAvatarFileHash(user) : undefined
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
msg: "成功",
|
||||
code: 200,
|
||||
data: {
|
||||
recent_chats: recentChats.forEach((content: string, chatId: string) => {
|
||||
const chat = Chat.findById(chatId)
|
||||
return {
|
||||
content,
|
||||
id: chatId,
|
||||
title: chat?.getTitle(user) || "未知",
|
||||
avatar: chat?.getAvatarFileHash(user) ? "uploaded_files/" + chat?.getAvatarFileHash(user) : undefined
|
||||
}
|
||||
})
|
||||
recent_chats: recentChatsList.reverse(),
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -132,9 +132,9 @@ export default class User {
|
||||
map.set(chatId, content)
|
||||
this.setAttr("recent_chats", JSON.stringify(map, MapJson.replacer))
|
||||
}
|
||||
getRecentChats() {
|
||||
getRecentChats(): Map<string, string> {
|
||||
try {
|
||||
return JSON.parse(this.bean.recent_chats, MapJson.reviver) as Map<string, string>
|
||||
return JSON.parse(this.bean.recent_chats, MapJson.reviver)
|
||||
} catch (e) {
|
||||
console.log(chalk.yellow(`警告: 最近对话列表解析失敗: ${(e as Error).message}`))
|
||||
return new Map()
|
||||
|
||||
Reference in New Issue
Block a user