Repository navigation
Expand file tree
/
Copy pathCreateConversationCallRequest.php
More file actions
56 lines (46 loc) · 1.72 KB
/
Copy pathCreateConversationCallRequest.php
File metadata and controls
56 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use App\Enums\PushAccess;
use App\Models\Conversation;
use App\Models\User;
use App\Queries\CallQuery;
use App\Queries\OrgCallQuery;
use App\Queries\PushAccessQuery;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Http\FormRequest;
final class CreateConversationCallRequest extends FormRequest
{
/**
* A call goes where a ping could: into a conversation that has started, to someone who can still be pushed to,
* and not over another call ringing for them, nor into an org's call either of them is in.
*/
public function authorize(PushAccessQuery $access, CallQuery $calls, OrgCallQuery $orgCalls): Response
{
$user = $this->user();
assert($user instanceof User);
$partner = $this->route('partner');
assert($partner instanceof User);
if (! $user->canMessage($partner)) {
return Response::denyAsNotFound();
}
if ($orgCalls->isInOne($user)) {
return Response::deny("You're already on a call.");
}
if ($access->get($user, $partner) !== PushAccess::Open || $calls->get($partner)?->isFrom($user) === false || $orgCalls->isInOne($partner)) {
return Response::deny("You can't call {$partner->mention()} right now.");
}
return Conversation::between($user, $partner) instanceof Conversation
? Response::allow()
: Response::deny("Say hi to {$partner->mention()} before calling them.");
}
/**
* @return array<string, array<int, string>>
*/
public function rules(): array
{
return [
'sdp' => ['required', 'string', 'starts_with:v=0', 'max:10000'],
];
}
}