From b3286c8f74589424927a1fc48e0e15e184653b87 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 6 May 2022 12:14:11 +0800 Subject: [PATCH] no message --- README.md | 10 +++ README_CN.md | 10 +++ app/Models/WebSocketDialogMsg.php | 1 + app/Tasks/EmailNoticeTask.php | 33 ++++--- app/Tasks/OverdueRemindEmailTask.php | 116 ------------------------- cmd | 12 +++ docker/php/php.ini | 2 +- resources/views/email/unread.blade.php | 20 ++++- 8 files changed, 71 insertions(+), 133 deletions(-) delete mode 100644 app/Tasks/OverdueRemindEmailTask.php diff --git a/README.md b/README.md index fcd14a2cd..682f93e39 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,16 @@ cd dootask ./cmd port 2222 ``` +### Change App Url + +```bash +# This URL only affects the email reply. +./cmd url {Your domain url} + +# example: +./cmd url https://domain.com +``` + ### Stop server ```bash diff --git a/README_CN.md b/README_CN.md index 11f993fb9..9e19675a7 100644 --- a/README_CN.md +++ b/README_CN.md @@ -45,6 +45,16 @@ cd dootask ./cmd port 2222 ``` +### 更换URL + +```bash +# 此地址仅影响邮件回复功能 +./cmd url {域名地址} + +# 例如: +./cmd url https://domain.com +``` + ### 停止服务 ```bash diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 465f516aa..7106c39d9 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -247,6 +247,7 @@ class WebSocketDialogMsg extends AbstractModel */ public static function formatMsg($text, $dialog_id) { + @ini_set("pcre.backtrack_limit", 999999999); // 图片 [:IMAGE:className:width:height:src:alt:] preg_match_all("/(<\/img>)*/s", $text, $matchs); foreach ($matchs[2] as $key => $base64) { diff --git a/app/Tasks/EmailNoticeTask.php b/app/Tasks/EmailNoticeTask.php index 63c0e9b2a..fa381d0e5 100644 --- a/app/Tasks/EmailNoticeTask.php +++ b/app/Tasks/EmailNoticeTask.php @@ -69,7 +69,7 @@ class EmailNoticeTask extends AbstractTask Carbon::now()->subMinutes($userMinute + 10), Carbon::now()->subMinutes($userMinute) ])->chunkById(100, function ($rows) { - $this->unreadMsgEmail($rows); + $this->unreadMsgEmail($rows, "user"); }); } if ($groupMinute > 0) { @@ -82,7 +82,7 @@ class EmailNoticeTask extends AbstractTask Carbon::now()->subMinutes($groupMinute + 10), Carbon::now()->subMinutes($groupMinute) ])->chunkById(100, function ($rows) { - $this->unreadMsgEmail($rows); + $this->unreadMsgEmail($rows, "group"); }); } } @@ -152,10 +152,11 @@ class EmailNoticeTask extends AbstractTask /** * 未读消息通知 - * @param \Illuminate\Database\Eloquent\Collection|EmailNoticeTask[] $rows + * @param $rows + * @param $dialogType * @return void */ - private function unreadMsgEmail($rows) + private function unreadMsgEmail($rows, $dialogType) { $array = $rows->groupBy('r_userid'); foreach ($array as $userid => $data) { @@ -170,32 +171,40 @@ class EmailNoticeTask extends AbstractTask continue; } $setting = Base::setting('emailSetting'); - $subject = env('APP_NAME') . " 未读消息提醒(" . count($data) . "条)"; + $msgType = $dialogType === "group" ? "群聊" : "个人"; + $subject = env('APP_NAME') . " 未读{$msgType}消息提醒(" . count($data) . "条)"; $content = view('email.unread', [ 'type' => 'head', 'nickname' => $user->nickname, + 'msgType' => $msgType, 'count' => count($data), ]); $lists = $data->groupBy('dialog_id'); /** @var WebSocketDialogMsg[] $items */ foreach ($lists as $items) { + $dialogId = 0; $dialogName = null; foreach ($items as $item) { $item->userInfo = User::userid2basic($item->userid); $item->preview = $item->previewMsg(true); + if (empty($dialogId)) { + $dialogId = $item->dialog_id; + } if ($dialogName === null) { - switch ($item->dialog_type) { - case "user": - $dialogName = $item->userInfo['nickname']; - break; - case "group": - $dialogName = $item->webSocketDialog?->name; - break; + if ($dialogType === "user" && $item->userInfo) { + if ($item->userInfo->profession) { + $dialogName = $item->userInfo->nickname . " ({$item->userInfo->profession})"; + } else { + $dialogName = $item->userInfo->nickname; + } + } else { + $dialogName = $item->webSocketDialog?->name; } } } $content .= view('email.unread', [ 'type' => 'content', + 'dialogUrl' => config("app.url") . "/manage/messenger/{$dialogId}", 'dialogName' => $dialogName, 'unread' => count($items), 'items' => $items, diff --git a/app/Tasks/OverdueRemindEmailTask.php b/app/Tasks/OverdueRemindEmailTask.php deleted file mode 100644 index 0f869e377..000000000 --- a/app/Tasks/OverdueRemindEmailTask.php +++ /dev/null @@ -1,116 +0,0 @@ - 0) { - ProjectTask::whereNull('complete_at') - ->whereNull('archived_at') - ->whereBetween("end_at", [ - Carbon::now()->addMinutes($hours * 60), - Carbon::now()->addMinutes($hours * 60 + 10) - ])->chunkById(100, function ($tasks) { - /** @var ProjectTask $task */ - foreach ($tasks as $task) { - $this->overdueBeforeAfterEmail($task, true); - } - }); - } - if ($hours2 > 0) { - ProjectTask::whereNull('complete_at') - ->whereNull('archived_at') - ->whereBetween("end_at", [ - Carbon::now()->subMinutes($hours2 * 60 + 10), - Carbon::now()->subMinutes($hours2 * 60) - ])->chunkById(100, function ($tasks) { - /** @var ProjectTask $task */ - foreach ($tasks as $task) { - $this->overdueBeforeAfterEmail($task, false); - } - }); - } - } - } - - /** - * 过期前、超期后提醒 - * @param ProjectTask $task - * @param $isBefore - * @return void - */ - private function overdueBeforeAfterEmail(ProjectTask $task, $isBefore) - { - $userids = $task->taskUser->where('owner', 1)->pluck('userid')->toArray(); - if (empty($userids)) { - return; - } - $users = User::whereIn('userid', $userids)->get(); - if (empty($users)) { - return; - } - - $setting = Base::setting('emailSetting'); - $hours = floatval($setting['task_remind_hours']); - $hours2 = floatval($setting['task_remind_hours2']); - - /** @var User $user */ - foreach ($users as $user) { - $data = [ - 'type' => $isBefore ? 1 : 2, - 'userid' => $user->userid, - 'task_id' => $task->id, - ]; - $emailLog = ProjectTaskMailLog::where($data)->first(); - if ($emailLog) { - continue; - } - try { - if (!Base::isEmail($user->email)) { - throw new \Exception("User email '{$user->email}' address error"); - } - if ($isBefore) { - $subject = env('APP_NAME') . " 任务提醒"; - $content = "

{$user->nickname} 您好:

您有一个任务【{$task->name}】还有{$hours}小时即将超时,请及时处理。

"; - } else { - $subject = env('APP_NAME') . " 任务过期提醒"; - $content = "

{$user->nickname} 您好:

您的任务【{$task->name}】已经超时{$hours2}小时,请及时处理。

"; - } - Factory::mailer() - ->setDsn("smtp://{$setting['account']}:{$setting['password']}@{$setting['smtp_server']}:{$setting['port']}?verify_peer=0") - ->setMessage(EmailMessage::create() - ->from(env('APP_NAME', 'Task') . " <{$setting['account']}>") - ->to($user->email) - ->subject($subject) - ->html($content)) - ->send(); - $data['is_send'] = 1; - } catch (\Exception $e) { - $data['send_error'] = $e->getMessage(); - } - $data['email'] = $user->email; - ProjectTaskMailLog::createInstance($data)->save(); - } - } -} diff --git a/cmd b/cmd index a4aaa0ad2..cfa3e0a72 100755 --- a/cmd +++ b/cmd @@ -358,6 +358,18 @@ if [ $# -gt 0 ]; then $COMPOSE up -d echo -e "${OK} ${GreenBG} 修改成功 ${Font}" echo -e "地址: http://${GreenBG}127.0.0.1:$(env_get APP_PORT)${Font}" + elif [[ "$1" == "url" ]]; then + shift 1 + env_set APP_URL "$1" + supervisorctl_restart php + echo -e "${OK} ${GreenBG} 修改成功 ${Font}" + elif [[ "$1" == "env" ]]; then + shift 1 + if [ -n "$1" ]; then + env_set $1 "$2" + fi + supervisorctl_restart php + echo -e "${OK} ${GreenBG} 修改成功 ${Font}" elif [[ "$1" == "repassword" ]]; then shift 1 run_exec mariadb "sh /etc/mysql/repassword.sh \"$@\"" diff --git a/docker/php/php.ini b/docker/php/php.ini index 1ffa3ddf1..7a76ff14a 100644 --- a/docker/php/php.ini +++ b/docker/php/php.ini @@ -1041,7 +1041,7 @@ cli_server.color = On [Pcre] ; PCRE library backtracking limit. ; http://php.net/pcre.backtrack-limit -pcre.backtrack_limit=10000000 +;pcre.backtrack_limit=100000 ; PCRE library recursion limit. ; Please note that if you set this value to a high number you may consume all diff --git a/resources/views/email/unread.blade.php b/resources/views/email/unread.blade.php index 9274c191e..cb3f6c73b 100755 --- a/resources/views/email/unread.blade.php +++ b/resources/views/email/unread.blade.php @@ -4,7 +4,7 @@

{{ $nickname }} 您好:

-

您有({{ $count }})条未读消息,请及时处理。

+

您有({{ $count }})条未读{{ $msgType }}消息,请及时处理。


@@ -15,7 +15,7 @@ -

+

{{ $dialogName }}

@@ -27,11 +27,11 @@ - + - {{$item->userInfo["nickname"]}} + {{$item->userInfo?->nickname}} @@ -45,6 +45,18 @@ @endforeach + @if (!empty($dialogUrl)) +
+ + + + + + +
+ 回复消息 +
+ @endif