Files
backend-mm/routes/channels.php
Mekan1206 c55694ec8c WIP
2026-08-15 21:01:10 +05:00

41 lines
1.1 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.support', function ($user) {
return ChatSupport::isOperator($user);
});
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
if (! ctype_digit((string) $conversationId)) {
return false;
}
$conversationId = (int) $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($conversationId);
});