Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit b5ddef3

Browse files
committed
Fixed the .here() not working
1 parent 76bc482 commit b5ddef3

File tree

1 file changed

+15
-50
lines changed

1 file changed

+15
-50
lines changed

src/Channels/PresenceChannel.php

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload)
3434
$this->channelManager
3535
->getChannelMembers($connection->app->id, $this->getName())
3636
->then(function ($users) use ($connection) {
37+
$hash = [];
38+
39+
foreach ($users as $socketId => $user) {
40+
$hash[$user->user_id] = $user->user_info ?? [];
41+
}
42+
3743
$connection->send(json_encode([
3844
'event' => 'pusher_internal:subscription_succeeded',
3945
'channel' => $this->getName(),
40-
'data' => json_encode($this->getChannelData($users)),
46+
'data' => json_encode([
47+
'presence' => [
48+
'ids' => collect($users)->map(function ($user) {
49+
return (string) $user->user_id;
50+
})->values(),
51+
'hash' => $hash,
52+
'count' => count($users),
53+
],
54+
]),
4155
]));
4256
});
4357

@@ -95,53 +109,4 @@ public function unsubscribe(ConnectionInterface $connection)
95109
);
96110
});
97111
}
98-
99-
/**
100-
* Get the Presence channel data.
101-
*
102-
* @param array $users
103-
* @return array
104-
*/
105-
protected function getChannelData(array $users): array
106-
{
107-
return [
108-
'presence' => [
109-
'ids' => $this->getUserIds($users),
110-
'hash' => $this->getHash($users),
111-
'count' => count($users),
112-
],
113-
];
114-
}
115-
116-
/**
117-
* Get the Presence Channel's users.
118-
*
119-
* @param array $users
120-
* @return array
121-
*/
122-
protected function getUserIds(array $users): array
123-
{
124-
return collect($users)
125-
->map(function ($user) {
126-
return (string) $user->user_id;
127-
})
128-
->values();
129-
}
130-
131-
/**
132-
* Compute the hash for the presence channel integrity.
133-
*
134-
* @param array $users
135-
* @return array
136-
*/
137-
protected function getHash(array $users): array
138-
{
139-
$hash = [];
140-
141-
foreach ($users as $socketId => $user) {
142-
$hash[$user->user_id] = $user->user_info ?? [];
143-
}
144-
145-
return $hash;
146-
}
147112
}

0 commit comments

Comments
 (0)