2018-11-22 21:20:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-11-27 15:11:12 +00:00
|
|
|
namespace BeyondCode\LaravelWebSockets\WebSockets\Controllers;
|
2018-11-22 21:20:23 +00:00
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2018-11-27 15:07:29 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\WebSocket\Pusher\Channels\PresenceChannel;
|
2018-11-22 21:20:23 +00:00
|
|
|
|
2018-11-27 14:59:02 +00:00
|
|
|
class FetchChannels extends Controller
|
2018-11-22 21:20:23 +00:00
|
|
|
{
|
|
|
|
|
public function __invoke(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$channels = Collection::make($this->channelManager->getChannels($request->appId))->filter(function ($channel) {
|
|
|
|
|
return $channel instanceof PresenceChannel;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if ($request->has('filter_by_prefix')) {
|
|
|
|
|
$channels = $channels->filter(function ($channel, $channelName) use ($request) {
|
|
|
|
|
return starts_with($channelName, $request->filter_by_prefix);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'channels' => $channels->map(function ($channel) {
|
|
|
|
|
return [
|
|
|
|
|
'user_count' => count($channel->getUsers()),
|
|
|
|
|
];
|
|
|
|
|
})->toArray()
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|