perf: 新增禁止私聊、群聊功能

This commit is contained in:
kuaifan 2024-02-05 13:46:23 +08:00
parent 7dd5b082cf
commit 7efaf3bb32
7 changed files with 122 additions and 35 deletions

View File

@ -856,18 +856,7 @@ class DialogController extends AbstractController
public function msg__sendtext() public function msg__sendtext()
{ {
$user = User::auth(); $user = User::auth();
// $user->checkChatInformation();
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);
}
}
}
// //
$dialog_id = intval(Request::input('dialog_id')); $dialog_id = intval(Request::input('dialog_id'));
$dialog_ids = trim(Request::input('dialog_ids')); $dialog_ids = trim(Request::input('dialog_ids'));
@ -959,6 +948,7 @@ class DialogController extends AbstractController
public function msg__sendrecord() public function msg__sendrecord()
{ {
$user = User::auth(); $user = User::auth();
$user->checkChatInformation();
// //
$dialog_id = intval(Request::input('dialog_id')); $dialog_id = intval(Request::input('dialog_id'));
$reply_id = intval(Request::input('reply_id')); $reply_id = intval(Request::input('reply_id'));
@ -1008,6 +998,7 @@ class DialogController extends AbstractController
public function msg__sendfile() public function msg__sendfile()
{ {
$user = User::auth(); $user = User::auth();
//
$dialogIds = [intval(Request::input('dialog_id'))]; $dialogIds = [intval(Request::input('dialog_id'))];
$replyId = intval(Request::input('reply_id')); $replyId = intval(Request::input('reply_id'));
$imageAttachment = intval(Request::input('image_attachment')); $imageAttachment = intval(Request::input('image_attachment'));
@ -1040,6 +1031,7 @@ class DialogController extends AbstractController
public function msg__sendfiles() public function msg__sendfiles()
{ {
$user = User::auth(); $user = User::auth();
//
$files = Request::file('files'); $files = Request::file('files');
$image64 = Request::input('image64'); $image64 = Request::input('image64');
$fileName = Request::input('filename'); $fileName = Request::input('filename');

View File

@ -40,7 +40,7 @@ class SystemController extends AbstractController
* @apiParam {String} type * @apiParam {String} type
* - get: 获取(默认) * - get: 获取(默认)
* - all: 获取所有(需要管理员权限) * - 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 {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {String} msg 返回信息(错误描述)
@ -71,6 +71,8 @@ class SystemController extends AbstractController
'task_default_time', 'task_default_time',
'all_group_mute', 'all_group_mute',
'all_group_autoin', 'all_group_autoin',
'user_private_chat_mute',
'user_group_chat_mute',
'image_compress', 'image_compress',
'image_save_local', 'image_save_local',
'start_home', '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['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_mute'] = $setting['all_group_mute'] ?: 'open';
$setting['all_group_autoin'] = $setting['all_group_autoin'] ?: 'yes'; $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_compress'] = $setting['image_compress'] ?: 'open';
$setting['image_save_local'] = $setting['image_save_local'] ?: 'open'; $setting['image_save_local'] = $setting['image_save_local'] ?: 'open';
$setting['start_home'] = $setting['start_home'] ?: 'close'; $setting['start_home'] = $setting['start_home'] ?: 'close';

View File

@ -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);
}
}
}
/** ***************************************************************************************** */ /** ***************************************************************************************** */
/** ***************************************************************************************** */ /** ***************************************************************************************** */
/** ***************************************************************************************** */ /** ***************************************************************************************** */

View File

@ -197,9 +197,13 @@ class WebSocketDialog extends AbstractModel
$this->dialog_delete = 1; $this->dialog_delete = 1;
} }
$this->dialog_user = $dialog_user; $this->dialog_user = $dialog_user;
$this->dialog_mute = Base::settingFind('system', 'user_private_chat_mute');
break; break;
case "group": case "group":
switch ($this->group_type) { switch ($this->group_type) {
case 'user':
$this->dialog_mute = Base::settingFind('system', 'user_group_chat_mute');
break;
case 'project': case 'project':
$this->group_info = Project::withTrashed()->select(['id', 'name', 'archived_at', 'deleted_at'])->whereDialogId($this->id)->first()?->cancelAppend()->cancelHidden(); $this->group_info = Project::withTrashed()->select(['id', 'name', 'archived_at', 'deleted_at'])->whereDialogId($this->id)->first()?->cancelAppend()->cancelHidden();
if ($this->group_info) { if ($this->group_info) {
@ -220,7 +224,7 @@ class WebSocketDialog extends AbstractModel
break; break;
case 'all': case 'all':
$this->name = Doo::translate('全体成员'); $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;
} }
break; break;
@ -459,17 +463,37 @@ class WebSocketDialog extends AbstractModel
*/ */
public function checkMute($userid) public function checkMute($userid)
{ {
if ($this->group_type === 'all') { $muteMsgTip = null;
$allGroupMute = Base::settingFind('system', 'all_group_mute'); $systemConfig = Base::setting('system');
switch ($allGroupMute) { switch ($this->type) {
case 'all': case 'user':
throw new ApiException('当前会话全员禁言'); if ($systemConfig['user_private_chat_mute'] === 'close') {
case 'user': $muteMsgTip = '个人会话禁言';
if (!User::find($userid)?->isAdmin()) { }
throw new ApiException('当前会话禁言'); 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);
} }
/** /**

View File

@ -0,0 +1,34 @@
<?php
use App\Models\User;
use App\Models\WebSocketDialog;
use App\Module\Base;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
class AllGroupMuteHandle extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$systemConfig = Base::setting('system');
if ($systemConfig['all_group_mute'] == 'user' || $systemConfig['all_group_mute'] == 'all') {
$systemConfig['all_group_mute'] = 'close';
Base::setting('system', $systemConfig);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}

View File

@ -1047,14 +1047,8 @@ export default {
}, },
isMute() { isMute() {
if (this.dialogData.group_type === 'all') { if (this.dialogData.dialog_mute === 'close') {
if (this.dialogData.all_group_mute === 'all') { return !this.userIsAdmin
return true
} else if (this.dialogData.all_group_mute === 'user') {
if (!this.userIsAdmin) {
return true
}
}
} }
return false return false
}, },

View File

@ -120,12 +120,10 @@
<FormItem :label="$L('全员群组禁言')" prop="allGroupMute"> <FormItem :label="$L('全员群组禁言')" prop="allGroupMute">
<RadioGroup v-model="formDatum.all_group_mute"> <RadioGroup v-model="formDatum.all_group_mute">
<Radio label="open">{{$L('开放')}}</Radio> <Radio label="open">{{$L('开放')}}</Radio>
<Radio label="user">{{$L('成员禁言')}}</Radio> <Radio label="close">{{$L('禁言')}}</Radio>
<Radio label="all">{{$L('全部禁言')}}</Radio>
</RadioGroup> </RadioGroup>
<div v-if="formDatum.all_group_mute == 'open'" class="form-tip">{{$L('开放所有人都可以发言')}}</div> <div v-if="formDatum.all_group_mute == 'open'" class="form-tip">{{$L('开放所有人都可以在全员群组发言')}}</div>
<div v-else-if="formDatum.all_group_mute == 'user'" class="form-tip">{{$L('成员禁言:仅管理员可以发言。')}}</div> <div v-else-if="formDatum.all_group_mute == 'close'" class="form-tip">{{$L('禁言:除管理员外所有人都禁止在全员群组发言。')}}</div>
<div v-else-if="formDatum.all_group_mute == 'all'" class="form-tip">{{$L('全部禁言:所有人都禁止发言。')}}</div>
</FormItem> </FormItem>
<FormItem :label="$L('自动进入全员群')" prop="allGroupAutoin"> <FormItem :label="$L('自动进入全员群')" prop="allGroupAutoin">
<RadioGroup v-model="formDatum.all_group_autoin"> <RadioGroup v-model="formDatum.all_group_autoin">
@ -135,6 +133,27 @@
<div v-if="formDatum.all_group_autoin == 'yes'" class="form-tip">{{$L('自动注册成功后自动进入全员群')}}</div> <div v-if="formDatum.all_group_autoin == 'yes'" class="form-tip">{{$L('自动注册成功后自动进入全员群')}}</div>
<div v-else-if="formDatum.all_group_autoin == 'no'" class="form-tip">{{$L('关闭:其他成员通过@邀请进入。')}}</div> <div v-else-if="formDatum.all_group_autoin == 'no'" class="form-tip">{{$L('关闭:其他成员通过@邀请进入。')}}</div>
</FormItem> </FormItem>
<FormItem :label="$L('私聊禁言')" prop="userPrivateChatMute">
<RadioGroup v-model="formDatum.user_private_chat_mute">
<Radio label="open">{{$L('开放')}}</Radio>
<Radio label="close">{{$L('禁言')}}</Radio>
</RadioGroup>
<div v-if="formDatum.user_private_chat_mute == 'open'" class="form-tip">{{$L('开放所有人都可以相互发起个人聊天')}}</div>
<div v-else-if="formDatum.user_private_chat_mute == 'close'" class="form-tip">{{$L('禁言:除管理员外所有人都禁止发起个人聊天。')}}</div>
</FormItem>
<FormItem :label="$L('群聊禁言')" prop="userGroupChatMute">
<RadioGroup v-model="formDatum.user_group_chat_mute">
<Radio label="open">{{$L('开放')}}</Radio>
<Radio label="close">{{$L('禁言')}}</Radio>
</RadioGroup>
<div v-if="formDatum.user_group_chat_mute == 'open'" class="form-tip">{{$L('开放允许个人群组聊天发言')}}</div>
<div v-else-if="formDatum.user_group_chat_mute == 'close'" class="form-tip form-list">
<ol>
<li>{{$L('除管理员外禁止个人群组聊天发言。')}}</li>
<li>{{$L('注意,仅禁止个人群组,其他类型的群组不禁止,比如:部门群聊、项目群聊等系统群聊。')}}</li>
</ol>
</div>
</FormItem>
<FormItem :label="$L('聊天资料')" prop="chatInformation"> <FormItem :label="$L('聊天资料')" prop="chatInformation">
<RadioGroup v-model="formDatum.chat_information"> <RadioGroup v-model="formDatum.chat_information">
<Radio label="optional">{{$L('可选')}}</Radio> <Radio label="optional">{{$L('可选')}}</Radio>