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; }