From 7cea81588868866ab5aae2467c1a446120a50ea4 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Tue, 12 Apr 2022 19:34:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constant/TalkEventConstant.php | 16 ++++++++-------- app/Controller/WebSocketController.php | 4 ++-- app/Process/RedisWebsocketSubscribe.php | 2 -- app/Service/Contact/ContactApplyService.php | 4 ++-- app/Service/Group/GroupService.php | 1 - app/Service/Message/ReceiveHandleService.php | 6 +++--- app/Service/Message/SubscribeHandleService.php | 16 ++++++++-------- app/Service/TalkService.php | 2 +- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/app/Constant/TalkEventConstant.php b/app/Constant/TalkEventConstant.php index d960789..4163b8e 100644 --- a/app/Constant/TalkEventConstant.php +++ b/app/Constant/TalkEventConstant.php @@ -18,22 +18,22 @@ class TalkEventConstant /** * 键盘输入事件通知 - 事件名 */ - const EVENT_KEYBOARD = 'event_keyboard'; + const EVENT_TALK_KEYBOARD = 'event_talk_keyboard'; /** * 用户在线状态通知 - 事件名 */ - const EVENT_ONLINE_STATUS = 'event_online_status'; + const EVENT_LOGIN = 'event_login'; /** * 聊天消息撤销通知 - 事件名 */ - const EVENT_REVOKE_TALK = 'event_revoke_talk'; + const EVENT_TALK_REVOKE = 'event_talk_revoke'; /** * 好友申请消息通知 - 事件名 */ - const EVENT_FRIEND_APPLY = 'event_friend_apply'; + const EVENT_CONTACT_APPLY = 'event_contact_apply'; /** * @return array @@ -42,10 +42,10 @@ class TalkEventConstant { return [ self::EVENT_TALK => '对话消息通知', - self::EVENT_KEYBOARD => '键盘输入事件通知', - self::EVENT_ONLINE_STATUS => '用户在线状态通知', - self::EVENT_REVOKE_TALK => '聊天消息撤销通知', - self::EVENT_FRIEND_APPLY => '好友申请消息通知' + self::EVENT_TALK_KEYBOARD => '键盘输入事件通知', + self::EVENT_LOGIN => '用户在线状态通知', + self::EVENT_TALK_REVOKE => '聊天消息撤销通知', + self::EVENT_CONTACT_APPLY => '好友申请消息通知' ]; } } diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index 634ec28..cce3e92 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -80,7 +80,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos } if (!$isOnline) { - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_ONLINE_STATUS, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_LOGIN, [ 'user_id' => $user_id, 'status' => 1, ])); @@ -133,7 +133,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos $isOnline = $this->client->isOnlineAll($user_id); if ($isOnline) return; - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_ONLINE_STATUS, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_LOGIN, [ 'user_id' => $user_id, 'status' => 0, ])); diff --git a/app/Process/RedisWebsocketSubscribe.php b/app/Process/RedisWebsocketSubscribe.php index e59ed99..4ef708e 100644 --- a/app/Process/RedisWebsocketSubscribe.php +++ b/app/Process/RedisWebsocketSubscribe.php @@ -50,8 +50,6 @@ class RedisWebsocketSubscribe extends AbstractProcess //echo PHP_EOL . "chan : $chan , msg : $message"; $data = json_decode($message, true); - var_dump("subscribe ====> {$message}"); - $this->handleService->handle($data); } } diff --git a/app/Service/Contact/ContactApplyService.php b/app/Service/Contact/ContactApplyService.php index 472d775..00d2c75 100644 --- a/app/Service/Contact/ContactApplyService.php +++ b/app/Service/Contact/ContactApplyService.php @@ -52,7 +52,7 @@ class ContactApplyService // 判断对方是否在线。如果在线发送消息通知 $isOnline = di()->get(SocketClientService::class)->isOnlineAll($friend_id); if ($isOnline) { - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_CONTACT_APPLY, [ 'apply_id' => $result->id, 'type' => 1, ])); @@ -103,7 +103,7 @@ class ContactApplyService // 判断对方是否在线。如果在线发送消息通知 $isOnline = di()->get(SocketClientService::class)->isOnlineAll($info->user_id); if ($isOnline) { - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_CONTACT_APPLY, [ 'apply_id' => $apply_id, 'type' => 2, ])); diff --git a/app/Service/Group/GroupService.php b/app/Service/Group/GroupService.php index 1631f7d..543ee38 100644 --- a/app/Service/Group/GroupService.php +++ b/app/Service/Group/GroupService.php @@ -282,7 +282,6 @@ class GroupService extends BaseService Db::commit(); } catch (Exception $e) { Db::rollBack(); - var_dump($e->getMessage()); return false; } diff --git a/app/Service/Message/ReceiveHandleService.php b/app/Service/Message/ReceiveHandleService.php index 51c22fd..5537ef5 100644 --- a/app/Service/Message/ReceiveHandleService.php +++ b/app/Service/Message/ReceiveHandleService.php @@ -22,8 +22,8 @@ class ReceiveHandleService // 消息事件绑定 const EVENTS = [ - TalkEventConstant::EVENT_TALK => 'onTalk', - TalkEventConstant::EVENT_KEYBOARD => 'onKeyboard', + TalkEventConstant::EVENT_TALK => 'onTalk', + TalkEventConstant::EVENT_TALK_KEYBOARD => 'onKeyboard', ]; /** @@ -79,7 +79,7 @@ class ReceiveHandleService */ public function onKeyboard($server, Frame $frame, $data) { - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_KEYBOARD, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_TALK_KEYBOARD, [ 'sender_id' => (int)$data['sender_id'], 'receiver_id' => (int)$data['receiver_id'], ])); diff --git a/app/Service/Message/SubscribeHandleService.php b/app/Service/Message/SubscribeHandleService.php index b2f6bf2..e4bccc8 100644 --- a/app/Service/Message/SubscribeHandleService.php +++ b/app/Service/Message/SubscribeHandleService.php @@ -25,16 +25,16 @@ class SubscribeHandleService TalkEventConstant::EVENT_TALK => 'onConsumeTalk', // 键盘输入事件 - TalkEventConstant::EVENT_KEYBOARD => 'onConsumeKeyboard', + TalkEventConstant::EVENT_TALK_KEYBOARD => 'onConsumeKeyboard', // 用户在线状态事件 - TalkEventConstant::EVENT_ONLINE_STATUS => 'onConsumeOnlineStatus', + TalkEventConstant::EVENT_LOGIN => 'onConsumeOnlineStatus', // 聊天消息推送事件 - TalkEventConstant::EVENT_REVOKE_TALK => 'onConsumeRevokeTalk', + TalkEventConstant::EVENT_TALK_REVOKE => 'onConsumeRevokeTalk', // 好友申请相关事件 - TalkEventConstant::EVENT_FRIEND_APPLY => 'onConsumeFriendApply' + TalkEventConstant::EVENT_CONTACT_APPLY => 'onConsumeFriendApply' ]; /** @@ -133,7 +133,7 @@ class SubscribeHandleService { $fds = $this->clientService->findUserFds($data['data']['receiver_id']); - $this->push($fds, $this->toJson(TalkEventConstant::EVENT_KEYBOARD, $data['data'])); + $this->push($fds, $this->toJson(TalkEventConstant::EVENT_TALK_KEYBOARD, $data['data'])); } /** @@ -157,7 +157,7 @@ class SubscribeHandleService $fds = array_unique(array_merge(...$fds)); - $this->push($fds, $this->toJson(TalkEventConstant::EVENT_ONLINE_STATUS, [ + $this->push($fds, $this->toJson(TalkEventConstant::EVENT_LOGIN, [ 'user_id' => $user_id, 'status' => $status ])); @@ -188,7 +188,7 @@ class SubscribeHandleService if (!$fds) return; - $this->push($fds, $this->toJson(TalkEventConstant::EVENT_REVOKE_TALK, [ + $this->push($fds, $this->toJson(TalkEventConstant::EVENT_TALK_REVOKE, [ 'talk_type' => $record->talk_type, 'sender_id' => $record->user_id, 'receiver_id' => $record->receiver_id, @@ -234,7 +234,7 @@ class SubscribeHandleService 'mobile' => $friendInfo->mobile, ]; - $this->push(array_unique($fds), $this->toJson(TalkEventConstant::EVENT_FRIEND_APPLY, $msg)); + $this->push(array_unique($fds), $this->toJson(TalkEventConstant::EVENT_CONTACT_APPLY, $msg)); } private function toJson(string $event, array $data): string diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index 08cca4d..b2a45dc 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -213,7 +213,7 @@ class TalkService extends BaseService $result->is_revoke = 1; $result->save(); - event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_REVOKE_TALK, [ + event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_TALK_REVOKE, [ 'record_id' => $result->id ]));