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

Commit 16ff2aa

Browse files
committed
Fixed uniqueness
1 parent b7ba98a commit 16ff2aa

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/ChannelManagers/LocalChannelManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function getChannelMembers($appId, string $channel): PromiseInterface
323323

324324
$members = collect($members)->map(function ($user) {
325325
return json_decode($user);
326-
})->unique('id')->toArray();
326+
})->unique('user_id')->toArray();
327327

328328
return new FulfilledPromise($members);
329329
}

src/ChannelManagers/RedisChannelManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function getChannelMembers($appId, string $channel): PromiseInterface
350350
->map(function ($user) {
351351
return json_decode($user);
352352
})
353-
->unique('id')
353+
->unique('user_id')
354354
->toArray();
355355
});
356356
}

tests/PresenceChannelTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,41 @@ public function test_connect_to_presence_channel_when_user_with_same_ids_is_alre
7373
]);
7474
}
7575

76+
$rick->assertSentEvent('pusher_internal:subscription_succeeded', [
77+
'channel' => 'presence-channel',
78+
'data' => json_encode([
79+
'presence' => [
80+
'ids' => ['1'],
81+
'hash' => ['1' => []],
82+
'count' => 1,
83+
],
84+
]),
85+
]);
86+
87+
$morty->assertSentEvent('pusher_internal:subscription_succeeded', [
88+
'channel' => 'presence-channel',
89+
'data' => json_encode([
90+
'presence' => [
91+
'ids' => ['1', '2'],
92+
'hash' => ['1' => [], '2' => []],
93+
'count' => 2,
94+
],
95+
]),
96+
]);
97+
98+
// The duplicated-user_id connection should get basically the list of ids
99+
// without dealing with duplicate user ids.
100+
$pickleRick->assertSentEvent('pusher_internal:subscription_succeeded', [
101+
'channel' => 'presence-channel',
102+
'data' => json_encode([
103+
'presence' => [
104+
'ids' => ['1', '2'],
105+
'hash' => ['1' => [], '2' => []],
106+
'count' => 2,
107+
],
108+
]),
109+
]);
110+
76111
$this->channelManager
77112
->getGlobalConnectionsCount('1234', 'presence-channel')
78113
->then(function ($total) {

0 commit comments

Comments
 (0)