From b5ddef3544a86ec0c93adfe28d298778c97e8c9b Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Fri, 11 Sep 2020 08:46:02 +0300 Subject: [PATCH] Fixed the .here() not working --- src/Channels/PresenceChannel.php | 65 ++++++++------------------------ 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/src/Channels/PresenceChannel.php b/src/Channels/PresenceChannel.php index ae22ecd..2bfa8ef 100644 --- a/src/Channels/PresenceChannel.php +++ b/src/Channels/PresenceChannel.php @@ -34,10 +34,24 @@ class PresenceChannel extends PrivateChannel $this->channelManager ->getChannelMembers($connection->app->id, $this->getName()) ->then(function ($users) use ($connection) { + $hash = []; + + foreach ($users as $socketId => $user) { + $hash[$user->user_id] = $user->user_info ?? []; + } + $connection->send(json_encode([ 'event' => 'pusher_internal:subscription_succeeded', 'channel' => $this->getName(), - 'data' => json_encode($this->getChannelData($users)), + 'data' => json_encode([ + 'presence' => [ + 'ids' => collect($users)->map(function ($user) { + return (string) $user->user_id; + })->values(), + 'hash' => $hash, + 'count' => count($users), + ], + ]), ])); }); @@ -95,53 +109,4 @@ class PresenceChannel extends PrivateChannel ); }); } - - /** - * Get the Presence channel data. - * - * @param array $users - * @return array - */ - protected function getChannelData(array $users): array - { - return [ - 'presence' => [ - 'ids' => $this->getUserIds($users), - 'hash' => $this->getHash($users), - 'count' => count($users), - ], - ]; - } - - /** - * Get the Presence Channel's users. - * - * @param array $users - * @return array - */ - protected function getUserIds(array $users): array - { - return collect($users) - ->map(function ($user) { - return (string) $user->user_id; - }) - ->values(); - } - - /** - * Compute the hash for the presence channel integrity. - * - * @param array $users - * @return array - */ - protected function getHash(array $users): array - { - $hash = []; - - foreach ($users as $socketId => $user) { - $hash[$user->user_id] = $user->user_info ?? []; - } - - return $hash; - } }