Files
backend-mm/routes/channels.php

35 lines
1.0 KiB
PHP

<?php
use App\Support\ChatSupport;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\DB;
/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
$isParticipant = DB::table('conversation_user')
->where('conversation_id', $conversationId)
->where('user_id', $user->id)
->exists();
if ($isParticipant) {
return true;
}
return ChatSupport::isOperator($user)
&& ChatSupport::conversationIncludesSupport((int) $conversationId);
});
Broadcast::channel('chat.support', function ($user) {
return ChatSupport::isOperator($user);
});