From c7f5c62e71ebb0b1dfab0ba0124942003e9f20d7 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 10 Dec 2024 23:34:31 +0800 Subject: [PATCH] no message --- app/Http/Controllers/Api/DialogController.php | 6 +++--- app/Models/User.php | 17 +++++++++++++++++ app/Models/WebSocketDialogMsg.php | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 5fa55722a..311cf60d8 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -1019,7 +1019,7 @@ class DialogController extends AbstractController * @apiParam {Number} [reply_id] 回复ID * @apiParam {String} [reply_check] 配合 reply_id 使用,判断是否需要验证回复ID的有效性 * - no: 不进行判断,直接使用提供的 reply_id(默认) - * - yes: 进行判断,如果上一条消息(非机器人)的 ID 为 reply_id,则认为 reply_id 无效 + * - yes: 进行判断,如果 reply_id 到最新消息都没有会员发的消息,则 reply_id 无效 * @apiParam {String} [silence] 是否静默发送 * - no: 正常发送(默认) * - yes: 静默发送 @@ -1056,8 +1056,8 @@ class DialogController extends AbstractController } elseif ($reply_id > 0) { $action = "reply-$reply_id"; if ($reply_check === 'yes') { - $lastMsgId = WebSocketDialogMsg::whereDialogId($dialog_id)->orderByDesc('id')->value('id'); - if ($lastMsgId == $reply_id) { + $exisUserMsg = WebSocketDialogMsg::whereDialogId($dialog_id)->where('id', '>', $reply_id)->whereBot(0)->exists(); + if (!$exisUserMsg) { $action = ""; } } diff --git a/app/Models/User.php b/app/Models/User.php index 04b4a5499..bed231ed8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -683,4 +683,21 @@ class User extends AbstractModel } return $botUser; } + + /** + * 是否机器人 + * @param $userid + * @return bool|mixed + */ + public static function isBot($userid) + { + if (empty($userid)) { + return false; + } + $userid = intval($userid); + if (RequestContext::has("isBot_" . $userid)) { + return RequestContext::get("isBot_" . $userid); + } + return (bool)User::find($userid)?->bot; + } } diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 05cc0df0b..342ca49f7 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -30,6 +30,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property int|null $todo 设为待办会员ID * @property int|null $link 是否存在链接 * @property int|null $modify 是否编辑 + * @property int $bot * @property int|null $reply_num 有多少条回复 * @property int|null $reply_id 回复ID * @property int|null $forward_id 转发ID @@ -50,6 +51,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg query() * @method static \Illuminate\Database\Eloquent\Builder|AbstractModel remove() * @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore() + * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereBot($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogMsg whereDialogId($value) @@ -1169,6 +1171,7 @@ class WebSocketDialogMsg extends AbstractModel 'type' => $type, 'mtype' => $mtype, 'link' => $link, + 'bot' => User::isBot($sender) ? 1 : 0, 'msg' => $msg, 'read' => 0, ]);