mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 21:02:49 +00:00
perf: 新增禁止私聊、群聊功能
This commit is contained in:
parent
7dd5b082cf
commit
7efaf3bb32
@ -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');
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** ***************************************************************************************** */
|
||||
/** ***************************************************************************************** */
|
||||
/** ***************************************************************************************** */
|
||||
|
||||
@ -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('当前会话全员禁言');
|
||||
$muteMsgTip = null;
|
||||
$systemConfig = Base::setting('system');
|
||||
switch ($this->type) {
|
||||
case 'user':
|
||||
if (!User::find($userid)?->isAdmin()) {
|
||||
throw new ApiException('当前会话禁言');
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1047,14 +1047,8 @@ export default {
|
||||
},
|
||||
|
||||
isMute() {
|
||||
if (this.dialogData.group_type === 'all') {
|
||||
if (this.dialogData.all_group_mute === 'all') {
|
||||
return true
|
||||
} else if (this.dialogData.all_group_mute === 'user') {
|
||||
if (!this.userIsAdmin) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if (this.dialogData.dialog_mute === 'close') {
|
||||
return !this.userIsAdmin
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
@ -120,12 +120,10 @@
|
||||
<FormItem :label="$L('全员群组禁言')" prop="allGroupMute">
|
||||
<RadioGroup v-model="formDatum.all_group_mute">
|
||||
<Radio label="open">{{$L('开放')}}</Radio>
|
||||
<Radio label="user">{{$L('成员禁言')}}</Radio>
|
||||
<Radio label="all">{{$L('全部禁言')}}</Radio>
|
||||
<Radio label="close">{{$L('禁言')}}</Radio>
|
||||
</RadioGroup>
|
||||
<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 == 'all'" 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 == 'close'" class="form-tip">{{$L('禁言:除管理员外所有人都禁止在全员群组发言。')}}</div>
|
||||
</FormItem>
|
||||
<FormItem :label="$L('自动进入全员群')" prop="allGroupAutoin">
|
||||
<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-else-if="formDatum.all_group_autoin == 'no'" class="form-tip">{{$L('关闭:其他成员通过@邀请进入。')}}</div>
|
||||
</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">
|
||||
<RadioGroup v-model="formDatum.chat_information">
|
||||
<Radio label="optional">{{$L('可选')}}</Radio>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user