feat(wip): 對話
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import chalk from "chalk"
|
||||
import Chat from "./Chat.ts"
|
||||
import User from "./User.ts";
|
||||
import User from "./User.ts"
|
||||
|
||||
export default class ChatPrivate extends Chat {
|
||||
static fromChat(chat: Chat) {
|
||||
return new ChatPrivate(chat.bean)
|
||||
}
|
||||
|
||||
static getChatIdByUsersId(userIdA: string, userIdB: string) {
|
||||
return [userIdA, userIdB].sort().join('-')
|
||||
}
|
||||
@@ -9,8 +14,16 @@ export default class ChatPrivate extends Chat {
|
||||
static createForPrivate(userA: User, userB: User) {
|
||||
return this.create(this.getChatIdByUsersId(userA.bean.id, userB.bean.id), 'private')
|
||||
}
|
||||
static findForPrivate() {
|
||||
|
||||
static findForPrivate(userA: User, userB: User) {
|
||||
return this.fromChat(this.findById(this.getChatIdByUsersId(userA.bean.id, userB.bean.id)) as Chat)
|
||||
}
|
||||
static findOrCreateForPrivate(userA: User, userB: User) {
|
||||
let a = this.findForPrivate(userA, userB)
|
||||
if (a == null) {
|
||||
this.createForPrivate(userA, userB)
|
||||
a = this.findForPrivate(userA, userB) as ChatPrivate
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
getTitleForPrivate(user: User, targetUser: User) {
|
||||
|
||||
Reference in New Issue
Block a user