Avoid displaying twice the same-id channel members
This commit is contained in:
parent
b41f8b7b75
commit
5808a6610c
|
|
@ -302,7 +302,7 @@ class LocalChannelManager implements ChannelManager
|
|||
|
||||
$members = collect($members)->map(function ($user) {
|
||||
return json_decode($user);
|
||||
})->toArray();
|
||||
})->unique('id')->toArray();
|
||||
|
||||
return new FulfilledPromise($members);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,6 +347,7 @@ class RedisChannelManager extends LocalChannelManager
|
|||
->map(function ($user) {
|
||||
return json_decode($user);
|
||||
})
|
||||
->unique('id')
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,4 +116,34 @@ class FetchUsersTest extends TestCase
|
|||
'users' => [['id' => 1]],
|
||||
], json_decode($response->getContent(), true));
|
||||
}
|
||||
|
||||
public function test_multiple_clients_with_same_id_gets_counted_once()
|
||||
{
|
||||
$rick = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
|
||||
$morty = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
|
||||
|
||||
$connection = new Mocks\Connection;
|
||||
|
||||
$requestPath = '/apps/1234/channel/presence-channel/users';
|
||||
|
||||
$routeParams = [
|
||||
'appId' => '1234',
|
||||
'channelName' => 'presence-channel',
|
||||
];
|
||||
|
||||
$queryString = Pusher::build_auth_query_string('TestKey', 'TestSecret', 'GET', $requestPath);
|
||||
|
||||
$request = new Request('GET', "{$requestPath}?{$queryString}&".http_build_query($routeParams));
|
||||
|
||||
$controller = app(FetchUsers::class);
|
||||
|
||||
$controller->onOpen($connection, $request);
|
||||
|
||||
/** @var \Illuminate\Http\JsonResponse $response */
|
||||
$response = array_pop($connection->sentRawData);
|
||||
|
||||
$this->assertSame([
|
||||
'users' => [['id' => 1]],
|
||||
], json_decode($response->getContent(), true));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue