优化代码

main
gzydong 2021-04-08 09:20:51 +08:00
parent 3d22010bec
commit 01f36b5fa8
1 changed files with 35 additions and 35 deletions

View File

@ -154,7 +154,7 @@ class ChatMessageConsumer extends ConsumerMessage
{ {
$source = $data['data']['source']; $source = $data['data']['source'];
$fds = $this->socketClientService->findUserFds($data['data']['sender']); $fds = $this->socketClientService->findUserFds($data['data']['sender']);
$group_name = ''; $groupInfo = null;
if ($source == 1) {// 私聊 if ($source == 1) {// 私聊
$fds = array_merge($fds, $this->socketClientService->findUserFds($data['data']['receive'])); $fds = array_merge($fds, $this->socketClientService->findUserFds($data['data']['receive']));
@ -164,7 +164,7 @@ class ChatMessageConsumer extends ConsumerMessage
$fds = array_merge($fds, $this->socketClientService->findUserFds((int)$uid)); $fds = array_merge($fds, $this->socketClientService->findUserFds((int)$uid));
} }
$group_name = Group::where('id', $data['data']['receive'])->value('group_name'); $groupInfo = Group::where('id', $data['data']['receive'])->first(['group_name', 'avatar']);
} }
// 客户端ID去重 // 客户端ID去重
@ -240,7 +240,8 @@ class ChatMessageConsumer extends ConsumerMessage
'source' => $result->source, 'source' => $result->source,
'avatar' => $result->avatar, 'avatar' => $result->avatar,
'nickname' => $result->nickname, 'nickname' => $result->nickname,
'group_name' => $group_name, 'group_name' => $groupInfo ? $groupInfo->group_name : '',
'group_avatar' => $groupInfo ? $groupInfo->avatar : '',
"user_id" => $result->user_id, "user_id" => $result->user_id,
"receive_id" => $result->receive_id, "receive_id" => $result->receive_id,
"created_at" => $result->created_at, "created_at" => $result->created_at,
@ -252,8 +253,6 @@ class ChatMessageConsumer extends ConsumerMessage
]) ])
]; ];
unset($result, $file, $code_block, $forward, $invite);
$this->socketPushNotify($fds, json_encode([SocketConstants::EVENT_TALK, $notify])); $this->socketPushNotify($fds, json_encode([SocketConstants::EVENT_TALK, $notify]));
return Result::ACK; return Result::ACK;
@ -383,6 +382,7 @@ class ChatMessageConsumer extends ConsumerMessage
"nickname" => "",// 用户昵称 "nickname" => "",// 用户昵称
"avatar" => "",// 用户头像 "avatar" => "",// 用户头像
"group_name" => "",// 群组名称 "group_name" => "",// 群组名称
"group_avatar" => "",// 群组头像
// 不同的消息类型 // 不同的消息类型
"file" => [], "file" => [],