From 057371d9a14f1e4e84bfbc660c4b173b3c7a1d51 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Fri, 23 Jul 2021 22:48:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/TalkMessageType.php | 19 ++++++++++--------- app/Service/TalkService.php | 15 +++++++++++++++ app/Service/UserFriendService.php | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/Constants/TalkMessageType.php b/app/Constants/TalkMessageType.php index 83b30fe..b6d5365 100644 --- a/app/Constants/TalkMessageType.php +++ b/app/Constants/TalkMessageType.php @@ -9,13 +9,14 @@ namespace App\Constants; */ class TalkMessageType { - const TEXT_MESSAGE = 1;//文本消息 - const FILE_MESSAGE = 2;//文件消息 - const FORWARD_MESSAGE = 3;//会话消息 - const CODE_MESSAGE = 4;//代码消息 - const VOTE_MESSAGE = 5;//投票消息 - const GROUP_NOTICE_MESSAGE = 6;//群组公告 - const FRIEND_APPLY_MESSAGE = 7;//好友申请 - const USER_LOGIN_MESSAGE = 8;//登录通知 - const GROUP_INVITE_MESSAGE = 9;//入群退群消息 + const SYSTEM_TEXT_MESSAGE = 0; //系统文本消息 + const TEXT_MESSAGE = 1; //文本消息 + const FILE_MESSAGE = 2; //文件消息 + const FORWARD_MESSAGE = 3; //会话消息 + const CODE_MESSAGE = 4; //代码消息 + const VOTE_MESSAGE = 5; //投票消息 + const GROUP_NOTICE_MESSAGE = 6; //群组公告 + const FRIEND_APPLY_MESSAGE = 7; //好友申请 + const USER_LOGIN_MESSAGE = 8; //登录通知 + const GROUP_INVITE_MESSAGE = 9; //入群退群消息 } diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index a719934..921e80f 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -81,6 +81,21 @@ class TalkService extends BaseService }); $rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->limit($limit)->get()->toArray(); + + if ($record_id === 0 && $talk_type == TalkModeConstant::PRIVATE_CHAT) { + if (!di()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true)) { + array_unshift($rows, [ + 'id' => ($rows[0]['id'] ?? 0) + 1, + 'talk_type' => TalkModeConstant::PRIVATE_CHAT, + 'msg_type' => TalkMessageType::SYSTEM_TEXT_MESSAGE, + 'user_id' => 0, + 'receiver_id' => $user_id, + 'content' => '你与对方已解除好友关系,系统已禁止发送消息!', + 'created_at' => date('Y-m-d H:i:s'), + ]); + } + } + return di()->get(FormatMessageService::class)->handleChatRecords($rows); } diff --git a/app/Service/UserFriendService.php b/app/Service/UserFriendService.php index 07d1902..dd63d2c 100644 --- a/app/Service/UserFriendService.php +++ b/app/Service/UserFriendService.php @@ -36,6 +36,7 @@ class UserFriendService public function isFriend(int $user_id, int $friend_id, $is_mutual = false) { $isTrue1 = UsersFriend::where('user_id', $user_id)->where('friend_id', $friend_id)->where('status', 1)->exists(); + if ($is_mutual === false) { return $isTrue1; }