diff --git a/src/ChannelManagers/LocalChannelManager.php b/src/ChannelManagers/LocalChannelManager.php index c29f7ff..5d33f83 100644 --- a/src/ChannelManagers/LocalChannelManager.php +++ b/src/ChannelManagers/LocalChannelManager.php @@ -323,7 +323,7 @@ class LocalChannelManager implements ChannelManager $members = collect($members)->map(function ($user) { return json_decode($user); - })->unique('id')->toArray(); + })->unique('user_id')->toArray(); return new FulfilledPromise($members); } diff --git a/src/ChannelManagers/RedisChannelManager.php b/src/ChannelManagers/RedisChannelManager.php index f914b2c..9b71d9a 100644 --- a/src/ChannelManagers/RedisChannelManager.php +++ b/src/ChannelManagers/RedisChannelManager.php @@ -350,7 +350,7 @@ class RedisChannelManager extends LocalChannelManager ->map(function ($user) { return json_decode($user); }) - ->unique('id') + ->unique('user_id') ->toArray(); }); } diff --git a/tests/PresenceChannelTest.php b/tests/PresenceChannelTest.php index 755f895..55ad3d1 100644 --- a/tests/PresenceChannelTest.php +++ b/tests/PresenceChannelTest.php @@ -73,6 +73,41 @@ class PresenceChannelTest extends TestCase ]); } + $rick->assertSentEvent('pusher_internal:subscription_succeeded', [ + 'channel' => 'presence-channel', + 'data' => json_encode([ + 'presence' => [ + 'ids' => ['1'], + 'hash' => ['1' => []], + 'count' => 1, + ], + ]), + ]); + + $morty->assertSentEvent('pusher_internal:subscription_succeeded', [ + 'channel' => 'presence-channel', + 'data' => json_encode([ + 'presence' => [ + 'ids' => ['1', '2'], + 'hash' => ['1' => [], '2' => []], + 'count' => 2, + ], + ]), + ]); + + // The duplicated-user_id connection should get basically the list of ids + // without dealing with duplicate user ids. + $pickleRick->assertSentEvent('pusher_internal:subscription_succeeded', [ + 'channel' => 'presence-channel', + 'data' => json_encode([ + 'presence' => [ + 'ids' => ['1', '2'], + 'hash' => ['1' => [], '2' => []], + 'count' => 2, + ], + ]), + ]); + $this->channelManager ->getGlobalConnectionsCount('1234', 'presence-channel') ->then(function ($total) {