TODO: 推翻整个项目重新建立根基
This commit is contained in:
@@ -121,6 +121,25 @@ export default class LingChairClient {
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 建议在 auth 返回 true 时调用
|
||||
*/
|
||||
getCachedAccessToken() {
|
||||
return this.access_token
|
||||
}
|
||||
/**
|
||||
* 建议在 auth 返回 true 时调用
|
||||
*/
|
||||
getCachedRefreshToken() {
|
||||
return this.refresh_token
|
||||
}
|
||||
/**
|
||||
* 客户端上线
|
||||
*
|
||||
* 使用验证方式优先级: 访问 > 刷新 > 账号密码
|
||||
*
|
||||
* 不会逐一尝试
|
||||
*/
|
||||
async auth(args: {
|
||||
refresh_token?: string,
|
||||
access_token?: string,
|
||||
@@ -134,6 +153,13 @@ export default class LingChairClient {
|
||||
return false
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 客户端上线
|
||||
*
|
||||
* 使用验证方式优先级: 访问 > 刷新 > 账号密码
|
||||
*
|
||||
* 不会逐一尝试
|
||||
*/
|
||||
async authOrThrow(args: {
|
||||
refresh_token?: string,
|
||||
access_token?: string,
|
||||
|
||||
13
client-protocol/RecentChat.ts
Normal file
13
client-protocol/RecentChat.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import RecentChatBean from "./bean/RecentChatBean.ts"
|
||||
import Chat from "./Chat.ts"
|
||||
import LingChairClient from "./LingChairClient.ts"
|
||||
|
||||
export default class RecentChat extends Chat {
|
||||
declare bean: RecentChatBean
|
||||
constructor(client: LingChairClient, bean: RecentChatBean) {
|
||||
super(client, bean)
|
||||
}
|
||||
getContent() {
|
||||
return this.bean.content
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import CallbackError from "./CallbackError.ts"
|
||||
import Chat from "./Chat.ts"
|
||||
import LingChairClient from "./LingChairClient.ts"
|
||||
import RecentChat from "./RecentChat.ts"
|
||||
import User from "./User.ts"
|
||||
import ChatBean from "./bean/ChatBean.ts"
|
||||
import RecentChatBean from "./bean/RecentChatBean.ts"
|
||||
@@ -157,6 +159,16 @@ export default class UserMySelf extends User {
|
||||
return re.data!.recent_chats as ChatBean[]
|
||||
throw new CallbackError(re)
|
||||
}
|
||||
async getMyFavouriteChats() {
|
||||
try {
|
||||
return await this.getMyFavouriteChatsOrThrow()
|
||||
} catch (_) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
async getMyFavouriteChatsOrThrow() {
|
||||
return (await this.getMyFavouriteChatBeansOrThrow()).map((bean) => new Chat(this.client, bean))
|
||||
}
|
||||
/*
|
||||
* ================================================
|
||||
* 最近对话
|
||||
@@ -177,6 +189,16 @@ export default class UserMySelf extends User {
|
||||
return re.data!.recent_chats as RecentChatBean[]
|
||||
throw new CallbackError(re)
|
||||
}
|
||||
async getMyRecentChats() {
|
||||
try {
|
||||
return await this.getMyRecentChatsOrThrow()
|
||||
} catch (_) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
async getMyRecentChatsOrThrow() {
|
||||
return (await this.getMyRecentChatBeansOrThrow()).map((bean) => new RecentChat(this.client, bean))
|
||||
}
|
||||
/*
|
||||
* ================================================
|
||||
* 所有对话
|
||||
@@ -197,4 +219,14 @@ export default class UserMySelf extends User {
|
||||
return re.data!.all_chats as ChatBean[]
|
||||
throw new CallbackError(re)
|
||||
}
|
||||
async getMyAllChats() {
|
||||
try {
|
||||
return await this.getMyAllChatsOrThrow()
|
||||
} catch (_) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
async getMyAllChatsOrThrow() {
|
||||
return (await this.getMyAllChatBeansOrThrow()).map((bean) => new Chat(this.client, bean))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ChatBean from "./ChatBean.ts"
|
||||
|
||||
export default class RecentChat extends ChatBean {
|
||||
export default class RecentChatBean extends ChatBean {
|
||||
declare content: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user