mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
feat: 新增自定义撤回及修改消息时限
This commit is contained in:
parent
cf5e126eaa
commit
957201804c
@ -12,6 +12,7 @@ use App\Models\File;
|
||||
use App\Models\User;
|
||||
use App\Module\Base;
|
||||
use App\Module\Timer;
|
||||
use App\Models\Setting;
|
||||
use App\Module\Extranet;
|
||||
use App\Module\ElasticSearch\ElasticSearchUserMsg;
|
||||
use App\Module\TimeRange;
|
||||
@ -1092,6 +1093,9 @@ class DialogController extends AbstractController
|
||||
//
|
||||
if ($update_id > 0) {
|
||||
$action = $update_mark ? "update-$update_id" : "change-$update_id";
|
||||
if (!($user->bot || $user->isAdmin())) {
|
||||
Setting::validateMsgLimit('edit', $update_id);
|
||||
}
|
||||
} elseif ($reply_id > 0) {
|
||||
$action = "reply-$reply_id";
|
||||
if ($reply_check === 'yes') {
|
||||
@ -1844,6 +1848,9 @@ class DialogController extends AbstractController
|
||||
if (empty($msg)) {
|
||||
return Base::retError("消息不存在或已被删除");
|
||||
}
|
||||
if (!($user->bot || $user->isAdmin())) {
|
||||
Setting::validateMsgLimit('rev', $msg);
|
||||
}
|
||||
$msg->withdrawMsg();
|
||||
return Base::retSuccess("success");
|
||||
}
|
||||
|
||||
@ -71,6 +71,8 @@ class SystemController extends AbstractController
|
||||
'voice2text',
|
||||
'translation',
|
||||
'e2e_message',
|
||||
'msg_rev_limit',
|
||||
'msg_edit_limit',
|
||||
'auto_archived',
|
||||
'archived_day',
|
||||
'task_visible',
|
||||
@ -135,6 +137,8 @@ class SystemController extends AbstractController
|
||||
$setting['voice2text'] = $setting['voice2text'] ?: 'close';
|
||||
$setting['translation'] = $setting['translation'] ?: 'close';
|
||||
$setting['e2e_message'] = $setting['e2e_message'] ?: 'close';
|
||||
$setting['msg_rev_limit'] = $setting['msg_rev_limit'] ?: '';
|
||||
$setting['msg_edit_limit'] = $setting['msg_edit_limit'] ?: '';
|
||||
$setting['auto_archived'] = $setting['auto_archived'] ?: 'close';
|
||||
$setting['archived_day'] = floatval($setting['archived_day']) ?: 7;
|
||||
$setting['task_visible'] = $setting['task_visible'] ?: 'close';
|
||||
|
||||
@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Module\Base;
|
||||
use App\Module\Doo;
|
||||
use App\Module\Timer;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* App\Models\Setting
|
||||
@ -263,4 +266,36 @@ class Setting extends AbstractModel
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证消息限制
|
||||
* @param $type
|
||||
* @param $msg
|
||||
* @return void
|
||||
*/
|
||||
public static function validateMsgLimit($type, $msg)
|
||||
{
|
||||
$keyName = 'msg_edit_limit';
|
||||
$error = '此消息不可修改';
|
||||
if ($type == 'rev') {
|
||||
$keyName = 'msg_rev_limit';
|
||||
$error = '此消息不可撤回';
|
||||
}
|
||||
$limitNum = intval(Base::settingFind('system', $keyName, 0));
|
||||
if ($limitNum <= 0) {
|
||||
return;
|
||||
}
|
||||
if ($msg instanceof WebSocketDialogMsg) {
|
||||
$dialogMsg = $msg;
|
||||
} else {
|
||||
$dialogMsg = WebSocketDialogMsg::find($msg);
|
||||
}
|
||||
if (!$dialogMsg) {
|
||||
return;
|
||||
}
|
||||
$limitTime = Carbon::parse($dialogMsg->created_at)->addMinutes($limitNum);
|
||||
if ($limitTime->lt(Carbon::now())) {
|
||||
throw new ApiException('已超过' . Doo::translate(Base::forumMinuteDay($limitNum)) . ',' . $error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -539,10 +539,6 @@ class WebSocketDialogMsg extends AbstractModel
|
||||
*/
|
||||
public function withdrawMsg()
|
||||
{
|
||||
$send_dt = Carbon::parse($this->created_at)->addDay();
|
||||
if ($send_dt->lt(Carbon::now())) {
|
||||
throw new ApiException('已超过24小时,此消息不能撤回');
|
||||
}
|
||||
AbstractModel::transaction(function() {
|
||||
$deleteRead = WebSocketDialogMsgRead::whereMsgId($this->id)->whereNull('read_at')->delete(); // 未阅读记录不需要软删除,直接删除即可
|
||||
$this->delete();
|
||||
|
||||
@ -1476,14 +1476,36 @@ class Base
|
||||
public static function forumHourDay($hour)
|
||||
{
|
||||
$hour = intval($hour);
|
||||
if ($hour > 24) {
|
||||
if ($hour >= 24) {
|
||||
$day = floor($hour / 24);
|
||||
$hour -= $day * 24;
|
||||
return $day . '天' . $hour . '小时';
|
||||
if ($hour > 0) {
|
||||
return $day . '天' . $hour . '小时';
|
||||
}
|
||||
return $day . '天';
|
||||
}
|
||||
return $hour . '小时';
|
||||
}
|
||||
|
||||
/**
|
||||
* 分钟转天/小时/分钟
|
||||
* @param $minute
|
||||
* @return string
|
||||
*/
|
||||
public static function forumMinuteDay($minute)
|
||||
{
|
||||
$minute = intval($minute);
|
||||
if ($minute >= 60) {
|
||||
$hour = floor($minute / 60);
|
||||
$minute -= $hour * 60;
|
||||
if ($minute > 0) {
|
||||
return Base::forumHourDay($hour) . $minute . '分钟';
|
||||
}
|
||||
return Base::forumHourDay($hour);
|
||||
}
|
||||
return $minute . '分钟';
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Carbon对象
|
||||
* @param $var
|
||||
|
||||
@ -206,6 +206,26 @@
|
||||
<div v-if="formDatum.e2e_message == 'open'" class="form-tip">{{$L('使用端到端加密传输数据。')}}</div>
|
||||
<div v-else class="form-tip">{{$L('关闭端到端加密传输数据。')}}</div>
|
||||
</FormItem>
|
||||
<FormItem :label="$L('撤回消息限制')" prop="msgRevLimit">
|
||||
<div style="width: 220px;">
|
||||
<Input type="number" number v-model="formDatum.msg_rev_limit" :placeholder="$L('默认不限制')">
|
||||
<template #append>
|
||||
<span>{{$L('分钟')}}</span>
|
||||
</template>
|
||||
</Input>
|
||||
</div>
|
||||
<div class="form-tip">{{$L('消息发出后的可撤回时长。')}} ({{$L('系统管理员除外')}})</div>
|
||||
</FormItem>
|
||||
<FormItem :label="$L('修改消息限制')" prop="msgEditLimit">
|
||||
<div style="width: 220px;">
|
||||
<Input type="number" number v-model="formDatum.msg_edit_limit" :placeholder="$L('默认不限制')">
|
||||
<template #append>
|
||||
<span>{{$L('分钟')}}</span>
|
||||
</template>
|
||||
</Input>
|
||||
</div>
|
||||
<div class="form-tip">{{$L('消息发出后的可修改时长。')}} ({{$L('系统管理员除外')}})</div>
|
||||
</FormItem>
|
||||
</div>
|
||||
</div>
|
||||
<div class="block-setting-box">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user