From 7378024235b7b6e152cd1fd1d6c07a73fcef73f3 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 6 Oct 2025 02:11:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D,=20chore:=20=E4=BD=BF=E7=94=A8=20User.create?= =?UTF-8?q?=20(createWithUserNameChecked=20=E5=B7=B2=E7=A7=BB=E9=99=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/UserApi.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/server/api/UserApi.ts b/server/api/UserApi.ts index 6660e96..b700f9e 100644 --- a/server/api/UserApi.ts +++ b/server/api/UserApi.ts @@ -102,7 +102,7 @@ export default class UserApi extends BaseApi { const nickname: string = args.nickname 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 { msg: "成功", @@ -261,7 +261,7 @@ export default class UserApi extends BaseApi { }) // 添加聯絡人 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: "參數缺失", code: 400, } @@ -273,18 +273,18 @@ export default class UserApi extends BaseApi { } const user = User.findById(token.author) as User - if (args.chat_id) - user!.addContact(args.chat_id as string) - else if (args.account) { - const targetUser = User.findByAccount(args.account as string) as User - if (targetUser == null) { - return { - msg: "找不到用戶", - code: 404, - } - } - const chat = ChatPrivate.findOrCreateForPrivate(user, targetUser) + const chat = Chat.findById(args.target as string) + const targetUser = User.findByAccount(args.target as string) as User + if (chat) 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 {