allow anyone controll room option

This commit is contained in:
2026-08-27 15:41:21 +02:00
parent b2c1d67283
commit 72152e2d45
16 changed files with 328 additions and 11 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Services\Rooms;
use App\Enums\RoomStateChange;
use App\Events\RoomStateChanged;
use App\Models\Room;
use Illuminate\Support\Facades\DB;
class RoomPermissionService
{
public function __construct(
private readonly RoomRealtimeStateService $realtimeState,
) {}
public function updateParticipantControls(Room $room, bool $allowParticipantControls): void
{
[$stateVersion, $wasChanged] = DB::transaction(function () use ($room, $allowParticipantControls): array {
$lockedRoom = Room::query()
->lockForUpdate()
->findOrFail($room->id);
if ($lockedRoom->allow_participant_controls === $allowParticipantControls) {
return [$lockedRoom->state_version, false];
}
$lockedRoom->update([
'allow_participant_controls' => $allowParticipantControls,
'last_activity_at' => now(),
'state_version' => $lockedRoom->state_version + 1,
]);
return [$lockedRoom->state_version, true];
});
if (! $wasChanged) {
return;
}
RoomStateChanged::dispatch(
$room->id,
$stateVersion,
RoomStateChange::PermissionsUpdated,
$this->realtimeState->for($room),
);
}
}
@@ -15,6 +15,7 @@ class RoomRealtimeStateService
* current_round: int,
* revealed: bool,
* state_version: int,
* allow_participant_controls: bool,
* statistics: array{average: string|null, median: string|null}|null,
* players: array<int, array{
* id: int,
@@ -44,6 +45,7 @@ class RoomRealtimeStateService
'current_round' => $room->current_round,
'revealed' => $room->revealed_at !== null,
'state_version' => $room->state_version,
'allow_participant_controls' => $room->allow_participant_controls,
'statistics' => $this->statistics->currentRound($room),
'players' => $room->players
->map(function ($player) use ($room): array {