diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index cdd19fc1a..ef5930266 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -856,18 +856,7 @@ class DialogController extends AbstractController public function msg__sendtext() { $user = User::auth(); - // - if (!$user->bot) { - $chatInformation = Base::settingFind('system', 'chat_information'); - if ($chatInformation == 'required') { - if (empty($user->getRawOriginal('nickname'))) { - return Base::retError('请设置昵称', [], -2); - } - if (empty($user->getRawOriginal('tel'))) { - return Base::retError('请设置联系电话', [], -3); - } - } - } + $user->checkChatInformation(); // $dialog_id = intval(Request::input('dialog_id')); $dialog_ids = trim(Request::input('dialog_ids')); @@ -959,6 +948,7 @@ class DialogController extends AbstractController public function msg__sendrecord() { $user = User::auth(); + $user->checkChatInformation(); // $dialog_id = intval(Request::input('dialog_id')); $reply_id = intval(Request::input('reply_id')); @@ -1008,6 +998,7 @@ class DialogController extends AbstractController public function msg__sendfile() { $user = User::auth(); + // $dialogIds = [intval(Request::input('dialog_id'))]; $replyId = intval(Request::input('reply_id')); $imageAttachment = intval(Request::input('image_attachment')); @@ -1040,6 +1031,7 @@ class DialogController extends AbstractController public function msg__sendfiles() { $user = User::auth(); + // $files = Request::file('files'); $image64 = Request::input('image64'); $fileName = Request::input('filename'); diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 3bc2ff3cd..9958f6606 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -40,7 +40,7 @@ class SystemController extends AbstractController * @apiParam {String} type * - get: 获取(默认) * - all: 获取所有(需要管理员权限) - * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'auto_archived', 'archived_day', 'task_visible', 'task_default_time', 'all_group_mute', 'all_group_autoin', 'image_compress', 'image_save_local', 'start_home']) + * - save: 保存设置(参数:['reg', 'reg_identity', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_information', 'anon_message', 'auto_archived', 'archived_day', 'task_visible', 'task_default_time', 'all_group_mute', 'all_group_autoin', 'user_private_chat_mute', 'user_group_chat_mute', 'image_compress', 'image_save_local', 'start_home']) * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -71,6 +71,8 @@ class SystemController extends AbstractController 'task_default_time', 'all_group_mute', 'all_group_autoin', + 'user_private_chat_mute', + 'user_group_chat_mute', 'image_compress', 'image_save_local', 'start_home', @@ -114,6 +116,8 @@ class SystemController extends AbstractController $setting['task_default_time'] = $setting['task_default_time'] ? Base::json2array($setting['task_default_time']) : ['09:00', '18:00']; $setting['all_group_mute'] = $setting['all_group_mute'] ?: 'open'; $setting['all_group_autoin'] = $setting['all_group_autoin'] ?: 'yes'; + $setting['user_private_chat_mute'] = $setting['user_private_chat_mute'] ?: 'open'; + $setting['user_group_chat_mute'] = $setting['user_group_chat_mute'] ?: 'open'; $setting['image_compress'] = $setting['image_compress'] ?: 'open'; $setting['image_save_local'] = $setting['image_save_local'] ?: 'open'; $setting['start_home'] = $setting['start_home'] ?: 'close'; diff --git a/app/Models/User.php b/app/Models/User.php index 49bb59c35..8f868dc68 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -290,6 +290,26 @@ class User extends AbstractModel }); } + /** + * 检查发送聊天内容前必须设置昵称、电话 + * @return void + */ + public function checkChatInformation() + { + if ($this->bot) { + return; + } + $chatInformation = Base::settingFind('system', 'chat_information'); + if ($chatInformation == 'required') { + if (empty($this->getRawOriginal('nickname'))) { + throw new ApiException('请设置昵称', [], -2); + } + if (empty($this->getRawOriginal('tel'))) { + throw new ApiException('请设置联系电话', [], -3); + } + } + } + /** ***************************************************************************************** */ /** ***************************************************************************************** */ /** ***************************************************************************************** */ diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index 05a8f6cda..5661f4901 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -197,9 +197,13 @@ class WebSocketDialog extends AbstractModel $this->dialog_delete = 1; } $this->dialog_user = $dialog_user; + $this->dialog_mute = Base::settingFind('system', 'user_private_chat_mute'); break; case "group": switch ($this->group_type) { + case 'user': + $this->dialog_mute = Base::settingFind('system', 'user_group_chat_mute'); + break; case 'project': $this->group_info = Project::withTrashed()->select(['id', 'name', 'archived_at', 'deleted_at'])->whereDialogId($this->id)->first()?->cancelAppend()->cancelHidden(); if ($this->group_info) { @@ -220,7 +224,7 @@ class WebSocketDialog extends AbstractModel break; case 'all': $this->name = Doo::translate('全体成员'); - $this->all_group_mute = Base::settingFind('system', 'all_group_mute'); + $this->dialog_mute = Base::settingFind('system', 'all_group_mute'); break; } break; @@ -459,17 +463,37 @@ class WebSocketDialog extends AbstractModel */ public function checkMute($userid) { - if ($this->group_type === 'all') { - $allGroupMute = Base::settingFind('system', 'all_group_mute'); - switch ($allGroupMute) { - case 'all': - throw new ApiException('当前会话全员禁言'); - case 'user': - if (!User::find($userid)?->isAdmin()) { - throw new ApiException('当前会话禁言'); + $muteMsgTip = null; + $systemConfig = Base::setting('system'); + switch ($this->type) { + case 'user': + if ($systemConfig['user_private_chat_mute'] === 'close') { + $muteMsgTip = '个人会话禁言'; + } + break; + + case 'group': + if ($this->group_type === 'user') { + if ($systemConfig['user_group_chat_mute'] === 'close') { + $muteMsgTip = '个人群组禁言'; } + } elseif ($this->group_type === 'all') { + if ($systemConfig['all_group_mute'] === 'close') { + $muteMsgTip = '当前会话全员禁言'; + } + } + break; + } + if ($muteMsgTip === null) { + return; + } + if ($userid) { + $user = User::find($userid); + if ($user?->bot || $user?->isAdmin()) { // 机器人或管理员不受禁言 + return; } } + throw new ApiException($muteMsgTip); } /** diff --git a/database/migrations/2024_02_05_212046_all_group_mute_handle.php b/database/migrations/2024_02_05_212046_all_group_mute_handle.php new file mode 100644 index 000000000..5493a5233 --- /dev/null +++ b/database/migrations/2024_02_05_212046_all_group_mute_handle.php @@ -0,0 +1,34 @@ + {{$L('开放')}} - {{$L('成员禁言')}} - {{$L('全部禁言')}} + {{$L('禁言')}} -
{{$L('开放:所有人都可以发言。')}}
-
{{$L('成员禁言:仅管理员可以发言。')}}
-
{{$L('全部禁言:所有人都禁止发言。')}}
+
{{$L('开放:所有人都可以在全员群组发言。')}}
+
{{$L('禁言:除管理员外所有人都禁止在全员群组发言。')}}
@@ -135,6 +133,27 @@
{{$L('自动:注册成功后自动进入全员群。')}}
{{$L('关闭:其他成员通过@邀请进入。')}}
+ + + {{$L('开放')}} + {{$L('禁言')}} + +
{{$L('开放:所有人都可以相互发起个人聊天。')}}
+
{{$L('禁言:除管理员外所有人都禁止发起个人聊天。')}}
+
+ + + {{$L('开放')}} + {{$L('禁言')}} + +
{{$L('开放:允许个人群组聊天发言。')}}
+
+
    +
  1. {{$L('除管理员外禁止个人群组聊天发言。')}}
  2. +
  3. {{$L('注意,仅禁止个人群组,其他类型的群组不禁止,比如:部门群聊、项目群聊等系统群聊。')}}
  4. +
+
+
{{$L('可选')}}