From a46ffa108960fbb5fbf096081c752e8c28fb15e0 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 20 Apr 2024 19:03:11 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B6=88=E6=81=AF=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BE=85=E5=8A=9E=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/DialogController.php | 66 +++++++++++++++++++ app/Models/WebSocketDialogMsg.php | 11 +++- .../manage/components/ChatInput/index.vue | 2 +- .../pages/manage/components/DialogWrapper.vue | 52 +++++++++++++-- .../sass/pages/components/chat-input.scss | 16 +++++ .../sass/pages/components/dialog-wrapper.scss | 25 +++++++ 6 files changed, 166 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 26032ade2..301cee00e 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -832,6 +832,72 @@ public function msg__unread() ]); } + /** + * @api {get} api/dialog/msg/checked 16. 设置消息checked + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup dialog + * @apiName msg__checked + * + * @apiParam {Number} dialog_id 对话ID + * @apiParam {Number} msg_id 消息ID + * @apiParam {Number} index li 位置 + * @apiParam {Number} checked 标记、取消标记 + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + * @apiSuccessExample {json} data: + { + "id": 43, + "msg": { + // .... + }, + } + */ + public function msg__checked() + { + $user = User::auth(); + // + $dialog_id = intval(Request::input('dialog_id')); + $msg_id = intval(Request::input('msg_id')); + $index = intval(Request::input('index')); + $checked = intval(Request::input('checked')); + // + $dialogMsg = WebSocketDialogMsg::whereId($msg_id)->whereDialogId($dialog_id)->first(); + if (empty($dialogMsg)) { + return Base::retError('消息不存在'); + } + if ($dialogMsg->userid != $user->userid) { + return Base::retError('仅支持修改自己的消息'); + } + if ($dialogMsg->type !== 'text') { + return Base::retError('仅支持文本消息'); + } + // + $oldMsg = Base::json2array($dialogMsg->getRawOriginal('msg')); + $oldText = $oldMsg['text'] ?? ''; + $newText = preg_replace_callback('/]*>/i', function ($matches) use ($index, $checked) { + static $i = 0; + if ($i++ == $index) { + $checked = $checked ? 'checked' : 'unchecked'; + return '
  • '; + } + return $matches[0]; + }, $oldText); + // + $dialogMsg->updateInstance([ + 'msg' => array_merge($oldMsg, ['text' => $newText]), + ]); + $dialogMsg->save(); + // + return Base::retSuccess('success', [ + 'id' => $dialogMsg->id, + 'msg' => $dialogMsg->msg, + ]); + } + /** * @api {post} api/dialog/msg/stream 17. 通知成员监听消息 * diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index eeab397c6..241bf9d44 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -751,6 +751,15 @@ public static function formatMsg($text, $dialog_id) $text = str_replace($str, "[:QUICK:{$quickKey}:{$quickLabel}:]", $text); } } + // 处理 li 标签 + preg_match_all("/]*?>/i", $text, $matchs); + foreach ($matchs[0] as $str) { + if (preg_match("/data-list=['\"](bullet|ordered|checked|unchecked)['\"]/i", $str, $match)) { + $text = str_replace($str, '
  • ', $text); + } else { + $text = str_replace($str, '
  • ', $text); + } + } // 处理链接标签 preg_match_all("/]*?href=([\"'])(.*?)\\1[^>]*?>(.*?)<\/a>/is", $text, $matchs); foreach ($matchs[0] as $key => $str) { @@ -785,7 +794,7 @@ public static function formatMsg($text, $dialog_id) } // 过滤标签 $text = strip_tags($text, '