From e495847a73c9f80e56d1f6e4f303f979a3cd96ca Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Fri, 9 Jul 2021 22:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/TalkMode.php | 8 +++-- app/Controller/Api/V1/DownloadController.php | 4 +-- app/Model/{ => Talk}/TalkList.php | 4 ++- app/Model/{Chat => Talk}/TalkRecords.php | 2 +- app/Model/{Chat => Talk}/TalkRecordsCode.php | 2 +- .../{Chat => Talk}/TalkRecordsDelete.php | 2 +- app/Model/{Chat => Talk}/TalkRecordsFile.php | 2 +- .../{Chat => Talk}/TalkRecordsForward.php | 2 +- .../{Chat => Talk}/TalkRecordsInvite.php | 2 +- app/Process/RedisWebsocketSubscribe.php | 13 ++++----- app/Service/EmoticonService.php | 4 +-- app/Service/GroupService.php | 6 ++-- app/Service/Message/ReceiveHandleService.php | 2 +- .../Message/SubscribeHandleService.php | 29 +++++++++++++++---- app/Service/TalkListService.php | 2 +- app/Service/TalkMessageService.php | 6 ++-- app/Service/TalkService.php | 10 +++---- app/Support/MessageProducer.php | 4 +-- app/Traits/StaticInstance.php | 9 +++--- 19 files changed, 66 insertions(+), 47 deletions(-) rename app/Model/{ => Talk}/TalkList.php (96%) rename app/Model/{Chat => Talk}/TalkRecords.php (98%) rename app/Model/{Chat => Talk}/TalkRecordsCode.php (96%) rename app/Model/{Chat => Talk}/TalkRecordsDelete.php (95%) rename app/Model/{Chat => Talk}/TalkRecordsFile.php (98%) rename app/Model/{Chat => Talk}/TalkRecordsForward.php (96%) rename app/Model/{Chat => Talk}/TalkRecordsInvite.php (97%) diff --git a/app/Constants/TalkMode.php b/app/Constants/TalkMode.php index 027d293..adce0cd 100644 --- a/app/Constants/TalkMode.php +++ b/app/Constants/TalkMode.php @@ -9,10 +9,14 @@ namespace App\Constants; */ class TalkMode { - // 私信 + /** + * 私信 + */ const PRIVATE_CHAT = 1; - // 群聊 + /** + * 群聊 + */ const GROUP_CHAT = 2; public static function getTypes() diff --git a/app/Controller/Api/V1/DownloadController.php b/app/Controller/Api/V1/DownloadController.php index 528fb60..e3388e5 100644 --- a/app/Controller/Api/V1/DownloadController.php +++ b/app/Controller/Api/V1/DownloadController.php @@ -16,8 +16,8 @@ use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\Middleware; use App\Middleware\JWTAuthMiddleware; use App\Model\Article\ArticleAnnex; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsFile; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsFile; use App\Model\Group\Group; use Hyperf\HttpServer\Contract\ResponseInterface; use League\Flysystem\Filesystem; diff --git a/app/Model/TalkList.php b/app/Model/Talk/TalkList.php similarity index 96% rename from app/Model/TalkList.php rename to app/Model/Talk/TalkList.php index 37e9869..942f9d8 100644 --- a/app/Model/TalkList.php +++ b/app/Model/Talk/TalkList.php @@ -2,7 +2,9 @@ declare (strict_types=1); -namespace App\Model; +namespace App\Model\Talk; + +use App\Model\BaseModel; /** * 聊天列表组数据表模型 diff --git a/app/Model/Chat/TalkRecords.php b/app/Model/Talk/TalkRecords.php similarity index 98% rename from app/Model/Chat/TalkRecords.php rename to app/Model/Talk/TalkRecords.php index 96ec8f8..96da3c0 100644 --- a/app/Model/Chat/TalkRecords.php +++ b/app/Model/Talk/TalkRecords.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Model/Chat/TalkRecordsCode.php b/app/Model/Talk/TalkRecordsCode.php similarity index 96% rename from app/Model/Chat/TalkRecordsCode.php rename to app/Model/Talk/TalkRecordsCode.php index de16ce4..e0b482c 100644 --- a/app/Model/Chat/TalkRecordsCode.php +++ b/app/Model/Talk/TalkRecordsCode.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Model/Chat/TalkRecordsDelete.php b/app/Model/Talk/TalkRecordsDelete.php similarity index 95% rename from app/Model/Chat/TalkRecordsDelete.php rename to app/Model/Talk/TalkRecordsDelete.php index 235c5c2..9fd76d7 100644 --- a/app/Model/Chat/TalkRecordsDelete.php +++ b/app/Model/Talk/TalkRecordsDelete.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Model/Chat/TalkRecordsFile.php b/app/Model/Talk/TalkRecordsFile.php similarity index 98% rename from app/Model/Chat/TalkRecordsFile.php rename to app/Model/Talk/TalkRecordsFile.php index 6b4743c..c21f7ce 100644 --- a/app/Model/Chat/TalkRecordsFile.php +++ b/app/Model/Talk/TalkRecordsFile.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Model/Chat/TalkRecordsForward.php b/app/Model/Talk/TalkRecordsForward.php similarity index 96% rename from app/Model/Chat/TalkRecordsForward.php rename to app/Model/Talk/TalkRecordsForward.php index 18071c8..794e991 100644 --- a/app/Model/Chat/TalkRecordsForward.php +++ b/app/Model/Talk/TalkRecordsForward.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Model/Chat/TalkRecordsInvite.php b/app/Model/Talk/TalkRecordsInvite.php similarity index 97% rename from app/Model/Chat/TalkRecordsInvite.php rename to app/Model/Talk/TalkRecordsInvite.php index 63eabc2..e3293d8 100644 --- a/app/Model/Chat/TalkRecordsInvite.php +++ b/app/Model/Talk/TalkRecordsInvite.php @@ -2,7 +2,7 @@ declare (strict_types=1); -namespace App\Model\Chat; +namespace App\Model\Talk; use App\Model\BaseModel; diff --git a/app/Process/RedisWebsocketSubscribe.php b/app/Process/RedisWebsocketSubscribe.php index cde1c2b..30812c0 100644 --- a/app/Process/RedisWebsocketSubscribe.php +++ b/app/Process/RedisWebsocketSubscribe.php @@ -9,6 +9,7 @@ use Hyperf\Process\AbstractProcess; use Hyperf\Process\Annotation\Process; /** + * Websocket 消息订阅处理服务 * @Process(name="RedisWebsocketSubscribe") */ class RedisWebsocketSubscribe extends AbstractProcess @@ -25,6 +26,9 @@ class RedisWebsocketSubscribe extends AbstractProcess */ private $handleService; + /** + * 执行入口 + */ public function handle(): void { $this->handleService = container()->get(SubscribeHandleService::class); @@ -44,13 +48,6 @@ class RedisWebsocketSubscribe extends AbstractProcess //echo PHP_EOL . "chan : $chan , msg : $message"; $data = json_decode($message, true); - if (!isset(SubscribeHandleService::EVENTS[$data['event']])) return; - - $this->handleService->{SubscribeHandleService::EVENTS[$data['event']]}($data); - } - - public function isEnable($server): bool - { - return true; + $this->handleService->handle($data); } } diff --git a/app/Service/EmoticonService.php b/app/Service/EmoticonService.php index 944a1d6..d89ab82 100644 --- a/app/Service/EmoticonService.php +++ b/app/Service/EmoticonService.php @@ -4,8 +4,8 @@ namespace App\Service; use App\Constants\TalkMessageType; use App\Constants\TalkMode; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsFile; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsFile; use App\Model\EmoticonItem; use App\Model\Group\Group; use App\Model\UsersEmoticon; diff --git a/app/Service/GroupService.php b/app/Service/GroupService.php index 5493700..2761f96 100644 --- a/app/Service/GroupService.php +++ b/app/Service/GroupService.php @@ -6,11 +6,11 @@ namespace App\Service; use App\Cache\LastMessage; use App\Constants\TalkMessageType; use App\Constants\TalkMode; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsInvite; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsInvite; use App\Model\Group\Group; use App\Model\Group\GroupMember; -use App\Model\TalkList; +use App\Model\Talk\TalkList; use Hyperf\DbConnection\Db; use Exception; diff --git a/app/Service/Message/ReceiveHandleService.php b/app/Service/Message/ReceiveHandleService.php index 48b102b..8f0018a 100644 --- a/app/Service/Message/ReceiveHandleService.php +++ b/app/Service/Message/ReceiveHandleService.php @@ -7,7 +7,7 @@ use App\Cache\UnreadTalk; use App\Constants\TalkMessageEvent; use App\Constants\TalkMessageType; use App\Constants\TalkMode; -use App\Model\Chat\TalkRecords; +use App\Model\Talk\TalkRecords; use App\Model\Group\Group; use App\Model\UsersFriend; use App\Service\SocketClientService; diff --git a/app/Service/Message/SubscribeHandleService.php b/app/Service/Message/SubscribeHandleService.php index cc05616..521d927 100644 --- a/app/Service/Message/SubscribeHandleService.php +++ b/app/Service/Message/SubscribeHandleService.php @@ -6,17 +6,16 @@ use App\Cache\SocketRoom; use App\Constants\TalkMessageEvent; use App\Constants\TalkMessageType; use App\Constants\TalkMode; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsCode; -use App\Model\Chat\TalkRecordsFile; -use App\Model\Chat\TalkRecordsForward; -use App\Model\Chat\TalkRecordsInvite; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsCode; +use App\Model\Talk\TalkRecordsFile; +use App\Model\Talk\TalkRecordsForward; +use App\Model\Talk\TalkRecordsInvite; use App\Model\Group\Group; use App\Model\User; use App\Model\UsersFriendsApply; use App\Service\SocketClientService; use App\Service\UserService; -use Hyperf\Amqp\Result; class SubscribeHandleService { @@ -52,6 +51,24 @@ class SubscribeHandleService $this->clientService = $clientService; } + /** + * @param array $data + *
+     * [
+     * 'uuid'    => '',
+     * 'event'   => '',
+     * 'data'    => '',
+     * 'options' => ''
+     * ];
+     * 
+ */ + public function handle(array $data) + { + if (isset(self::EVENTS[$data['event']])) { + call_user_func([$this, self::EVENTS[$data['event']]], $data); + } + } + /** * 对话聊天消息 * diff --git a/app/Service/TalkListService.php b/app/Service/TalkListService.php index a556d23..5191f02 100644 --- a/app/Service/TalkListService.php +++ b/app/Service/TalkListService.php @@ -6,7 +6,7 @@ use App\Cache\LastMessage; use App\Cache\ServerRunID; use App\Cache\UnreadTalk; use App\Constants\TalkMode; -use App\Model\TalkList; +use App\Model\Talk\TalkList; use App\Model\UsersFriend; class TalkListService diff --git a/app/Service/TalkMessageService.php b/app/Service/TalkMessageService.php index 1cd87b2..bb2e96f 100644 --- a/app/Service/TalkMessageService.php +++ b/app/Service/TalkMessageService.php @@ -3,11 +3,11 @@ namespace App\Service; use App\Constants\TalkMessageType; -use App\Model\Chat\TalkRecordsCode; +use App\Model\Talk\TalkRecordsCode; use Exception; use App\Constants\MediaFileType; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsFile; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsFile; use Hyperf\DbConnection\Db; class TalkMessageService diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index 8f8fc7f..cb23160 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -8,11 +8,11 @@ use Exception; use App\Model\User; use App\Model\UsersFriend; use App\Model\Group\Group; -use App\Model\Chat\TalkRecords; -use App\Model\Chat\TalkRecordsCode; -use App\Model\Chat\TalkRecordsFile; -use App\Model\Chat\TalkRecordsForward; -use App\Model\Chat\TalkRecordsInvite; +use App\Model\Talk\TalkRecords; +use App\Model\Talk\TalkRecordsCode; +use App\Model\Talk\TalkRecordsFile; +use App\Model\Talk\TalkRecordsForward; +use App\Model\Talk\TalkRecordsInvite; use App\Traits\PagingTrait; use Hyperf\DbConnection\Db; diff --git a/app/Support/MessageProducer.php b/app/Support/MessageProducer.php index ea20986..1f3435a 100644 --- a/app/Support/MessageProducer.php +++ b/app/Support/MessageProducer.php @@ -1,9 +1,7 @@