mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 21:52:08 +00:00
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?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),
|
|
);
|
|
}
|
|
}
|