53 lines
1.4 KiB
PHP
53 lines
1.4 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.inbox.{userId}', function ($user, $userId) {
|
|
if (! ctype_digit((string) $userId)) {
|
|
return false;
|
|
}
|
|
|
|
return (int) $user->id === (int) $userId
|
|
&& ChatSupport::canAccessPanelChat($user);
|
|
});
|
|
|
|
Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
|
|
if ($conversationId === 'support') {
|
|
return ChatSupport::isOperator($user);
|
|
}
|
|
|
|
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);
|
|
});
|