feat: 添加任意对话, chore: 使用 User.create (createWithUserNameChecked 已移除)
This commit is contained in:
@@ -102,7 +102,7 @@ export default class UserApi extends BaseApi {
|
|||||||
const nickname: string = args.nickname as string
|
const nickname: string = args.nickname as string
|
||||||
const password: string = args.password as string
|
const password: string = args.password as string
|
||||||
|
|
||||||
const user = User.createWithUserNameChecked(username, password, nickname, null)
|
const user = User.create(username, password, nickname, null)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
msg: "成功",
|
msg: "成功",
|
||||||
@@ -261,7 +261,7 @@ export default class UserApi extends BaseApi {
|
|||||||
})
|
})
|
||||||
// 添加聯絡人
|
// 添加聯絡人
|
||||||
this.registerEvent("User.addContact", (args, { deviceId }) => {
|
this.registerEvent("User.addContact", (args, { deviceId }) => {
|
||||||
if (this.checkArgsMissing(args, ['token']) || (args.chat_id == null && args.account == null)) return {
|
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
||||||
msg: "參數缺失",
|
msg: "參數缺失",
|
||||||
code: 400,
|
code: 400,
|
||||||
}
|
}
|
||||||
@@ -273,18 +273,18 @@ export default class UserApi extends BaseApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = User.findById(token.author) as User
|
const user = User.findById(token.author) as User
|
||||||
if (args.chat_id)
|
const chat = Chat.findById(args.target as string)
|
||||||
user!.addContact(args.chat_id as string)
|
const targetUser = User.findByAccount(args.target as string) as User
|
||||||
else if (args.account) {
|
if (chat)
|
||||||
const targetUser = User.findByAccount(args.account as string) as User
|
|
||||||
if (targetUser == null) {
|
|
||||||
return {
|
|
||||||
msg: "找不到用戶",
|
|
||||||
code: 404,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const chat = ChatPrivate.findOrCreateForPrivate(user, targetUser)
|
|
||||||
user!.addContact(chat.bean.id)
|
user!.addContact(chat.bean.id)
|
||||||
|
else if (targetUser) {
|
||||||
|
const privChat = ChatPrivate.findOrCreateForPrivate(user, targetUser)
|
||||||
|
user!.addContact(privChat.bean.id)
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
msg: "找不到目标",
|
||||||
|
code: 404,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user