feat: add Reverb realtime messaging

This commit is contained in:
2026-03-21 12:51:59 +01:00
parent 60f78e8235
commit e8b5edf5d2
45 changed files with 3609 additions and 339 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Policies;
use App\Models\Conversation;
use App\Models\ConversationParticipant;
use App\Models\User;
class ConversationPolicy
{
public function view(User $user, Conversation $conversation): bool
{
return $this->participantRecord($user, $conversation) !== null
&& (bool) ($conversation->is_active ?? true);
}
public function send(User $user, Conversation $conversation): bool
{
return $this->view($user, $conversation);
}
public function manageParticipants(User $user, Conversation $conversation): bool
{
$participant = $this->participantRecord($user, $conversation);
return $participant !== null && $participant->role === 'admin';
}
public function rename(User $user, Conversation $conversation): bool
{
return $conversation->isGroup() && $this->manageParticipants($user, $conversation);
}
public function joinPresence(User $user, Conversation $conversation): bool
{
return $this->view($user, $conversation);
}
private function participantRecord(User $user, Conversation $conversation): ?ConversationParticipant
{
return ConversationParticipant::query()
->where('conversation_id', $conversation->id)
->where('user_id', $user->id)
->whereNull('left_at')
->first();
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Policies;
use App\Models\ConversationParticipant;
use App\Models\Message;
use App\Models\User;
class MessagePolicy
{
public function view(User $user, Message $message): bool
{
return ConversationParticipant::query()
->where('conversation_id', $message->conversation_id)
->where('user_id', $user->id)
->whereNull('left_at')
->exists();
}
public function update(User $user, Message $message): bool
{
return $message->sender_id === $user->id && $message->deleted_at === null;
}
public function delete(User $user, Message $message): bool
{
return $message->sender_id === $user->id || $user->isAdmin();
}
}