代码优化

main
gzydong 2021-07-09 22:57:19 +08:00
parent b63c33e2ae
commit e495847a73
19 changed files with 66 additions and 47 deletions

View File

@ -9,10 +9,14 @@ namespace App\Constants;
*/
class TalkMode
{
// 私信
/**
* 私信
*/
const PRIVATE_CHAT = 1;
// 群聊
/**
* 群聊
*/
const GROUP_CHAT = 2;
public static function getTypes()

View File

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

View File

@ -2,7 +2,9 @@
declare (strict_types=1);
namespace App\Model;
namespace App\Model\Talk;
use App\Model\BaseModel;
/**
* 聊天列表组数据表模型

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

@ -2,7 +2,7 @@
declare (strict_types=1);
namespace App\Model\Chat;
namespace App\Model\Talk;
use App\Model\BaseModel;

View File

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

View File

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

View File

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

View File

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

View File

@ -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
* <pre>
* [
* 'uuid' => '',
* 'event' => '',
* 'data' => '',
* 'options' => ''
* ];
* </pre>
*/
public function handle(array $data)
{
if (isset(self::EVENTS[$data['event']])) {
call_user_func([$this, self::EVENTS[$data['event']]], $data);
}
}
/**
* 对话聊天消息
*

View File

@ -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

View File

@ -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

View File

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

View File

@ -1,9 +1,7 @@
<?php
namespace App\Support;
use App\Constants\RedisSubscribeChan;
class MessageProducer
@ -25,6 +23,8 @@ class MessageProducer
}
/**
* 推送消息至 Redis 订阅通道中
*
* @param array $message
*/
public static function publish(array $message)

View File

@ -11,6 +11,10 @@ trait StaticInstance
{
private static $instance;
private function __construct()
{
}
/**
* 获取单例
*
@ -25,12 +29,7 @@ trait StaticInstance
return static::$instance;
}
private function __construct()
{
}
private function __clone()
{
}
}