mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 23:32:09 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b190ff719e | ||
|
|
54d23c3660 | ||
|
|
640a2970c3 | ||
|
|
2ab95cebdf | ||
|
|
6ca91f3fe9 | ||
|
|
2f6cdcf591 | ||
|
|
f44d822fa3 | ||
|
|
817b1ce1cb | ||
|
|
1e0f5cf143 | ||
|
|
3377a817a3 | ||
|
|
6586ea8ec8 | ||
|
|
d2042fb95b | ||
|
|
164658dae2 | ||
|
|
2f05e56089 | ||
|
|
e30d2e61aa | ||
|
|
e58a398c07 | ||
|
|
8aa6428089 | ||
|
|
b2c1d67283 | ||
|
|
d6e5455e90 |
@@ -0,0 +1,7 @@
|
|||||||
|
# Project Rules Index
|
||||||
|
|
||||||
|
Before planning or editing, find the row whose globs match the file's path and read that rule file.
|
||||||
|
|
||||||
|
| Applies to | Rule file |
|
||||||
|
| --- | --- |
|
||||||
|
| {app/Events/**,app/Services/Rooms/**,resources/js/composables/**} | .ai/rules/js-composables.md |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
paths:
|
||||||
|
- '{app/Events/**,app/Services/Rooms/**,resources/js/composables/**}'
|
||||||
|
---
|
||||||
|
|
||||||
|
# Js Composables
|
||||||
|
|
||||||
|
## Never broadcast hidden room votes
|
||||||
|
Room table updates are delivered as synchronous WebSocket state payloads without polling or Inertia reloads. Before a round is revealed, broadcast only has_voted and keep every player's vote null; actual vote values may enter the shared payload only after reveal. State-changing commands remain server-authorized HTTP requests.
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
[mcp_servers.laravel-boost]
|
[mcp_servers.laravel-boost]
|
||||||
command = "php"
|
command = "php"
|
||||||
args = ["artisan", "boost:mcp"]
|
args = ["artisan", "boost:mcp"]
|
||||||
|
|
||||||
[mcp_servers.nightwatch]
|
|
||||||
command = "npx"
|
|
||||||
args = ["-y", "mcp-remote", "https://nightwatch.laravel.com/mcp"]
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
printf -v run_attempt '%03d' "${GITHUB_RUN_ATTEMPT}"
|
printf -v run_attempt '%03d' "${GITHUB_RUN_ATTEMPT}"
|
||||||
tag="main-${GITHUB_RUN_NUMBER}-${run_attempt}-${GITHUB_SHA:0:12}"
|
tag="main-${GITHUB_RUN_NUMBER}-${run_attempt}-${GITHUB_SHA:0:12}"
|
||||||
environment="staging"
|
environment="staging"
|
||||||
vite_app_version="staging-${GITHUB_SHA:0:12}"
|
vite_app_version="main-${GITHUB_SHA:0:12}"
|
||||||
vite_reverb_app_key="1af96b48d2ef78983e4ef281eed3a48b"
|
vite_reverb_app_key="1af96b48d2ef78983e4ef281eed3a48b"
|
||||||
vite_reverb_host="scrum-poker.twyco-staging.de"
|
vite_reverb_host="scrum-poker.twyco-staging.de"
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
# Scrumpoker without AD's
|
# Scrumpoker without AD's
|
||||||
|
|
||||||
trigger workflow
|
trigger workflow
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ namespace App\Enums;
|
|||||||
enum RoomStateChange: string
|
enum RoomStateChange: string
|
||||||
{
|
{
|
||||||
case PlayerJoined = 'player_joined';
|
case PlayerJoined = 'player_joined';
|
||||||
|
case PlayerUpdated = 'player_updated';
|
||||||
|
case PlayerKicked = 'player_kicked';
|
||||||
|
case PlayerInstanceReplaced = 'player_instance_replaced';
|
||||||
case VoteChanged = 'vote_changed';
|
case VoteChanged = 'vote_changed';
|
||||||
case CardsRevealed = 'cards_revealed';
|
case CardsRevealed = 'cards_revealed';
|
||||||
case VotesReset = 'votes_reset';
|
case VotesReset = 'votes_reset';
|
||||||
@@ -12,4 +15,5 @@ enum RoomStateChange: string
|
|||||||
case RoomReopened = 'room_reopened';
|
case RoomReopened = 'room_reopened';
|
||||||
case RoomClosed = 'room_closed';
|
case RoomClosed = 'room_closed';
|
||||||
case RoomDeleted = 'room_deleted';
|
case RoomDeleted = 'room_deleted';
|
||||||
|
case RoomSettingsUpdated = 'room_settings_updated';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,24 @@ namespace App\Events;
|
|||||||
use App\Enums\RoomStateChange;
|
use App\Enums\RoomStateChange;
|
||||||
use Illuminate\Broadcasting\Channel;
|
use Illuminate\Broadcasting\Channel;
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class RoomStateChanged implements ShouldBroadcast
|
class RoomStateChanged implements ShouldBroadcastNow
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed>|null $state
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly string $roomId,
|
public readonly string $roomId,
|
||||||
public readonly int $version,
|
public readonly int $version,
|
||||||
public readonly RoomStateChange $change,
|
public readonly RoomStateChange $change,
|
||||||
|
public readonly ?array $state = null,
|
||||||
|
public readonly ?int $affectedPlayerId = null,
|
||||||
|
public readonly ?string $affectedInstanceId = null,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function broadcastOn(): Channel
|
public function broadcastOn(): Channel
|
||||||
@@ -30,13 +36,24 @@ class RoomStateChanged implements ShouldBroadcast
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{version: int, change: string}
|
* @return array{version: int, change: string, state: array<string, mixed>|null, affected_player_id?: int, affected_instance_id?: string}
|
||||||
*/
|
*/
|
||||||
public function broadcastWith(): array
|
public function broadcastWith(): array
|
||||||
{
|
{
|
||||||
return [
|
$payload = [
|
||||||
'version' => $this->version,
|
'version' => $this->version,
|
||||||
'change' => $this->change->value,
|
'change' => $this->change->value,
|
||||||
|
'state' => $this->state,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($this->affectedPlayerId !== null) {
|
||||||
|
$payload['affected_player_id'] = $this->affectedPlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->affectedInstanceId !== null) {
|
||||||
|
$payload['affected_instance_id'] = $this->affectedInstanceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class EmbeddedLogoutController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the incoming request.
|
||||||
|
*/
|
||||||
|
public function __invoke(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$joinCode = $request->string('join_code')->trim()->upper()->toString();
|
||||||
|
$playerName = $request->string('player_name')->trim()->toString();
|
||||||
|
$room = Room::query()->where('join_code', $joinCode)->first();
|
||||||
|
$playerId = null;
|
||||||
|
|
||||||
|
if ($room !== null) {
|
||||||
|
$sessionPlayerId = $request->session()->get("room_players.{$room->id}");
|
||||||
|
|
||||||
|
if (is_numeric($sessionPlayerId)) {
|
||||||
|
$playerId = $room->players()
|
||||||
|
->whereKey((int) $sessionPlayerId)
|
||||||
|
->value('id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Auth::guard('web')->logout();
|
||||||
|
$request->session()->invalidate();
|
||||||
|
$request->session()->regenerateToken();
|
||||||
|
|
||||||
|
if ($room !== null && is_numeric($playerId)) {
|
||||||
|
$request->session()->put("room_players.{$room->id}", (int) $playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return to_route('embedded.room', [
|
||||||
|
'join_code' => $joinCode,
|
||||||
|
'player_name' => $playerName,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\ShowEmbeddedRoomRequest;
|
||||||
|
use App\Http\Resources\CurrentPlayerResource;
|
||||||
|
use App\Http\Resources\RoomResource;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Services\Rooms\RoomPageService;
|
||||||
|
use App\Services\Rooms\RoomParticipationService;
|
||||||
|
use App\Services\Rooms\RoomPlayerInstanceService;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
|
||||||
|
class EmbeddedRoomController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomParticipationService $roomParticipation,
|
||||||
|
private readonly RoomPageService $roomPage,
|
||||||
|
private readonly RoomPlayerInstanceService $playerInstances,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(ShowEmbeddedRoomRequest $request): Response
|
||||||
|
{
|
||||||
|
/** @var array{join_code: string, player_name: string} $validated */
|
||||||
|
$validated = $request->validated();
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$room = Room::query()
|
||||||
|
->where('join_code', $validated['join_code'])
|
||||||
|
->firstOrFail();
|
||||||
|
$player = $this->roomParticipation->joinEmbedded(
|
||||||
|
$room,
|
||||||
|
$user,
|
||||||
|
$validated['player_name'],
|
||||||
|
$request->session()->get("room_players.{$room->id}"),
|
||||||
|
);
|
||||||
|
$player = $this->roomParticipation->activateInstance(
|
||||||
|
$room,
|
||||||
|
$player,
|
||||||
|
$this->playerInstances->for($request),
|
||||||
|
);
|
||||||
|
|
||||||
|
$request->session()->put("room_players.{$room->id}", $player->id);
|
||||||
|
|
||||||
|
$pageData = $this->roomPage->prepare($room, $player, $user);
|
||||||
|
|
||||||
|
return Inertia::render('embedded/Room', [
|
||||||
|
'room' => (new RoomResource($pageData))->resolve($request),
|
||||||
|
'currentPlayer' => (new CurrentPlayerResource($pageData))->resolve($request),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ use App\Models\Player;
|
|||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Services\Rooms\RoomCreationService;
|
use App\Services\Rooms\RoomCreationService;
|
||||||
use App\Services\Rooms\RoomPageService;
|
use App\Services\Rooms\RoomPageService;
|
||||||
|
use App\Services\Rooms\RoomPlayerInstanceService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
@@ -20,6 +21,7 @@ class RoomController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly RoomCreationService $roomCreation,
|
private readonly RoomCreationService $roomCreation,
|
||||||
private readonly RoomPageService $roomPage,
|
private readonly RoomPageService $roomPage,
|
||||||
|
private readonly RoomPlayerInstanceService $playerInstances,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function create(Request $request): Response
|
public function create(Request $request): Response
|
||||||
@@ -40,6 +42,9 @@ class RoomController extends Controller
|
|||||||
$validated,
|
$validated,
|
||||||
$request->user(),
|
$request->user(),
|
||||||
);
|
);
|
||||||
|
$player->update([
|
||||||
|
'active_instance_id' => $this->playerInstances->for($request),
|
||||||
|
]);
|
||||||
|
|
||||||
$request->session()->put(
|
$request->session()->put(
|
||||||
"room_players.{$room->id}",
|
"room_players.{$room->id}",
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Http\Requests\JoinRoomRequest;
|
use App\Http\Requests\JoinRoomRequest;
|
||||||
use App\Services\Rooms\RoomParticipationService;
|
use App\Services\Rooms\RoomParticipationService;
|
||||||
|
use App\Services\Rooms\RoomPlayerInstanceService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
|
||||||
class RoomPlayerController extends Controller
|
class RoomPlayerController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly RoomParticipationService $roomParticipation,
|
private readonly RoomParticipationService $roomParticipation,
|
||||||
|
private readonly RoomPlayerInstanceService $playerInstances,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function join(JoinRoomRequest $request): RedirectResponse
|
public function join(JoinRoomRequest $request): RedirectResponse
|
||||||
@@ -23,6 +25,11 @@ class RoomPlayerController extends Controller
|
|||||||
$request->user(),
|
$request->user(),
|
||||||
is_array($sessionPlayerIds) ? $sessionPlayerIds : [],
|
is_array($sessionPlayerIds) ? $sessionPlayerIds : [],
|
||||||
);
|
);
|
||||||
|
$player = $this->roomParticipation->activateInstance(
|
||||||
|
$room,
|
||||||
|
$player,
|
||||||
|
$this->playerInstances->for($request),
|
||||||
|
);
|
||||||
|
|
||||||
$request->session()->put(
|
$request->session()->put(
|
||||||
"room_players.{$room->id}",
|
"room_players.{$room->id}",
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\KickRoomPlayerRequest;
|
||||||
|
use App\Models\Player;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Services\Rooms\RoomParticipationService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
|
class RoomPlayerKickController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomParticipationService $roomParticipation,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(KickRoomPlayerRequest $request, Room $room, Player $player): RedirectResponse
|
||||||
|
{
|
||||||
|
$this->roomParticipation->kick(
|
||||||
|
$room,
|
||||||
|
$player,
|
||||||
|
$request->user(),
|
||||||
|
$request->currentPlayer($room),
|
||||||
|
);
|
||||||
|
|
||||||
|
Inertia::flash('toast', [
|
||||||
|
'type' => 'success',
|
||||||
|
'message' => "{$player->name} wurde aus dem Raum entfernt.",
|
||||||
|
]);
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\UpdateRoomSettingsRequest;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\Rooms\RoomSettingsService;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
use Inertia\Response;
|
||||||
|
|
||||||
|
class RoomSettingsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomSettingsService $roomSettings,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function edit(Room $room, Request $request): Response
|
||||||
|
{
|
||||||
|
abort_unless($request->user()?->id === $room->owner_id, 403);
|
||||||
|
|
||||||
|
return Inertia::render('rooms/Settings', [
|
||||||
|
'room' => [
|
||||||
|
'id' => $room->id,
|
||||||
|
'title' => $room->title,
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'allow_participants_to_manage_rounds' => $room->allow_participants_to_manage_rounds,
|
||||||
|
'is_persistent' => $room->is_persistent,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateRoomSettingsRequest $request, Room $room): RedirectResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
abort_unless($user instanceof User, 403);
|
||||||
|
|
||||||
|
/** @var array{allow_participants_to_manage_rounds: bool, is_persistent: bool} $settings */
|
||||||
|
$settings = $request->validated();
|
||||||
|
$this->roomSettings->update($room, $user, $settings);
|
||||||
|
|
||||||
|
Inertia::flash('toast', [
|
||||||
|
'type' => 'success',
|
||||||
|
'message' => 'Die Raumeinstellungen wurden gespeichert.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ namespace App\Http\Controllers;
|
|||||||
use App\Models\Player;
|
use App\Models\Player;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Services\Rooms\RoundService;
|
use App\Services\Rooms\RoundService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class RoundController extends Controller
|
class RoundController extends Controller
|
||||||
{
|
{
|
||||||
@@ -14,38 +14,38 @@ class RoundController extends Controller
|
|||||||
private readonly RoundService $rounds,
|
private readonly RoundService $rounds,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function reset(Request $request, Room $room): RedirectResponse
|
public function reset(Request $request, Room $room): Response
|
||||||
{
|
{
|
||||||
$this->ensureModerator($request, $room);
|
$this->ensureCanManageRounds($request, $room);
|
||||||
$this->rounds->reset($room);
|
$this->rounds->reset($room);
|
||||||
|
|
||||||
return back();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reveal(Request $request, Room $room): RedirectResponse
|
public function reveal(Request $request, Room $room): Response
|
||||||
{
|
{
|
||||||
$this->ensureModerator($request, $room);
|
$this->ensureCanManageRounds($request, $room);
|
||||||
$this->rounds->reveal($room);
|
$this->rounds->reveal($room);
|
||||||
|
|
||||||
return back();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRound(Request $request, Room $room): RedirectResponse
|
public function nextRound(Request $request, Room $room): Response
|
||||||
{
|
{
|
||||||
$this->ensureModerator($request, $room);
|
$this->ensureCanManageRounds($request, $room);
|
||||||
$this->rounds->startNext($room);
|
$this->rounds->startNext($room);
|
||||||
|
|
||||||
return back();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ensureModerator(Request $request, Room $room): void
|
private function ensureCanManageRounds(Request $request, Room $room): void
|
||||||
{
|
{
|
||||||
$player = $request->attributes->get('currentPlayer');
|
$player = $request->attributes->get('currentPlayer');
|
||||||
|
|
||||||
abort_unless(
|
abort_unless(
|
||||||
$player instanceof Player
|
$player instanceof Player
|
||||||
&& $player->room_id === $room->id
|
&& $player->room_id === $room->id
|
||||||
&& $player->is_moderator,
|
&& ($player->is_moderator || $room->allow_participants_to_manage_rounds),
|
||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use App\Http\Requests\SubmitVoteRequest;
|
|||||||
use App\Models\Player;
|
use App\Models\Player;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Services\Rooms\VoteService;
|
use App\Services\Rooms\VoteService;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class VoteController extends Controller
|
class VoteController extends Controller
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ class VoteController extends Controller
|
|||||||
public function store(
|
public function store(
|
||||||
SubmitVoteRequest $request,
|
SubmitVoteRequest $request,
|
||||||
Room $room,
|
Room $room,
|
||||||
): RedirectResponse {
|
): Response {
|
||||||
$player = $request->attributes->get('currentPlayer');
|
$player = $request->attributes->get('currentPlayer');
|
||||||
|
|
||||||
abort_unless(
|
abort_unless(
|
||||||
@@ -32,6 +32,6 @@ class VoteController extends Controller
|
|||||||
$request->validated('value'),
|
$request->validated('value'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return back();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
|
use App\Services\Rooms\RoomParticipationService;
|
||||||
|
use App\Services\Rooms\RoomPlayerInstanceService;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
@@ -10,6 +12,11 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
|
|
||||||
class EnsureRoomParticipant
|
class EnsureRoomParticipant
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomParticipationService $roomParticipation,
|
||||||
|
private readonly RoomPlayerInstanceService $playerInstances,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
@@ -44,13 +51,43 @@ class EnsureRoomParticipant
|
|||||||
}
|
}
|
||||||
|
|
||||||
$playerId = $request->session()->get($sessionKey);
|
$playerId = $request->session()->get($sessionKey);
|
||||||
|
$hasSessionPlayer = is_numeric($playerId);
|
||||||
|
$instanceId = $this->playerInstances->for($request);
|
||||||
|
|
||||||
$player = is_numeric($playerId)
|
$player = $hasSessionPlayer
|
||||||
? $room->players()->find((int) $playerId)
|
? $room->players()->find((int) $playerId)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if ($player === null && $playerId) {
|
if ($player === null && $hasSessionPlayer) {
|
||||||
$request->session()->forget($sessionKey);
|
$request->session()->forget($sessionKey);
|
||||||
|
|
||||||
|
return to_route('room.join', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
])->withErrors([
|
||||||
|
'join_code' => 'Diese Spieler-Instanz ist nicht mehr aktiv.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$player !== null
|
||||||
|
&& $player->active_instance_id !== null
|
||||||
|
&& $player->active_instance_id !== $instanceId
|
||||||
|
) {
|
||||||
|
$request->session()->forget($sessionKey);
|
||||||
|
|
||||||
|
return to_route('room.join', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
])->withErrors([
|
||||||
|
'join_code' => 'Dein Account ist diesem Raum in einer anderen Instanz beigetreten.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($player !== null) {
|
||||||
|
$player = $this->roomParticipation->activateInstance(
|
||||||
|
$room,
|
||||||
|
$player,
|
||||||
|
$instanceId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($player === null && $request->user() !== null) {
|
if ($player === null && $request->user() !== null) {
|
||||||
@@ -59,6 +96,11 @@ class EnsureRoomParticipant
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($player !== null) {
|
if ($player !== null) {
|
||||||
|
$player = $this->roomParticipation->activateInstance(
|
||||||
|
$room,
|
||||||
|
$player,
|
||||||
|
$instanceId,
|
||||||
|
);
|
||||||
$request->session()->put($sessionKey, $player->id);
|
$request->session()->put($sessionKey, $player->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Player;
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class KickRoomPlayerRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
$room = $this->route('room');
|
||||||
|
$targetPlayer = $this->route('player');
|
||||||
|
|
||||||
|
if (
|
||||||
|
! $room instanceof Room
|
||||||
|
|| ! $targetPlayer instanceof Player
|
||||||
|
|| $targetPlayer->room_id !== $room->id
|
||||||
|
|| $targetPlayer->is_moderator
|
||||||
|
|| ($room->owner_id !== null && $targetPlayer->user_id === $room->owner_id)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->user();
|
||||||
|
|
||||||
|
if ($user !== null && $user->id === $room->owner_id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentPlayer = $this->currentPlayer($room);
|
||||||
|
|
||||||
|
return ! $room->isClosed()
|
||||||
|
&& $currentPlayer !== null
|
||||||
|
&& $currentPlayer->id !== $targetPlayer->id
|
||||||
|
&& ($currentPlayer->is_moderator || $room->allow_participants_to_manage_rounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function currentPlayer(Room $room): ?Player
|
||||||
|
{
|
||||||
|
$playerId = $this->session()->get("room_players.{$room->id}");
|
||||||
|
|
||||||
|
if (! is_numeric($playerId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $room->activePlayers()->find((int) $playerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, array<int, string>>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Player;
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Contracts\Validation\Validator;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Inertia\Inertia;
|
||||||
|
|
||||||
|
class ShowEmbeddedRoomRequest extends FormRequest
|
||||||
|
{
|
||||||
|
private const string PLAYER_NAME_TAKEN_MESSAGE = 'Dieser Anzeigename ist in dem Raum bereits vorhanden.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
$this->merge([
|
||||||
|
'join_code' => $this->string('join_code')->trim()->upper()->toString(),
|
||||||
|
'player_name' => $this->string('player_name')->trim()->toString(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'join_code' => [
|
||||||
|
'bail',
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'size:6',
|
||||||
|
Rule::exists(Room::class, 'join_code')->whereNull('deleted_at'),
|
||||||
|
],
|
||||||
|
'player_name' => ['required', 'string', 'max:50'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<callable(Validator): void> */
|
||||||
|
public function after(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
function (Validator $validator): void {
|
||||||
|
if ($validator->errors()->has('join_code')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$room = Room::query()
|
||||||
|
->where('join_code', $this->input('join_code'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($room?->isClosed()) {
|
||||||
|
$validator->errors()->add('join_code', 'Dieser Raum ist geschlossen.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($room === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sessionPlayerId = $this->session()->get("room_players.{$room->id}");
|
||||||
|
$existingPlayer = null;
|
||||||
|
|
||||||
|
if ($this->user() !== null) {
|
||||||
|
$existingPlayer = $room->players()
|
||||||
|
->where('user_id', $this->user()->id)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($existingPlayer === null && is_numeric($sessionPlayerId)) {
|
||||||
|
$existingPlayer = $room->players()->find((int) $sessionPlayerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nameIsTaken = Player::query()
|
||||||
|
->where('room_id', $room->id)
|
||||||
|
->where('name', $this->input('player_name'))
|
||||||
|
->when(
|
||||||
|
$existingPlayer !== null,
|
||||||
|
fn ($query) => $query->whereKeyNot($existingPlayer->id),
|
||||||
|
)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($nameIsTaken) {
|
||||||
|
$validator->errors()->add(
|
||||||
|
'player_name',
|
||||||
|
self::PLAYER_NAME_TAKEN_MESSAGE,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'join_code.exists' => 'Dieser Raumcode existiert nicht.',
|
||||||
|
'join_code.size' => 'Der Raumcode muss aus sechs Zeichen bestehen.',
|
||||||
|
'player_name.required' => 'Bitte hinterlege in der Hub-App einen Anzeigenamen.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function failedValidation(Validator $validator): never
|
||||||
|
{
|
||||||
|
$message = $validator->errors()->first();
|
||||||
|
$showLoginAction = $this->user() === null
|
||||||
|
&& $message === self::PLAYER_NAME_TAKEN_MESSAGE;
|
||||||
|
|
||||||
|
if ($showLoginAction) {
|
||||||
|
$this->session()->put('url.intended', $this->fullUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpResponseException(
|
||||||
|
Inertia::render('embedded/Error', [
|
||||||
|
'message' => $message,
|
||||||
|
'showLoginAction' => $showLoginAction,
|
||||||
|
])->toResponse($this)->setStatusCode(422),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateRoomSettingsRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
$room = $this->route('room');
|
||||||
|
|
||||||
|
return $room instanceof Room
|
||||||
|
&& $this->user()?->id === $room->owner_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, array<int, string>>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'allow_participants_to_manage_rounds' => ['required', 'boolean'],
|
||||||
|
'is_persistent' => ['required', 'boolean'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ class CurrentPlayerResource extends JsonResource
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $player->id,
|
'id' => $player->id,
|
||||||
|
'instance_id' => $player->active_instance_id,
|
||||||
'name' => $player->name,
|
'name' => $player->name,
|
||||||
'is_moderator' => $player->is_moderator,
|
'is_moderator' => $player->is_moderator,
|
||||||
'current_vote' => $pageData->currentVote,
|
'current_vote' => $pageData->currentVote,
|
||||||
|
|||||||
@@ -19,6 +19,17 @@ class DashboardRoomResource extends JsonResource
|
|||||||
'current_round' => $this->resource->current_round,
|
'current_round' => $this->resource->current_round,
|
||||||
'players_count' => $this->resource->players_count,
|
'players_count' => $this->resource->players_count,
|
||||||
'active_player_count' => $this->resource->active_player_count,
|
'active_player_count' => $this->resource->active_player_count,
|
||||||
|
'players' => $this->resource->relationLoaded('activePlayers')
|
||||||
|
? $this->resource->activePlayers
|
||||||
|
->map(fn ($player): array => [
|
||||||
|
'id' => $player->id,
|
||||||
|
'name' => $player->name,
|
||||||
|
'is_moderator' => $player->is_moderator,
|
||||||
|
'is_owner' => $player->user_id === $this->resource->owner_id,
|
||||||
|
])
|
||||||
|
->values()
|
||||||
|
->all()
|
||||||
|
: [],
|
||||||
'last_activity_at' => $this->resource->last_activity_at?->toIso8601String(),
|
'last_activity_at' => $this->resource->last_activity_at?->toIso8601String(),
|
||||||
'closed_at' => $this->resource->closed_at?->toIso8601String(),
|
'closed_at' => $this->resource->closed_at?->toIso8601String(),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class RoomResource extends JsonResource
|
|||||||
'current_round' => $room->current_round,
|
'current_round' => $room->current_round,
|
||||||
'revealed' => $room->revealed_at !== null,
|
'revealed' => $room->revealed_at !== null,
|
||||||
'state_version' => $room->state_version,
|
'state_version' => $room->state_version,
|
||||||
|
'allow_participants_to_manage_rounds' => $room->allow_participants_to_manage_rounds,
|
||||||
|
'is_persistent' => $room->is_persistent,
|
||||||
'statistics' => $pageData->statistics,
|
'statistics' => $pageData->statistics,
|
||||||
'deck' => (new RoomDeckResource($room->deck_config))->resolve($request),
|
'deck' => (new RoomDeckResource($room->deck_config))->resolve($request),
|
||||||
'players' => $room->players
|
'players' => $room->players
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class CloseInactiveRooms implements ShouldQueue
|
|||||||
|
|
||||||
Room::query()
|
Room::query()
|
||||||
->whereNull('closed_at')
|
->whereNull('closed_at')
|
||||||
|
->where('is_persistent', false)
|
||||||
->where(function ($query) use ($guestCutoff, $accountCutoff): void {
|
->where(function ($query) use ($guestCutoff, $accountCutoff): void {
|
||||||
$query
|
$query
|
||||||
->where(function ($query) use ($guestCutoff): void {
|
->where(function ($query) use ($guestCutoff): void {
|
||||||
@@ -40,7 +41,12 @@ class CloseInactiveRooms implements ShouldQueue
|
|||||||
->lockForUpdate()
|
->lockForUpdate()
|
||||||
->find((string) $roomId);
|
->find((string) $roomId);
|
||||||
|
|
||||||
if ($room === null || $room->isClosed() || $room->last_activity_at === null) {
|
if (
|
||||||
|
$room === null
|
||||||
|
|| $room->isClosed()
|
||||||
|
|| $room->is_persistent
|
||||||
|
|| $room->last_activity_at === null
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use Illuminate\Support\Carbon;
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $room_id
|
* @property string $room_id
|
||||||
* @property int|null $user_id
|
* @property int|null $user_id
|
||||||
|
* @property string|null $active_instance_id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property bool $is_moderator
|
* @property bool $is_moderator
|
||||||
* @property Carbon|null $last_seen_at
|
* @property Carbon|null $last_seen_at
|
||||||
@@ -25,6 +26,7 @@ class Player extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'room_id',
|
'room_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
|
'active_instance_id',
|
||||||
'name',
|
'name',
|
||||||
'is_moderator',
|
'is_moderator',
|
||||||
'last_seen_at',
|
'last_seen_at',
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||||||
* @property CarbonImmutable|null $last_activity_at
|
* @property CarbonImmutable|null $last_activity_at
|
||||||
* @property CarbonImmutable|null $closed_at
|
* @property CarbonImmutable|null $closed_at
|
||||||
* @property CarbonImmutable|null $deleted_at
|
* @property CarbonImmutable|null $deleted_at
|
||||||
|
* @property bool $allow_participants_to_manage_rounds
|
||||||
|
* @property bool $is_persistent
|
||||||
* @property int $players_count
|
* @property int $players_count
|
||||||
*/
|
*/
|
||||||
class Room extends Model
|
class Room extends Model
|
||||||
@@ -37,6 +39,13 @@ class Room extends Model
|
|||||||
'state_version',
|
'state_version',
|
||||||
'last_activity_at',
|
'last_activity_at',
|
||||||
'closed_at',
|
'closed_at',
|
||||||
|
'allow_participants_to_manage_rounds',
|
||||||
|
'is_persistent',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'allow_participants_to_manage_rounds' => false,
|
||||||
|
'is_persistent' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
@@ -48,6 +57,8 @@ class Room extends Model
|
|||||||
'last_activity_at' => 'immutable_datetime',
|
'last_activity_at' => 'immutable_datetime',
|
||||||
'closed_at' => 'immutable_datetime',
|
'closed_at' => 'immutable_datetime',
|
||||||
'deck_config' => 'array',
|
'deck_config' => 'array',
|
||||||
|
'allow_participants_to_manage_rounds' => 'boolean',
|
||||||
|
'is_persistent' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ class DashboardRoomService
|
|||||||
{
|
{
|
||||||
$ownedRooms = $user
|
$ownedRooms = $user
|
||||||
->ownedRooms()
|
->ownedRooms()
|
||||||
|
->with([
|
||||||
|
'activePlayers' => fn ($query) => $query
|
||||||
|
->select(['id', 'room_id', 'user_id', 'name', 'is_moderator', 'created_at'])
|
||||||
|
->orderByDesc('is_moderator')
|
||||||
|
->orderBy('created_at'),
|
||||||
|
])
|
||||||
->withCount('players')
|
->withCount('players')
|
||||||
->withCount(['activePlayers as active_player_count'])
|
->withCount(['activePlayers as active_player_count'])
|
||||||
->orderByRaw('closed_at IS NOT NULL')
|
->orderByRaw('closed_at IS NOT NULL')
|
||||||
|
|||||||
@@ -29,15 +29,17 @@ class RoomEmoteService
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rateLimitKey = "room-emote:{$room->id}:{$player->id}";
|
if (! $player->isModerator()) {
|
||||||
|
$rateLimitKey = "room-emote:{$room->id}:{$player->id}";
|
||||||
|
|
||||||
abort_if(
|
abort_if(
|
||||||
RateLimiter::tooManyAttempts($rateLimitKey, 10),
|
RateLimiter::tooManyAttempts($rateLimitKey, 10),
|
||||||
429,
|
429,
|
||||||
'Bitte warte kurz, bevor du erneut wirfst.',
|
'Bitte warte kurz, bevor du erneut wirfst.',
|
||||||
);
|
);
|
||||||
|
|
||||||
RateLimiter::hit($rateLimitKey, 10);
|
RateLimiter::hit($rateLimitKey, 10);
|
||||||
|
}
|
||||||
|
|
||||||
PaperBallThrown::dispatch(
|
PaperBallThrown::dispatch(
|
||||||
Str::uuid()->toString(),
|
Str::uuid()->toString(),
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ use Illuminate\Support\Facades\DB;
|
|||||||
|
|
||||||
class RoomLifecycleService
|
class RoomLifecycleService
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomRealtimeStateService $realtimeState,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{player: Player, was_reopened: bool}
|
* @return array{player: Player, was_reopened: bool}
|
||||||
*/
|
*/
|
||||||
@@ -49,6 +53,7 @@ class RoomLifecycleService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$stateVersion,
|
$stateVersion,
|
||||||
RoomStateChange::RoomReopened,
|
RoomStateChange::RoomReopened,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ use Illuminate\Validation\ValidationException;
|
|||||||
|
|
||||||
class RoomParticipationService
|
class RoomParticipationService
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomRealtimeStateService $realtimeState,
|
||||||
|
) {}
|
||||||
|
|
||||||
public function findByJoinCode(string $joinCode): ?Room
|
public function findByJoinCode(string $joinCode): ?Room
|
||||||
{
|
{
|
||||||
if ($joinCode === '') {
|
if ($joinCode === '') {
|
||||||
@@ -92,8 +96,247 @@ class RoomParticipationService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$room->state_version,
|
$room->state_version,
|
||||||
RoomStateChange::PlayerJoined,
|
RoomStateChange::PlayerJoined,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
|
|
||||||
return [$room, $player];
|
return [$room, $player];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function joinEmbedded(
|
||||||
|
Room $room,
|
||||||
|
?User $user,
|
||||||
|
string $playerName,
|
||||||
|
mixed $sessionPlayerId,
|
||||||
|
): Player {
|
||||||
|
[$player, $change, $stateVersion] = DB::transaction(function () use ($room, $user, $playerName, $sessionPlayerId): array {
|
||||||
|
$lockedRoom = Room::query()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($room->id);
|
||||||
|
|
||||||
|
if ($lockedRoom->isClosed()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'join_code' => 'Dieser Raum ist geschlossen.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = $this->findExistingEmbeddedPlayer(
|
||||||
|
$lockedRoom,
|
||||||
|
$user,
|
||||||
|
$sessionPlayerId,
|
||||||
|
);
|
||||||
|
|
||||||
|
$nameIsTaken = $lockedRoom->players()
|
||||||
|
->where('name', $playerName)
|
||||||
|
->when(
|
||||||
|
$player !== null,
|
||||||
|
fn ($query) => $query->whereKeyNot($player->id),
|
||||||
|
)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($nameIsTaken) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'player_name' => 'Dieser Anzeigename ist in dem Raum bereits vorhanden.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$change = null;
|
||||||
|
|
||||||
|
if ($player === null) {
|
||||||
|
$player = $lockedRoom->players()->create([
|
||||||
|
'user_id' => $user?->id,
|
||||||
|
'name' => $playerName,
|
||||||
|
'is_moderator' => false,
|
||||||
|
'last_seen_at' => now(),
|
||||||
|
]);
|
||||||
|
$change = RoomStateChange::PlayerJoined;
|
||||||
|
} else {
|
||||||
|
if ($player->inactive_at !== null) {
|
||||||
|
$change = RoomStateChange::PlayerJoined;
|
||||||
|
} elseif ($player->name !== $playerName) {
|
||||||
|
$change = RoomStateChange::PlayerUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updates = [
|
||||||
|
'name' => $playerName,
|
||||||
|
'last_seen_at' => now(),
|
||||||
|
'inactive_at' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (
|
||||||
|
$user !== null
|
||||||
|
&& $player->user_id === null
|
||||||
|
&& ! $lockedRoom->players()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->whereKeyNot($player->id)
|
||||||
|
->exists()
|
||||||
|
) {
|
||||||
|
$updates['user_id'] = $user->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player->update($updates);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($change === null) {
|
||||||
|
return [$player, null, null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$lockedRoom->update([
|
||||||
|
'last_activity_at' => now(),
|
||||||
|
'state_version' => $lockedRoom->state_version + 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [$player, $change, $lockedRoom->state_version];
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($change instanceof RoomStateChange && is_int($stateVersion)) {
|
||||||
|
RoomStateChanged::dispatch(
|
||||||
|
$room->id,
|
||||||
|
$stateVersion,
|
||||||
|
$change,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $player;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findExistingEmbeddedPlayer(
|
||||||
|
Room $room,
|
||||||
|
?User $user,
|
||||||
|
mixed $sessionPlayerId,
|
||||||
|
): ?Player {
|
||||||
|
if ($user !== null) {
|
||||||
|
$userPlayer = $room->players()
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->lockForUpdate()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($userPlayer !== null) {
|
||||||
|
return $userPlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($sessionPlayerId)) {
|
||||||
|
$sessionPlayer = $room->players()
|
||||||
|
->whereKey((int) $sessionPlayerId)
|
||||||
|
->lockForUpdate()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($sessionPlayer !== null) {
|
||||||
|
return $sessionPlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function activateInstance(Room $room, Player $player, string $instanceId): Player
|
||||||
|
{
|
||||||
|
[$activePlayer, $replacedInstanceId, $stateVersion] = DB::transaction(function () use ($room, $player, $instanceId): array {
|
||||||
|
$lockedRoom = Room::query()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($room->id);
|
||||||
|
$lockedPlayer = $lockedRoom->players()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($player->id);
|
||||||
|
|
||||||
|
if ($lockedPlayer->active_instance_id === $instanceId) {
|
||||||
|
return [$lockedPlayer, null, null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$replacedInstanceId = $lockedPlayer->active_instance_id;
|
||||||
|
$lockedPlayer->update([
|
||||||
|
'active_instance_id' => $instanceId,
|
||||||
|
'last_seen_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($replacedInstanceId === null) {
|
||||||
|
return [$lockedPlayer, null, null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$lockedRoom->update([
|
||||||
|
'last_activity_at' => now(),
|
||||||
|
'state_version' => $lockedRoom->state_version + 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [$lockedPlayer, $replacedInstanceId, $lockedRoom->state_version];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (is_string($replacedInstanceId) && is_int($stateVersion)) {
|
||||||
|
RoomStateChanged::dispatch(
|
||||||
|
$room->id,
|
||||||
|
$stateVersion,
|
||||||
|
RoomStateChange::PlayerInstanceReplaced,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
|
$activePlayer->id,
|
||||||
|
$replacedInstanceId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $activePlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function kick(
|
||||||
|
Room $room,
|
||||||
|
Player $player,
|
||||||
|
?User $user,
|
||||||
|
?Player $currentPlayer,
|
||||||
|
): void {
|
||||||
|
$stateVersion = DB::transaction(function () use ($room, $player, $user, $currentPlayer): ?int {
|
||||||
|
$lockedRoom = Room::query()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($room->id);
|
||||||
|
|
||||||
|
$lockedCurrentPlayer = $currentPlayer === null
|
||||||
|
? null
|
||||||
|
: $lockedRoom->activePlayers()
|
||||||
|
->lockForUpdate()
|
||||||
|
->find($currentPlayer->id);
|
||||||
|
$isOwner = $user !== null && $lockedRoom->owner_id === $user->id;
|
||||||
|
$participantCanManage = ! $lockedRoom->isClosed()
|
||||||
|
&& $lockedCurrentPlayer !== null
|
||||||
|
&& ($lockedCurrentPlayer->is_moderator
|
||||||
|
|| $lockedRoom->allow_participants_to_manage_rounds);
|
||||||
|
|
||||||
|
abort_unless($isOwner || $participantCanManage, 403);
|
||||||
|
|
||||||
|
$lockedPlayer = $lockedRoom->players()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($player->id);
|
||||||
|
|
||||||
|
abort_if(
|
||||||
|
$lockedPlayer->is_moderator
|
||||||
|
|| ($lockedRoom->owner_id !== null
|
||||||
|
&& $lockedPlayer->user_id === $lockedRoom->owner_id)
|
||||||
|
|| $lockedCurrentPlayer?->id === $lockedPlayer->id,
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($lockedPlayer->inactive_at !== null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lockedPlayer->update([
|
||||||
|
'inactive_at' => now(),
|
||||||
|
]);
|
||||||
|
$lockedRoom->update([
|
||||||
|
'last_activity_at' => now(),
|
||||||
|
'state_version' => $lockedRoom->state_version + 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $lockedRoom->state_version;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($stateVersion === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomStateChanged::dispatch(
|
||||||
|
$room->id,
|
||||||
|
$stateVersion,
|
||||||
|
RoomStateChange::PlayerKicked,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
|
$player->id,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Rooms;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class RoomPlayerInstanceService
|
||||||
|
{
|
||||||
|
private const string SESSION_KEY = 'room_player_instance_id';
|
||||||
|
|
||||||
|
public function for(Request $request): string
|
||||||
|
{
|
||||||
|
$instanceId = $request->session()->get(self::SESSION_KEY);
|
||||||
|
|
||||||
|
if (is_string($instanceId) && Str::isUuid($instanceId)) {
|
||||||
|
return $instanceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$instanceId = (string) Str::uuid();
|
||||||
|
$request->session()->put(self::SESSION_KEY, $instanceId);
|
||||||
|
|
||||||
|
return $instanceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Rooms;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
|
||||||
|
class RoomRealtimeStateService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomStatisticsService $statistics,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* current_round: int,
|
||||||
|
* revealed: bool,
|
||||||
|
* state_version: int,
|
||||||
|
* allow_participants_to_manage_rounds: bool,
|
||||||
|
* statistics: array{average: string|null, median: string|null}|null,
|
||||||
|
* players: array<int, array{
|
||||||
|
* id: int,
|
||||||
|
* name: string,
|
||||||
|
* is_moderator: bool,
|
||||||
|
* is_owner: bool,
|
||||||
|
* has_voted: bool,
|
||||||
|
* vote: string|null
|
||||||
|
* }>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function for(Room $room): array
|
||||||
|
{
|
||||||
|
$room->refresh();
|
||||||
|
$room->load([
|
||||||
|
'players' => fn ($query) => $query
|
||||||
|
->active()
|
||||||
|
->select(['id', 'room_id', 'user_id', 'name', 'is_moderator', 'created_at'])
|
||||||
|
->orderByDesc('is_moderator')
|
||||||
|
->orderBy('created_at'),
|
||||||
|
'players.votes' => fn ($query) => $query
|
||||||
|
->where('room_id', $room->id)
|
||||||
|
->where('round', $room->current_round),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'current_round' => $room->current_round,
|
||||||
|
'revealed' => $room->revealed_at !== null,
|
||||||
|
'state_version' => $room->state_version,
|
||||||
|
'allow_participants_to_manage_rounds' => $room->allow_participants_to_manage_rounds,
|
||||||
|
'statistics' => $this->statistics->currentRound($room),
|
||||||
|
'players' => $room->players
|
||||||
|
->map(function ($player) use ($room): array {
|
||||||
|
$vote = $player->votes->first();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $player->id,
|
||||||
|
'name' => $player->name,
|
||||||
|
'is_moderator' => $player->is_moderator,
|
||||||
|
'is_owner' => $player->user_id === $room->owner_id,
|
||||||
|
'has_voted' => $vote !== null,
|
||||||
|
'vote' => $room->revealed_at !== null ? $vote?->value : null,
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->all(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Rooms;
|
||||||
|
|
||||||
|
use App\Enums\RoomStateChange;
|
||||||
|
use App\Events\RoomStateChanged;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class RoomSettingsService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomRealtimeStateService $realtimeState,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/** @param array{allow_participants_to_manage_rounds: bool, is_persistent: bool} $settings */
|
||||||
|
public function update(Room $room, User $user, array $settings): void
|
||||||
|
{
|
||||||
|
$stateVersion = DB::transaction(function () use ($room, $user, $settings): ?int {
|
||||||
|
$lockedRoom = Room::query()
|
||||||
|
->lockForUpdate()
|
||||||
|
->findOrFail($room->id);
|
||||||
|
|
||||||
|
abort_unless($lockedRoom->owner_id === $user->id, 403);
|
||||||
|
|
||||||
|
$lockedRoom->fill($settings);
|
||||||
|
|
||||||
|
if (! $lockedRoom->isDirty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lockedRoom->state_version++;
|
||||||
|
$lockedRoom->save();
|
||||||
|
|
||||||
|
return $lockedRoom->state_version;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($stateVersion === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomStateChanged::dispatch(
|
||||||
|
$room->id,
|
||||||
|
$stateVersion,
|
||||||
|
RoomStateChange::RoomSettingsUpdated,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,10 @@ use Illuminate\Validation\ValidationException;
|
|||||||
|
|
||||||
class RoundService
|
class RoundService
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomRealtimeStateService $realtimeState,
|
||||||
|
) {}
|
||||||
|
|
||||||
public function reset(Room $room): void
|
public function reset(Room $room): void
|
||||||
{
|
{
|
||||||
$stateVersion = DB::transaction(function () use ($room): int {
|
$stateVersion = DB::transaction(function () use ($room): int {
|
||||||
@@ -38,6 +42,7 @@ class RoundService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$stateVersion,
|
$stateVersion,
|
||||||
RoomStateChange::VotesReset,
|
RoomStateChange::VotesReset,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +74,7 @@ class RoundService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$stateVersion,
|
$stateVersion,
|
||||||
RoomStateChange::CardsRevealed,
|
RoomStateChange::CardsRevealed,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +107,7 @@ class RoundService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$stateVersion,
|
$stateVersion,
|
||||||
RoomStateChange::NextRound,
|
RoomStateChange::NextRound,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ use Illuminate\Validation\ValidationException;
|
|||||||
|
|
||||||
class VoteService
|
class VoteService
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly RoomRealtimeStateService $realtimeState,
|
||||||
|
) {}
|
||||||
|
|
||||||
public function submit(Room $room, Player $player, string $value): void
|
public function submit(Room $room, Player $player, string $value): void
|
||||||
{
|
{
|
||||||
$stateVersion = DB::transaction(function () use ($room, $player, $value): int {
|
$stateVersion = DB::transaction(function () use ($room, $player, $value): int {
|
||||||
@@ -52,6 +56,7 @@ class VoteService
|
|||||||
$room->id,
|
$room->id,
|
||||||
$stateVersion,
|
$stateVersion,
|
||||||
RoomStateChange::VoteChanged,
|
RoomStateChange::VoteChanged,
|
||||||
|
$this->realtimeState->for($room),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('rooms', function (Blueprint $table) {
|
||||||
|
$table->boolean('allow_participants_to_manage_rounds')->default(false);
|
||||||
|
$table->boolean('is_persistent')->default(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('rooms', function (Blueprint $table) {
|
||||||
|
$table->dropColumn([
|
||||||
|
'allow_participants_to_manage_rounds',
|
||||||
|
'is_persistent',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('players', function (Blueprint $table) {
|
||||||
|
$table->uuid('active_instance_id')->nullable()->after('user_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('players', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('active_instance_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -38,6 +38,8 @@ http {
|
|||||||
|
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
include /etc/nginx/fastcgi_params;
|
include /etc/nginx/fastcgi_params;
|
||||||
|
fastcgi_buffer_size 32k;
|
||||||
|
fastcgi_buffers 8 32k;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
fastcgi_param HTTP_PROXY '';
|
fastcgi_param HTTP_PROXY '';
|
||||||
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
|
fastcgi_param HTTP_X_FORWARDED_FOR $http_x_forwarded_for;
|
||||||
|
|||||||
Generated
+4
-3
@@ -4,6 +4,7 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "scrum-poker-internal",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inertiajs/vite": "^3.0.0",
|
"@inertiajs/vite": "^3.0.0",
|
||||||
"@inertiajs/vue3": "^3.0.0",
|
"@inertiajs/vue3": "^3.0.0",
|
||||||
@@ -4959,9 +4960,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/js-yaml": {
|
"node_modules/js-yaml": {
|
||||||
"version": "4.3.1",
|
"version": "4.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
|
||||||
"integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==",
|
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -9,8 +9,8 @@ const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
|||||||
createInertiaApp({
|
createInertiaApp({
|
||||||
title: (title) => (title ? `${title} - ${appName}` : appName),
|
title: (title) => (title ? `${title} - ${appName}` : appName),
|
||||||
|
|
||||||
layout: () => {
|
layout: (name) => {
|
||||||
return PublicLayout;
|
return name.startsWith('embedded/') ? null : PublicLayout;
|
||||||
},
|
},
|
||||||
|
|
||||||
progress: {
|
progress: {
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Link, useForm } from '@inertiajs/vue3';
|
import { Link, useForm } from '@inertiajs/vue3';
|
||||||
import { DoorOpen, Plus, Trash2 } from '@lucide/vue';
|
import {
|
||||||
|
DoorOpen,
|
||||||
|
Plus,
|
||||||
|
Settings as SettingsIcon,
|
||||||
|
Trash2,
|
||||||
|
UserMinus,
|
||||||
|
} from '@lucide/vue';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import DashboardRoomCard from '@/components/dashboard/DashboardRoomCard.vue';
|
import DashboardRoomCard from '@/components/dashboard/DashboardRoomCard.vue';
|
||||||
@@ -13,12 +19,23 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
import { create, destroy, reopen, show } from '@/routes/room';
|
import { create, destroy, reopen, show } from '@/routes/room';
|
||||||
import type { DashboardRoom, OwnedRoomListProps } from '@/types/dashboard';
|
import { destroy as kickRoomPlayer } from '@/routes/room/player';
|
||||||
|
import { edit as roomSettings } from '@/routes/room/settings';
|
||||||
|
import type {
|
||||||
|
DashboardRoom,
|
||||||
|
DashboardRoomPlayer,
|
||||||
|
OwnedRoomListProps,
|
||||||
|
} from '@/types/dashboard';
|
||||||
|
|
||||||
defineProps<OwnedRoomListProps>();
|
defineProps<OwnedRoomListProps>();
|
||||||
|
|
||||||
const selectedRoom = ref<DashboardRoom | null>(null);
|
const selectedRoom = ref<DashboardRoom | null>(null);
|
||||||
|
const selectedPlayer = ref<{
|
||||||
|
room: DashboardRoom;
|
||||||
|
player: DashboardRoomPlayer;
|
||||||
|
} | null>(null);
|
||||||
const deleteForm = useForm({});
|
const deleteForm = useForm({});
|
||||||
|
const kickForm = useForm({});
|
||||||
|
|
||||||
function setDeleteDialogOpen(open: boolean): void {
|
function setDeleteDialogOpen(open: boolean): void {
|
||||||
if (!open && !deleteForm.processing) {
|
if (!open && !deleteForm.processing) {
|
||||||
@@ -26,6 +43,12 @@ function setDeleteDialogOpen(open: boolean): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setKickDialogOpen(open: boolean): void {
|
||||||
|
if (!open && !kickForm.processing) {
|
||||||
|
selectedPlayer.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function deleteRoom(): void {
|
function deleteRoom(): void {
|
||||||
if (selectedRoom.value === null || deleteForm.processing) {
|
if (selectedRoom.value === null || deleteForm.processing) {
|
||||||
return;
|
return;
|
||||||
@@ -38,6 +61,25 @@ function deleteRoom(): void {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function kickPlayer(): void {
|
||||||
|
if (selectedPlayer.value === null || kickForm.processing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
kickForm.delete(
|
||||||
|
kickRoomPlayer({
|
||||||
|
room: selectedPlayer.value.room.id,
|
||||||
|
player: selectedPlayer.value.player.id,
|
||||||
|
}).url,
|
||||||
|
{
|
||||||
|
preserveScroll: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
selectedPlayer.value = null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -91,6 +133,14 @@ function deleteRoom(): void {
|
|||||||
Raum öffnen
|
Raum öffnen
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
<Link
|
||||||
|
:href="roomSettings(room.id)"
|
||||||
|
class="inline-flex items-center gap-2 rounded-md px-3 py-2 text-sm font-semibold transition hover:bg-slate-700"
|
||||||
|
>
|
||||||
|
<SettingsIcon class="size-4" />
|
||||||
|
Einstellungen
|
||||||
|
</Link>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex items-center gap-2 rounded-md px-3 py-2 text-sm font-semibold text-rose-300 transition hover:bg-rose-500/80"
|
class="inline-flex items-center gap-2 rounded-md px-3 py-2 text-sm font-semibold text-rose-300 transition hover:bg-rose-500/80"
|
||||||
@@ -99,6 +149,56 @@ function deleteRoom(): void {
|
|||||||
<Trash2 class="size-4" />
|
<Trash2 class="size-4" />
|
||||||
Raum löschen
|
Raum löschen
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="mt-2 w-full rounded-md border border-slate-700 bg-slate-900/40 p-3"
|
||||||
|
>
|
||||||
|
<h3 class="text-sm font-semibold">Teilnehmer</h3>
|
||||||
|
|
||||||
|
<ul
|
||||||
|
v-if="room.players.length > 0"
|
||||||
|
class="mt-2 flex flex-col gap-2"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
v-for="player in room.players"
|
||||||
|
:key="player.id"
|
||||||
|
class="flex items-center justify-between gap-3 rounded-md bg-slate-800 px-3 py-2"
|
||||||
|
>
|
||||||
|
<span class="min-w-0">
|
||||||
|
<span
|
||||||
|
class="block truncate text-sm"
|
||||||
|
:class="
|
||||||
|
player.is_moderator
|
||||||
|
? 'text-amber-300'
|
||||||
|
: 'text-slate-100'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ player.name }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="player.is_owner"
|
||||||
|
class="shrink-0 text-xs text-slate-400"
|
||||||
|
>
|
||||||
|
Du
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-semibold text-rose-300 transition hover:bg-rose-500/20 hover:text-rose-200"
|
||||||
|
@click="selectedPlayer = { room, player }"
|
||||||
|
>
|
||||||
|
<UserMinus class="size-3.5" />
|
||||||
|
Kicken
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p v-else class="mt-2 text-sm text-slate-400">
|
||||||
|
Aktuell sind keine Teilnehmer im Raum.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</DashboardRoomCard>
|
</DashboardRoomCard>
|
||||||
</div>
|
</div>
|
||||||
@@ -164,5 +264,42 @@ function deleteRoom(): void {
|
|||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
:open="selectedPlayer !== null"
|
||||||
|
@update:open="setKickDialogOpen"
|
||||||
|
>
|
||||||
|
<DialogContent
|
||||||
|
class="border-slate-700 bg-slate-800 text-slate-100 sm:max-w-md"
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Teilnehmer wirklich kicken?</DialogTitle>
|
||||||
|
<DialogDescription class="text-slate-300">
|
||||||
|
{{ selectedPlayer?.player.name }} wird aus „{{
|
||||||
|
selectedPlayer?.room.title ?? 'Scrum Poker'
|
||||||
|
}}“ entfernt und zur Startseite weitergeleitet.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogFooter class="gap-6 space-x-4 sm:gap-0">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border border-slate-600 px-4 py-2 text-sm font-semibold text-slate-200 transition hover:bg-slate-700"
|
||||||
|
:disabled="kickForm.processing"
|
||||||
|
@click="selectedPlayer = null"
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md bg-rose-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-rose-500 disabled:opacity-50"
|
||||||
|
:disabled="kickForm.processing"
|
||||||
|
@click="kickPlayer"
|
||||||
|
>
|
||||||
|
{{ kickForm.processing ? 'Wird entfernt …' : 'Kicken' }}
|
||||||
|
</button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Head, usePage } from '@inertiajs/vue3';
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import RoomHeader from '@/components/rooms/RoomHeader.vue';
|
||||||
|
import RoomRetentionNotice from '@/components/rooms/RoomRetentionNotice.vue';
|
||||||
|
import RoomTable from '@/components/rooms/RoomTable.vue';
|
||||||
|
import RoomVoteDeck from '@/components/rooms/RoomVoteDeck.vue';
|
||||||
|
import { useRoomRealtime } from '@/composables/useRoomRealtime';
|
||||||
|
import type { RoomExperienceProps } from '@/types/room';
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<RoomExperienceProps>(), {
|
||||||
|
embedded: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const page = usePage();
|
||||||
|
const presenterMode = ref(false);
|
||||||
|
const roomNotice = computed(() => page.props.roomNotice);
|
||||||
|
const isAuthenticated = computed(() => page.props.auth.user !== null);
|
||||||
|
const embeddedBackgroundColor = computed(() => {
|
||||||
|
if (!props.embedded) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const backgroundColor = new URL(
|
||||||
|
page.url,
|
||||||
|
'https://embedded.invalid',
|
||||||
|
).searchParams.get('background_color');
|
||||||
|
|
||||||
|
return backgroundColor && /^#[0-9a-f]{6}$/i.test(backgroundColor)
|
||||||
|
? backgroundColor
|
||||||
|
: undefined;
|
||||||
|
});
|
||||||
|
const canFavorite = computed(
|
||||||
|
() => !props.embedded && page.props.auth.user?.id != props.room.owner_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
room: realtimeRoom,
|
||||||
|
currentPlayer: realtimeCurrentPlayer,
|
||||||
|
setCurrentVote,
|
||||||
|
} = useRoomRealtime(
|
||||||
|
() => props.room,
|
||||||
|
() => props.currentPlayer,
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Head :title="realtimeRoom.title ?? 'Scrum Poker'" />
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="min-h-svh bg-slate-900 px-3 py-6 text-white sm:px-6 md:flex md:min-h-0 md:flex-col md:overflow-hidden lg:px-10"
|
||||||
|
:style="
|
||||||
|
embeddedBackgroundColor
|
||||||
|
? { backgroundColor: embeddedBackgroundColor }
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
:class="
|
||||||
|
embedded
|
||||||
|
? 'md:h-dvh'
|
||||||
|
: '-m-6 min-h-[calc(100svh-4rem)] md:h-[calc(100dvh-4rem-1px)]'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<RoomRetentionNotice v-if="roomNotice" :notice="roomNotice" />
|
||||||
|
|
||||||
|
<RoomHeader
|
||||||
|
:id="realtimeRoom.id"
|
||||||
|
:title="realtimeRoom.title"
|
||||||
|
:join_code="realtimeRoom.join_code"
|
||||||
|
:is_favorite="realtimeRoom.is_favorite"
|
||||||
|
:players="realtimeRoom.players"
|
||||||
|
:can-favorite="canFavorite"
|
||||||
|
:can-manage-participants="
|
||||||
|
realtimeCurrentPlayer.is_moderator ||
|
||||||
|
realtimeRoom.allow_participants_to_manage_rounds
|
||||||
|
"
|
||||||
|
:current-player-id="realtimeCurrentPlayer.id"
|
||||||
|
:can-logout="embedded && isAuthenticated"
|
||||||
|
:player-name="realtimeCurrentPlayer.name"
|
||||||
|
v-model:presenter-mode="presenterMode"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<RoomTable
|
||||||
|
:room="realtimeRoom"
|
||||||
|
:current-player="realtimeCurrentPlayer"
|
||||||
|
:presenter-mode="presenterMode"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<RoomVoteDeck
|
||||||
|
:room-id="realtimeRoom.id"
|
||||||
|
:revealed="realtimeRoom.revealed"
|
||||||
|
:cards="realtimeRoom.deck.cards"
|
||||||
|
:current-vote="realtimeCurrentPlayer.current_vote"
|
||||||
|
:presenter-mode="presenterMode"
|
||||||
|
@vote-changed="setCurrentVote"
|
||||||
|
/>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@@ -1,16 +1,65 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Link } from '@inertiajs/vue3';
|
import { Link, useForm } from '@inertiajs/vue3';
|
||||||
import { Check, Copy } from '@lucide/vue';
|
import { Check, Copy, LogOut, Settings, UserMinus, Users } from '@lucide/vue';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from '@/components/ui/dropdown-menu';
|
||||||
|
import { logout as embeddedLogout } from '@/routes/embedded';
|
||||||
import { favorite } from '@/routes/room';
|
import { favorite } from '@/routes/room';
|
||||||
import type { RoomHeaderEmits, RoomHeaderProps } from '@/types/room';
|
import { destroy as kickRoomPlayer } from '@/routes/room/player';
|
||||||
|
import type {
|
||||||
|
RoomHeaderEmits,
|
||||||
|
RoomHeaderProps,
|
||||||
|
RoomPlayer,
|
||||||
|
} from '@/types/room';
|
||||||
|
|
||||||
const props = defineProps<RoomHeaderProps>();
|
const props = defineProps<RoomHeaderProps>();
|
||||||
const emit = defineEmits<RoomHeaderEmits>();
|
const emit = defineEmits<RoomHeaderEmits>();
|
||||||
|
|
||||||
const copied = ref(false);
|
const copied = ref(false);
|
||||||
|
const participantsDialogOpen = ref(false);
|
||||||
|
const selectedPlayer = ref<RoomPlayer | null>(null);
|
||||||
|
const kickForm = useForm({});
|
||||||
|
|
||||||
|
function kickPlayer(): void {
|
||||||
|
if (selectedPlayer.value === null || kickForm.processing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
kickForm.delete(
|
||||||
|
kickRoomPlayer({
|
||||||
|
room: props.id,
|
||||||
|
player: selectedPlayer.value.id,
|
||||||
|
}).url,
|
||||||
|
{
|
||||||
|
preserveScroll: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
selectedPlayer.value = null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setKickDialogOpen(open: boolean): void {
|
||||||
|
if (!open && !kickForm.processing) {
|
||||||
|
selectedPlayer.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function copyInviteLink(): Promise<void> {
|
async function copyInviteLink(): Promise<void> {
|
||||||
const inviteUrl = new URL('/room/join', window.location.origin);
|
const inviteUrl = new URL('/room/join', window.location.origin);
|
||||||
@@ -25,61 +74,225 @@ async function copyInviteLink(): Promise<void> {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header
|
<div class="contents">
|
||||||
class="mx-auto flex w-full max-w-6xl flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"
|
<header
|
||||||
>
|
class="mx-auto flex w-full max-w-6xl flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"
|
||||||
<div>
|
>
|
||||||
<h1 class="text-2xl font-bold sm:text-3xl">
|
<div>
|
||||||
{{ title ?? 'Scrum Poker' }}
|
<h1 class="text-2xl font-bold sm:text-3xl">
|
||||||
</h1>
|
{{ title ?? 'Scrum Poker' }}
|
||||||
|
</h1>
|
||||||
|
|
||||||
<Link
|
<Link
|
||||||
v-if="canFavorite"
|
v-if="canFavorite"
|
||||||
:href="favorite(id)"
|
:href="favorite(id)"
|
||||||
method="post"
|
method="post"
|
||||||
as="button"
|
as="button"
|
||||||
class="mt-2 inline-flex items-center gap-2"
|
class="mt-2 inline-flex items-center gap-2"
|
||||||
>
|
>
|
||||||
<span>Favorit</span>
|
<span>Favorit</span>
|
||||||
<span class="material-icons" aria-hidden="true">
|
<span class="material-icons" aria-hidden="true">
|
||||||
{{ is_favorite ? 'favorite' : 'favorite_border' }}
|
{{ is_favorite ? 'favorite' : 'favorite_border' }}
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col items-end gap-2">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="flex w-fit items-center gap-3 rounded-xl border border-slate-700 bg-slate-800 px-4 py-2.5 text-left transition hover:bg-slate-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-cyan-300"
|
|
||||||
@click="copyInviteLink"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
<span
|
|
||||||
class="block text-sm tracking-[0.18em] text-slate-400"
|
|
||||||
>
|
|
||||||
Raumcode
|
|
||||||
</span>
|
</span>
|
||||||
<strong class="font-mono text-lg tracking-[0.2em]">
|
</Link>
|
||||||
{{ join_code }}
|
</div>
|
||||||
</strong>
|
|
||||||
</span>
|
|
||||||
<Check v-if="copied" class="size-5 text-emerald-300" />
|
|
||||||
<Copy v-else class="size-5 text-slate-300" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<label
|
<div class="flex flex-col items-end gap-2">
|
||||||
for="presenter-mode"
|
<Link
|
||||||
class="flex cursor-pointer items-center gap-2 text-sm text-slate-300"
|
v-if="canLogout"
|
||||||
>
|
:href="
|
||||||
<Checkbox
|
embeddedLogout({
|
||||||
id="presenter-mode"
|
query: {
|
||||||
:model-value="presenterMode"
|
join_code,
|
||||||
@update:model-value="
|
player_name: playerName,
|
||||||
emit('update:presenterMode', $event === true)
|
},
|
||||||
|
})
|
||||||
"
|
"
|
||||||
/>
|
method="post"
|
||||||
<span>Präsentatormodus</span>
|
as="button"
|
||||||
</label>
|
class="inline-flex items-center gap-2 text-sm text-slate-300 transition hover:text-white"
|
||||||
</div>
|
>
|
||||||
</header>
|
<LogOut class="size-4" />
|
||||||
|
Abmelden
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<DropdownMenu v-if="canManageParticipants">
|
||||||
|
<DropdownMenuTrigger :as-child="true">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex size-11 items-center justify-center rounded-xl border border-slate-700 bg-slate-800 text-slate-300 transition hover:bg-slate-700 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-cyan-300"
|
||||||
|
aria-label="Raumeinstellungen öffnen"
|
||||||
|
>
|
||||||
|
<Settings class="size-5" />
|
||||||
|
</button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent
|
||||||
|
align="end"
|
||||||
|
class="w-52 border-slate-700 bg-slate-800 text-slate-100"
|
||||||
|
>
|
||||||
|
<DropdownMenuLabel class="text-slate-400">
|
||||||
|
Einstellungen
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuItem
|
||||||
|
class="focus:bg-slate-700 focus:text-white"
|
||||||
|
@select="participantsDialogOpen = true"
|
||||||
|
>
|
||||||
|
<Users class="size-4" />
|
||||||
|
Teilnehmer
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-3 rounded-xl border border-slate-700 bg-slate-800 px-4 py-2.5 text-left transition hover:bg-slate-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-cyan-300"
|
||||||
|
@click="copyInviteLink"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<span
|
||||||
|
class="block text-sm tracking-[0.18em] text-slate-400"
|
||||||
|
>
|
||||||
|
Raumcode
|
||||||
|
</span>
|
||||||
|
<strong class="font-mono text-lg tracking-[0.2em]">
|
||||||
|
{{ join_code }}
|
||||||
|
</strong>
|
||||||
|
</span>
|
||||||
|
<Check v-if="copied" class="size-5 text-emerald-300" />
|
||||||
|
<Copy v-else class="size-5 text-slate-300" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label
|
||||||
|
for="presenter-mode"
|
||||||
|
class="flex cursor-pointer items-center gap-2 text-sm text-slate-300"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id="presenter-mode"
|
||||||
|
:model-value="presenterMode"
|
||||||
|
@update:model-value="
|
||||||
|
emit('update:presenterMode', $event === true)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<span>Präsentatormodus</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<Dialog v-model:open="participantsDialogOpen">
|
||||||
|
<DialogContent
|
||||||
|
class="max-h-[calc(100dvh-2rem)] overflow-hidden border-slate-700 bg-slate-800 text-slate-100 sm:max-w-xl"
|
||||||
|
overlay-class="bg-black/70 backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Teilnehmer</DialogTitle>
|
||||||
|
<DialogDescription class="text-slate-300">
|
||||||
|
Verwalte die aktiven Teilnehmer in diesem Raum.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<ul
|
||||||
|
v-if="players.length > 0"
|
||||||
|
class="flex max-h-[min(60dvh,32rem)] flex-col gap-2 overflow-y-auto pr-1"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
v-for="player in players"
|
||||||
|
:key="player.id"
|
||||||
|
class="flex items-center justify-between gap-3 rounded-md bg-slate-900/60 px-3 py-2"
|
||||||
|
>
|
||||||
|
<span class="min-w-0">
|
||||||
|
<span
|
||||||
|
class="block truncate text-sm"
|
||||||
|
:class="
|
||||||
|
player.is_moderator
|
||||||
|
? 'text-amber-300'
|
||||||
|
: 'text-slate-100'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ player.name }}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="
|
||||||
|
player.id === currentPlayerId ||
|
||||||
|
player.is_moderator
|
||||||
|
"
|
||||||
|
class="shrink-0 text-xs text-slate-400"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
player.id === currentPlayerId
|
||||||
|
? player.is_moderator
|
||||||
|
? 'Du · Admin'
|
||||||
|
: 'Du'
|
||||||
|
: 'Admin'
|
||||||
|
}}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-semibold text-rose-300 transition hover:bg-rose-500/20 hover:text-rose-200"
|
||||||
|
@click="selectedPlayer = player"
|
||||||
|
>
|
||||||
|
<UserMinus class="size-3.5" />
|
||||||
|
Kicken
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p v-else class="text-sm text-slate-400">
|
||||||
|
Aktuell sind keine Teilnehmer im Raum.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border border-slate-600 px-4 py-2 text-sm font-semibold text-slate-200 transition hover:bg-slate-700"
|
||||||
|
@click="participantsDialogOpen = false"
|
||||||
|
>
|
||||||
|
Schließen
|
||||||
|
</button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
:open="selectedPlayer !== null"
|
||||||
|
@update:open="setKickDialogOpen"
|
||||||
|
>
|
||||||
|
<DialogContent
|
||||||
|
class="border-slate-700 bg-slate-800 text-slate-100 sm:max-w-md"
|
||||||
|
overlay-class="bg-black/70 backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Teilnehmer wirklich kicken?</DialogTitle>
|
||||||
|
<DialogDescription class="text-slate-300">
|
||||||
|
{{ selectedPlayer?.name }} wird aus „{{
|
||||||
|
title ?? 'Scrum Poker'
|
||||||
|
}}“ entfernt und zur Startseite weitergeleitet.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogFooter class="gap-6 space-x-4 sm:gap-0">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md border border-slate-600 px-4 py-2 text-sm font-semibold text-slate-200 transition hover:bg-slate-700"
|
||||||
|
:disabled="kickForm.processing"
|
||||||
|
@click="selectedPlayer = null"
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-md bg-rose-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-rose-500 disabled:opacity-50"
|
||||||
|
:disabled="kickForm.processing"
|
||||||
|
@click="kickPlayer"
|
||||||
|
>
|
||||||
|
{{ kickForm.processing ? 'Wird entfernt …' : 'Kicken' }}
|
||||||
|
</button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useForm } from '@inertiajs/vue3';
|
import { useHttp } from '@inertiajs/vue3';
|
||||||
import { Eye, RotateCcw, Trash2 } from '@lucide/vue';
|
import { Eye, RotateCcw, Trash2 } from '@lucide/vue';
|
||||||
|
|
||||||
import { nextRound, reset as resetRound, reveal } from '@/routes/room';
|
import { nextRound, reset as resetRound, reveal } from '@/routes/room';
|
||||||
@@ -7,26 +7,29 @@ import type { RoomModeratorControlsProps } from '@/types/room';
|
|||||||
|
|
||||||
const props = defineProps<RoomModeratorControlsProps>();
|
const props = defineProps<RoomModeratorControlsProps>();
|
||||||
|
|
||||||
const revealForm = useForm<{ room?: string }>({});
|
const revealRequest = useHttp<{ room?: string }>(
|
||||||
const nextRoundForm = useForm<{ room?: string }>({});
|
() => reveal(props.roomId),
|
||||||
const resetForm = useForm<{ room?: string }>({});
|
{},
|
||||||
|
);
|
||||||
|
const nextRoundRequest = useHttp<{ room?: string }>(
|
||||||
|
() => nextRound(props.roomId),
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
const resetRequest = useHttp<{ room?: string }>(
|
||||||
|
() => resetRound(props.roomId),
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
function revealCards(): void {
|
function revealCards(): void {
|
||||||
revealForm.submit(reveal(props.roomId), {
|
void revealRequest.submit();
|
||||||
preserveScroll: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function startNextRound(): void {
|
function startNextRound(): void {
|
||||||
nextRoundForm.submit(nextRound(props.roomId), {
|
void nextRoundRequest.submit();
|
||||||
preserveScroll: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetVotes(): void {
|
function resetVotes(): void {
|
||||||
resetForm.submit(resetRound(props.roomId), {
|
void resetRequest.submit();
|
||||||
preserveScroll: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -35,7 +38,7 @@ function resetVotes(): void {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex items-center gap-2 rounded-xl border border-slate-600 bg-slate-800 px-4 py-2.5 font-semibold text-slate-200 transition hover:bg-slate-700 disabled:cursor-not-allowed disabled:opacity-40"
|
class="inline-flex items-center gap-2 rounded-xl border border-slate-600 bg-slate-800 px-4 py-2.5 font-semibold text-slate-200 transition hover:bg-slate-700 disabled:cursor-not-allowed disabled:opacity-40"
|
||||||
:disabled="resetForm.processing || !hasVotes"
|
:disabled="resetRequest.processing || !hasVotes"
|
||||||
@click="resetVotes"
|
@click="resetVotes"
|
||||||
>
|
>
|
||||||
<Trash2 class="size-4" />
|
<Trash2 class="size-4" />
|
||||||
@@ -45,18 +48,18 @@ function resetVotes(): void {
|
|||||||
|
|
||||||
<div class="moderator-controls">
|
<div class="moderator-controls">
|
||||||
<p
|
<p
|
||||||
v-if="revealForm.errors.room || nextRoundForm.errors.room"
|
v-if="revealRequest.errors.room || nextRoundRequest.errors.room"
|
||||||
class="max-w-64 rounded-lg bg-rose-950/90 px-3 py-2 text-right text-sm text-rose-200 shadow-lg"
|
class="max-w-64 rounded-lg bg-rose-950/90 px-3 py-2 text-right text-sm text-rose-200 shadow-lg"
|
||||||
role="alert"
|
role="alert"
|
||||||
>
|
>
|
||||||
{{ revealForm.errors.room ?? nextRoundForm.errors.room }}
|
{{ revealRequest.errors.room ?? nextRoundRequest.errors.room }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-if="!revealed"
|
v-if="!revealed"
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex items-center gap-2 rounded-xl border border-slate-300 bg-slate-100 px-5 py-2.5 font-semibold text-slate-900 transition hover:bg-white disabled:opacity-50"
|
class="inline-flex items-center gap-2 rounded-xl border border-slate-300 bg-slate-100 px-5 py-2.5 font-semibold text-slate-900 transition hover:bg-white disabled:opacity-50"
|
||||||
:disabled="revealForm.processing"
|
:disabled="revealRequest.processing"
|
||||||
@click="revealCards"
|
@click="revealCards"
|
||||||
>
|
>
|
||||||
<Eye class="size-4" />
|
<Eye class="size-4" />
|
||||||
@@ -67,7 +70,7 @@ function resetVotes(): void {
|
|||||||
v-else
|
v-else
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex items-center gap-2 rounded-xl border border-slate-300 bg-slate-100 px-5 py-2.5 font-semibold text-slate-900 transition hover:bg-white disabled:opacity-50"
|
class="inline-flex items-center gap-2 rounded-xl border border-slate-300 bg-slate-100 px-5 py-2.5 font-semibold text-slate-900 transition hover:bg-white disabled:opacity-50"
|
||||||
:disabled="nextRoundForm.processing"
|
:disabled="nextRoundRequest.processing"
|
||||||
@click="startNextRound"
|
@click="startNextRound"
|
||||||
>
|
>
|
||||||
<RotateCcw class="size-4" />
|
<RotateCcw class="size-4" />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { CircleUserRound, Crown } from '@lucide/vue';
|
import { CircleUserRound } from '@lucide/vue';
|
||||||
|
|
||||||
import type { RoomSeatProps } from '@/types/room';
|
import type { RoomSeatProps } from '@/types/room';
|
||||||
|
|
||||||
@@ -75,22 +75,18 @@ function playerVote(): string | null {
|
|||||||
:class="{ 'player-details-above': player.isTopSeat }"
|
:class="{ 'player-details-above': player.isTopSeat }"
|
||||||
>
|
>
|
||||||
<p
|
<p
|
||||||
class="player-name max-w-32 text-center text-sm leading-tight font-semibold text-slate-100"
|
class="player-name max-w-32 text-center text-sm leading-tight font-semibold"
|
||||||
|
:class="
|
||||||
|
player.is_moderator ? 'text-amber-300' : 'text-slate-100'
|
||||||
|
"
|
||||||
>
|
>
|
||||||
{{ player.name }}
|
{{ player.name }}
|
||||||
</p>
|
</p>
|
||||||
<div
|
<div
|
||||||
v-if="player.is_moderator || isCurrentPlayer()"
|
v-if="isCurrentPlayer()"
|
||||||
class="flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[11px]"
|
class="flex flex-wrap items-center justify-center gap-x-2 gap-y-0.5 text-[11px]"
|
||||||
>
|
>
|
||||||
<span
|
<span class="text-cyan-300">Du</span>
|
||||||
v-if="player.is_moderator"
|
|
||||||
class="inline-flex items-center gap-1 text-amber-300"
|
|
||||||
>
|
|
||||||
<Crown class="size-3 fill-amber-300" aria-hidden="true" />
|
|
||||||
Moderator
|
|
||||||
</span>
|
|
||||||
<span v-if="isCurrentPlayer()" class="text-cyan-300">Du</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const { activePaperBalls, hitPlayerIds, throwingAtPlayerId, throwPaperBall } =
|
|||||||
usePaperBallToss({
|
usePaperBallToss({
|
||||||
roomId: () => props.room.id,
|
roomId: () => props.room.id,
|
||||||
currentPlayerId: () => props.currentPlayer.id,
|
currentPlayerId: () => props.currentPlayer.id,
|
||||||
|
currentPlayerIsModerator: () => props.currentPlayer.is_moderator,
|
||||||
board: gameBoard,
|
board: gameBoard,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,12 +116,17 @@ const voteCount = computed(
|
|||||||
:revealed="room.revealed"
|
:revealed="room.revealed"
|
||||||
:presenter-mode="presenterMode"
|
:presenter-mode="presenterMode"
|
||||||
:is-paper-ball-hit="hitPlayerIds.includes(player.id)"
|
:is-paper-ball-hit="hitPlayerIds.includes(player.id)"
|
||||||
:throw-disabled="throwingAtPlayerId !== null"
|
:throw-disabled="
|
||||||
|
!currentPlayer.is_moderator && throwingAtPlayerId !== null
|
||||||
|
"
|
||||||
@throw-paper-ball="throwPaperBall"
|
@throw-paper-ball="throwPaperBall"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RoomModeratorControls
|
<RoomModeratorControls
|
||||||
v-if="currentPlayer.is_moderator"
|
v-if="
|
||||||
|
currentPlayer.is_moderator ||
|
||||||
|
room.allow_participants_to_manage_rounds
|
||||||
|
"
|
||||||
:room-id="room.id"
|
:room-id="room.id"
|
||||||
:revealed="room.revealed"
|
:revealed="room.revealed"
|
||||||
:has-votes="voteCount > 0"
|
:has-votes="voteCount > 0"
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useForm } from '@inertiajs/vue3';
|
import { useHttp } from '@inertiajs/vue3';
|
||||||
import { Keyboard } from '@lucide/vue';
|
import { Keyboard } from '@lucide/vue';
|
||||||
import { useEventListener } from '@vueuse/core';
|
import { useEventListener } from '@vueuse/core';
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
|
||||||
import { store as storeVote } from '@/routes/room/vote';
|
import { store as storeVote } from '@/routes/room/vote';
|
||||||
import type { RoomVoteDeckProps } from '@/types/room';
|
import type { RoomVoteDeckEmits, RoomVoteDeckProps } from '@/types/room';
|
||||||
|
|
||||||
const props = defineProps<RoomVoteDeckProps>();
|
const props = defineProps<RoomVoteDeckProps>();
|
||||||
|
const emit = defineEmits<RoomVoteDeckEmits>();
|
||||||
|
|
||||||
const cardShortcuts = [
|
const cardShortcuts = [
|
||||||
'1',
|
'1',
|
||||||
@@ -25,29 +26,32 @@ const cardShortcuts = [
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
const voteForm = useForm({
|
const voteRequest = useHttp(() => storeVote(props.roomId), {
|
||||||
value: props.currentVote ?? '',
|
value: props.currentVote ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.currentVote,
|
() => props.currentVote,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (!voteForm.processing) {
|
if (!voteRequest.processing) {
|
||||||
voteForm.value = value ?? '';
|
voteRequest.value = value ?? '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function submitVote(value: string): void {
|
function submitVote(value: string): void {
|
||||||
if (props.revealed || voteForm.processing) {
|
if (props.revealed || voteRequest.processing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
voteForm.value = value;
|
const previousVote = props.currentVote;
|
||||||
voteForm.submit(storeVote(props.roomId), {
|
|
||||||
preserveScroll: true,
|
voteRequest.value = value;
|
||||||
|
emit('vote-changed', value);
|
||||||
|
void voteRequest.submit({
|
||||||
onError: () => {
|
onError: () => {
|
||||||
voteForm.value = props.currentVote ?? '';
|
voteRequest.value = previousVote ?? '';
|
||||||
|
emit('vote-changed', previousVote);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -71,7 +75,7 @@ function handleKeyboardVote(event: KeyboardEvent): void {
|
|||||||
if (
|
if (
|
||||||
!props.presenterMode ||
|
!props.presenterMode ||
|
||||||
props.revealed ||
|
props.revealed ||
|
||||||
voteForm.processing ||
|
voteRequest.processing ||
|
||||||
event.repeat ||
|
event.repeat ||
|
||||||
event.altKey ||
|
event.altKey ||
|
||||||
event.ctrlKey ||
|
event.ctrlKey ||
|
||||||
@@ -118,10 +122,10 @@ useEventListener('keydown', handleKeyboardVote);
|
|||||||
class="deck-card"
|
class="deck-card"
|
||||||
:class="{
|
:class="{
|
||||||
'is-selected':
|
'is-selected':
|
||||||
!presenterMode && voteForm.value === card.key,
|
!presenterMode && voteRequest.value === card.key,
|
||||||
}"
|
}"
|
||||||
:disabled="voteForm.processing"
|
:disabled="voteRequest.processing"
|
||||||
:aria-pressed="voteForm.value === card.key"
|
:aria-pressed="voteRequest.value === card.key"
|
||||||
:aria-label="`Karte ${card.label} wählen`"
|
:aria-label="`Karte ${card.label} wählen`"
|
||||||
@click="submitVote(card.key)"
|
@click="submitVote(card.key)"
|
||||||
>
|
>
|
||||||
@@ -138,11 +142,11 @@ useEventListener('keydown', handleKeyboardVote);
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p
|
<p
|
||||||
v-if="voteForm.errors.value"
|
v-if="voteRequest.errors.value"
|
||||||
class="mt-3 text-sm text-rose-300"
|
class="mt-3 text-sm text-rose-300"
|
||||||
role="alert"
|
role="alert"
|
||||||
>
|
>
|
||||||
{{ voteForm.errors.value }}
|
{{ voteRequest.errors.value }}
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -16,19 +16,26 @@ defineOptions({
|
|||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const props = withDefaults(defineProps<DialogContentProps & { class?: HTMLAttributes["class"], showCloseButton?: boolean }>(), {
|
const props = withDefaults(
|
||||||
showCloseButton: true,
|
defineProps<DialogContentProps & {
|
||||||
})
|
class?: HTMLAttributes["class"]
|
||||||
|
overlayClass?: HTMLAttributes["class"]
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
showCloseButton: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
const emits = defineEmits<DialogContentEmits>()
|
const emits = defineEmits<DialogContentEmits>()
|
||||||
|
|
||||||
const delegatedProps = reactiveOmit(props, "class")
|
const delegatedProps = reactiveOmit(props, "class", "overlayClass", "showCloseButton")
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(delegatedProps, emits)
|
const forwarded = useForwardPropsEmits(delegatedProps, emits)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DialogPortal>
|
<DialogPortal>
|
||||||
<DialogOverlay />
|
<DialogOverlay :class="props.overlayClass" />
|
||||||
<DialogContent
|
<DialogContent
|
||||||
data-slot="dialog-content"
|
data-slot="dialog-content"
|
||||||
v-bind="{ ...$attrs, ...forwarded }"
|
v-bind="{ ...$attrs, ...forwarded }"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const THROW_BUTTON_COOLDOWN = 550;
|
|||||||
export function usePaperBallToss({
|
export function usePaperBallToss({
|
||||||
roomId,
|
roomId,
|
||||||
currentPlayerId,
|
currentPlayerId,
|
||||||
|
currentPlayerIsModerator,
|
||||||
board,
|
board,
|
||||||
}: PaperBallTossOptions) {
|
}: PaperBallTossOptions) {
|
||||||
const activePaperBalls = ref<PaperBallFlight[]>([]);
|
const activePaperBalls = ref<PaperBallFlight[]>([]);
|
||||||
@@ -35,9 +36,11 @@ export function usePaperBallToss({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function throwPaperBall(targetPlayerId: number): Promise<void> {
|
async function throwPaperBall(targetPlayerId: number): Promise<void> {
|
||||||
|
const shouldApplyCooldown = !currentPlayerIsModerator();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
targetPlayerId === currentPlayerId() ||
|
targetPlayerId === currentPlayerId() ||
|
||||||
throwingAtPlayerId.value !== null
|
(shouldApplyCooldown && throwingAtPlayerId.value !== null)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,9 @@ export function usePaperBallToss({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throwingAtPlayerId.value = targetPlayerId;
|
if (shouldApplyCooldown) {
|
||||||
|
throwingAtPlayerId.value = targetPlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(throwPaperBallRoute(roomId()).url, {
|
const response = await fetch(throwPaperBallRoute(roomId()).url, {
|
||||||
@@ -91,11 +96,13 @@ export function usePaperBallToss({
|
|||||||
} catch {
|
} catch {
|
||||||
toast.error('Der Papierknäuel konnte nicht geworfen werden.');
|
toast.error('Der Papierknäuel konnte nicht geworfen werden.');
|
||||||
} finally {
|
} finally {
|
||||||
schedule(() => {
|
if (shouldApplyCooldown) {
|
||||||
if (throwingAtPlayerId.value === targetPlayerId) {
|
schedule(() => {
|
||||||
throwingAtPlayerId.value = null;
|
if (throwingAtPlayerId.value === targetPlayerId) {
|
||||||
}
|
throwingAtPlayerId.value = null;
|
||||||
}, THROW_BUTTON_COOLDOWN);
|
}
|
||||||
|
}, THROW_BUTTON_COOLDOWN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,72 +1,92 @@
|
|||||||
import { router } from '@inertiajs/vue3';
|
import { router } from '@inertiajs/vue3';
|
||||||
import { onScopeDispose, watch } from 'vue';
|
import { onScopeDispose, ref, shallowReadonly, watch } from 'vue';
|
||||||
|
|
||||||
import { getEcho } from '@/lib/echo';
|
import { getEcho } from '@/lib/echo';
|
||||||
import type { RoomStateChangedPayload } from '@/types/room';
|
import { home } from '@/routes';
|
||||||
|
import { join } from '@/routes/room';
|
||||||
|
import type {
|
||||||
|
CurrentRoomPlayer,
|
||||||
|
PokerRoom,
|
||||||
|
RoomStateChangedPayload,
|
||||||
|
} from '@/types/room';
|
||||||
|
|
||||||
const ROOM_EVENT = '.room.state.changed';
|
const ROOM_EVENT = '.room.state.changed';
|
||||||
|
|
||||||
export function useRoomRealtime(
|
export function useRoomRealtime(
|
||||||
roomId: () => string,
|
initialRoom: () => PokerRoom,
|
||||||
stateVersion: () => number,
|
initialCurrentPlayer: () => CurrentRoomPlayer,
|
||||||
): void {
|
) {
|
||||||
let reloadInProgress = false;
|
const room = ref<PokerRoom>({ ...initialRoom() });
|
||||||
let pendingVersion = 0;
|
const currentPlayer = ref<CurrentRoomPlayer>({ ...initialCurrentPlayer() });
|
||||||
let disposed = false;
|
|
||||||
|
|
||||||
function reloadRoom(): void {
|
|
||||||
if (reloadInProgress || disposed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadInProgress = true;
|
|
||||||
|
|
||||||
router.reload({
|
|
||||||
only: ['room', 'currentPlayer'],
|
|
||||||
onFinish: () => {
|
|
||||||
reloadInProgress = false;
|
|
||||||
|
|
||||||
if (disposed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pendingVersion > stateVersion()) {
|
|
||||||
reloadRoom();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingVersion = stateVersion();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRoomChange(payload: RoomStateChangedPayload): void {
|
function handleRoomChange(payload: RoomStateChangedPayload): void {
|
||||||
if (
|
if (
|
||||||
typeof payload.version !== 'number' ||
|
typeof payload.version !== 'number' ||
|
||||||
payload.version <= Math.max(stateVersion(), pendingVersion)
|
payload.version <= room.value.state_version
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingVersion = payload.version;
|
|
||||||
|
|
||||||
if (payload.change === 'room_deleted') {
|
if (payload.change === 'room_deleted') {
|
||||||
router.visit('/', { replace: true });
|
router.visit(home().url, { replace: true });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadRoom();
|
if (
|
||||||
|
payload.change === 'player_kicked' &&
|
||||||
|
payload.affected_player_id === currentPlayer.value.id
|
||||||
|
) {
|
||||||
|
router.visit(home().url, { replace: true });
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
payload.change === 'player_instance_replaced' &&
|
||||||
|
payload.affected_player_id === currentPlayer.value.id &&
|
||||||
|
payload.affected_instance_id === currentPlayer.value.instance_id
|
||||||
|
) {
|
||||||
|
router.visit(home().url, { replace: true });
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.change === 'room_closed') {
|
||||||
|
router.visit(
|
||||||
|
join({ query: { join_code: room.value.join_code } }).url,
|
||||||
|
{ replace: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.state === null || payload.state === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
room.value = {
|
||||||
|
...room.value,
|
||||||
|
...payload.state,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
payload.change === 'votes_reset' ||
|
||||||
|
payload.change === 'next_round'
|
||||||
|
) {
|
||||||
|
currentPlayer.value = {
|
||||||
|
...currentPlayer.value,
|
||||||
|
current_vote: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopWatchingRoom = watch(
|
const stopWatchingRoom = watch(
|
||||||
roomId,
|
() => initialRoom().id,
|
||||||
(nextRoomId, _previousRoomId, onCleanup) => {
|
(nextRoomId, _previousRoomId, onCleanup) => {
|
||||||
const echo = getEcho();
|
const echo = getEcho();
|
||||||
const channelName = `rooms.${nextRoomId}`;
|
const channelName = `rooms.${nextRoomId}`;
|
||||||
|
|
||||||
pendingVersion = stateVersion();
|
|
||||||
echo.channel(channelName).listen(ROOM_EVENT, handleRoomChange);
|
echo.channel(channelName).listen(ROOM_EVENT, handleRoomChange);
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
@@ -76,19 +96,30 @@ export function useRoomRealtime(
|
|||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
const stopWatchingVersion = watch(
|
const stopWatchingInitialState = watch(
|
||||||
stateVersion,
|
[initialRoom, initialCurrentPlayer],
|
||||||
(version) => {
|
([nextRoom, nextCurrentPlayer]) => {
|
||||||
if (!reloadInProgress) {
|
room.value = { ...nextRoom };
|
||||||
pendingVersion = Math.max(pendingVersion, version);
|
currentPlayer.value = { ...nextCurrentPlayer };
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ flush: 'sync' },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
onScopeDispose(() => {
|
onScopeDispose(() => {
|
||||||
disposed = true;
|
|
||||||
stopWatchingRoom();
|
stopWatchingRoom();
|
||||||
stopWatchingVersion();
|
stopWatchingInitialState();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function setCurrentVote(value: string | null): void {
|
||||||
|
currentPlayer.value = {
|
||||||
|
...currentPlayer.value,
|
||||||
|
current_vote: value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
room: shallowReadonly(room),
|
||||||
|
currentPlayer: shallowReadonly(currentPlayer),
|
||||||
|
setCurrentVote,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,11 @@ defineProps<{
|
|||||||
|
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<Label for="remember" class="flex items-center space-x-3">
|
<Label for="remember" class="flex items-center space-x-3">
|
||||||
<Checkbox id="remember" name="remember" :tabindex="3" />
|
<Checkbox
|
||||||
|
id="remember"
|
||||||
|
name="remember"
|
||||||
|
:tabindex="3"
|
||||||
|
/>
|
||||||
<span>Remember me</span>
|
<span>Remember me</span>
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Head, Link } from '@inertiajs/vue3';
|
||||||
|
import { CircleAlert } from '@lucide/vue';
|
||||||
|
|
||||||
|
import { login } from '@/routes';
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
message: string;
|
||||||
|
showLoginAction: boolean;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Head title="Scrum Poker nicht verfügbar" />
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="grid min-h-svh place-items-center bg-slate-900 p-8 text-slate-100"
|
||||||
|
>
|
||||||
|
<section
|
||||||
|
class="flex max-w-lg flex-col items-center gap-4 rounded-2xl border border-slate-700 bg-slate-800 p-8 text-center shadow-xl"
|
||||||
|
>
|
||||||
|
<CircleAlert class="size-10 text-amber-300" />
|
||||||
|
<h1 class="text-2xl font-bold">Raum kann nicht geöffnet werden</h1>
|
||||||
|
<p class="text-slate-300">{{ message }}</p>
|
||||||
|
<Link
|
||||||
|
v-if="showLoginAction"
|
||||||
|
:href="login()"
|
||||||
|
class="inline-flex rounded-lg bg-white px-4 py-2 font-semibold text-slate-900 transition hover:bg-slate-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
|
||||||
|
>
|
||||||
|
Anmelden
|
||||||
|
</Link>
|
||||||
|
<p class="text-sm text-slate-400">
|
||||||
|
Bitte ändere Raumcode oder Anzeigename auf der Home-Seite der
|
||||||
|
Fillibri Hub App und öffne Scrum Poker erneut.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import RoomExperience from '@/components/rooms/RoomExperience.vue';
|
||||||
|
import type { RoomPageProps } from '@/types/room';
|
||||||
|
|
||||||
|
const props = defineProps<RoomPageProps>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<RoomExperience
|
||||||
|
:room="props.room"
|
||||||
|
:current-player="props.currentPlayer"
|
||||||
|
embedded
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Head, Link, useForm } from '@inertiajs/vue3';
|
||||||
|
import { ArrowLeft } from '@lucide/vue';
|
||||||
|
|
||||||
|
import InputError from '@/components/InputError.vue';
|
||||||
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
|
import { dashboard } from '@/routes';
|
||||||
|
import { update as updateSettings } from '@/routes/room/settings';
|
||||||
|
import type { RoomSettingsPageProps } from '@/types/room';
|
||||||
|
|
||||||
|
const props = defineProps<RoomSettingsPageProps>();
|
||||||
|
const form = useForm({
|
||||||
|
allow_participants_to_manage_rounds:
|
||||||
|
props.room.allow_participants_to_manage_rounds,
|
||||||
|
is_persistent: props.room.is_persistent,
|
||||||
|
});
|
||||||
|
|
||||||
|
function submit(): void {
|
||||||
|
form.patch(updateSettings(props.room.id).url, {
|
||||||
|
preserveScroll: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Head title="Raumeinstellungen" />
|
||||||
|
|
||||||
|
<main
|
||||||
|
class="flex min-h-[calc(100svh-4rem)] justify-center bg-slate-900 p-4 text-slate-100 sm:p-8"
|
||||||
|
>
|
||||||
|
<section class="flex w-full max-w-2xl flex-col gap-6">
|
||||||
|
<Link
|
||||||
|
:href="dashboard()"
|
||||||
|
class="inline-flex w-fit items-center gap-2 text-sm text-slate-300 transition hover:text-white"
|
||||||
|
>
|
||||||
|
<ArrowLeft class="size-4" />
|
||||||
|
Zurück zu meinen Räumen
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1 class="text-2xl font-bold">Raumeinstellungen</h1>
|
||||||
|
<p class="mt-1 text-sm text-slate-400">
|
||||||
|
{{ room.title ?? 'Scrum Poker' }} · {{ room.join_code }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
class="flex flex-col gap-6 rounded-xl border border-slate-700 bg-slate-800 p-6"
|
||||||
|
@submit.prevent="submit"
|
||||||
|
>
|
||||||
|
<label class="flex cursor-pointer items-center gap-4">
|
||||||
|
<Checkbox
|
||||||
|
:model-value="form.allow_participants_to_manage_rounds"
|
||||||
|
class="border-white"
|
||||||
|
@update:model-value="
|
||||||
|
form.allow_participants_to_manage_rounds =
|
||||||
|
$event === true
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<span>
|
||||||
|
<strong class="block"
|
||||||
|
>Alle dürfen den Raum verwalten</strong
|
||||||
|
>
|
||||||
|
<span class="mt-1 block text-sm text-slate-400">
|
||||||
|
Alle aktiven Teilnehmer, auch Gäste, dürfen Runden
|
||||||
|
steuern und andere Teilnehmer aus dem Raum
|
||||||
|
entfernen.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<InputError
|
||||||
|
:message="form.errors.allow_participants_to_manage_rounds"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label class="flex cursor-pointer items-center gap-4">
|
||||||
|
<Checkbox
|
||||||
|
:model-value="form.is_persistent"
|
||||||
|
class="border-white"
|
||||||
|
@update:model-value="
|
||||||
|
form.is_persistent = $event === true
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<span>
|
||||||
|
<strong class="block"
|
||||||
|
>Raum dauerhaft offen halten</strong
|
||||||
|
>
|
||||||
|
<span class="mt-1 block text-sm text-slate-400">
|
||||||
|
Der Raum wird auch nach längerer Inaktivität nicht
|
||||||
|
automatisch geschlossen.
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<InputError :message="form.errors.is_persistent" />
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="inline-flex w-fit rounded-md bg-primary px-4 py-2 text-sm font-semibold text-primary-foreground transition hover:bg-primary/90 disabled:opacity-50"
|
||||||
|
:disabled="form.processing"
|
||||||
|
>
|
||||||
|
{{ form.processing ? 'Wird gespeichert …' : 'Speichern' }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@@ -1,62 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, usePage, usePoll } from '@inertiajs/vue3';
|
import RoomExperience from '@/components/rooms/RoomExperience.vue';
|
||||||
import { computed, ref } from 'vue';
|
|
||||||
|
|
||||||
import RoomHeader from '@/components/rooms/RoomHeader.vue';
|
|
||||||
import RoomRetentionNotice from '@/components/rooms/RoomRetentionNotice.vue';
|
|
||||||
import RoomTable from '@/components/rooms/RoomTable.vue';
|
|
||||||
import RoomVoteDeck from '@/components/rooms/RoomVoteDeck.vue';
|
|
||||||
import { useRoomRealtime } from '@/composables/useRoomRealtime';
|
|
||||||
import type { RoomPageProps } from '@/types/room';
|
import type { RoomPageProps } from '@/types/room';
|
||||||
|
|
||||||
const props = defineProps<RoomPageProps>();
|
const props = defineProps<RoomPageProps>();
|
||||||
|
|
||||||
const page = usePage();
|
|
||||||
const presenterMode = ref(false);
|
|
||||||
const roomNotice = computed(() => page.props.roomNotice);
|
|
||||||
const canFavorite = computed(
|
|
||||||
() => page.props.auth.user?.id != props.room.owner_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
useRoomRealtime(
|
|
||||||
() => props.room.id,
|
|
||||||
() => props.room.state_version,
|
|
||||||
);
|
|
||||||
|
|
||||||
usePoll(30_000, {
|
|
||||||
only: ['room', 'currentPlayer'],
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Head :title="room.title ?? 'Scrum Poker'" />
|
<RoomExperience :room="props.room" :current-player="props.currentPlayer" />
|
||||||
|
|
||||||
<main
|
|
||||||
class="-m-6 min-h-[calc(100svh-4rem)] bg-slate-900 px-3 py-6 text-white sm:px-6 md:flex md:h-[calc(100dvh-4rem-1px)] md:min-h-0 md:flex-col md:overflow-hidden lg:px-10"
|
|
||||||
>
|
|
||||||
<RoomRetentionNotice v-if="roomNotice" :notice="roomNotice" />
|
|
||||||
|
|
||||||
<RoomHeader
|
|
||||||
:id="room.id"
|
|
||||||
:title="room.title"
|
|
||||||
:join_code="room.join_code"
|
|
||||||
:is_favorite="room.is_favorite"
|
|
||||||
:can-favorite="canFavorite"
|
|
||||||
v-model:presenter-mode="presenterMode"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<RoomTable
|
|
||||||
:room="room"
|
|
||||||
:current-player="currentPlayer"
|
|
||||||
:presenter-mode="presenterMode"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<RoomVoteDeck
|
|
||||||
:room-id="room.id"
|
|
||||||
:revealed="room.revealed"
|
|
||||||
:cards="room.deck.cards"
|
|
||||||
:current-vote="currentPlayer.current_vote"
|
|
||||||
:presenter-mode="presenterMode"
|
|
||||||
/>
|
|
||||||
</main>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
export type DashboardRoomPlayer = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
is_moderator: boolean;
|
||||||
|
is_owner: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type DashboardRoom = {
|
export type DashboardRoom = {
|
||||||
id: string;
|
id: string;
|
||||||
title: string | null;
|
title: string | null;
|
||||||
@@ -5,6 +12,7 @@ export type DashboardRoom = {
|
|||||||
current_round: number;
|
current_round: number;
|
||||||
players_count: number;
|
players_count: number;
|
||||||
active_player_count: number;
|
active_player_count: number;
|
||||||
|
players: DashboardRoomPlayer[];
|
||||||
last_activity_at: string | null;
|
last_activity_at: string | null;
|
||||||
closed_at: string | null;
|
closed_at: string | null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export type PaperBallFlight = {
|
|||||||
export type PaperBallTossOptions = {
|
export type PaperBallTossOptions = {
|
||||||
roomId: () => string;
|
roomId: () => string;
|
||||||
currentPlayerId: () => number;
|
currentPlayerId: () => number;
|
||||||
|
currentPlayerIsModerator: () => boolean;
|
||||||
board: Ref<HTMLElement | null>;
|
board: Ref<HTMLElement | null>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export type RoomPlayer = {
|
|||||||
|
|
||||||
export type CurrentRoomPlayer = {
|
export type CurrentRoomPlayer = {
|
||||||
id: number;
|
id: number;
|
||||||
|
instance_id: string;
|
||||||
name: string;
|
name: string;
|
||||||
is_moderator: boolean;
|
is_moderator: boolean;
|
||||||
current_vote: string | null;
|
current_vote: string | null;
|
||||||
@@ -44,6 +45,8 @@ export type PokerRoom = {
|
|||||||
current_round: number;
|
current_round: number;
|
||||||
revealed: boolean;
|
revealed: boolean;
|
||||||
state_version: number;
|
state_version: number;
|
||||||
|
allow_participants_to_manage_rounds: boolean;
|
||||||
|
is_persistent: boolean;
|
||||||
statistics: RoomStatistics | null;
|
statistics: RoomStatistics | null;
|
||||||
deck: RoomDeck;
|
deck: RoomDeck;
|
||||||
players: RoomPlayer[];
|
players: RoomPlayer[];
|
||||||
@@ -64,6 +67,23 @@ export type RoomPageProps = {
|
|||||||
currentPlayer: CurrentRoomPlayer;
|
currentPlayer: CurrentRoomPlayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomExperienceProps = RoomPageProps & {
|
||||||
|
embedded?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RoomSettings = Pick<
|
||||||
|
PokerRoom,
|
||||||
|
| 'id'
|
||||||
|
| 'title'
|
||||||
|
| 'join_code'
|
||||||
|
| 'allow_participants_to_manage_rounds'
|
||||||
|
| 'is_persistent'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type RoomSettingsPageProps = {
|
||||||
|
room: RoomSettings;
|
||||||
|
};
|
||||||
|
|
||||||
export type CreateRoomPageProps = {
|
export type CreateRoomPageProps = {
|
||||||
decks: SelectableDeck[];
|
decks: SelectableDeck[];
|
||||||
defaultPlayerName: string | null;
|
defaultPlayerName: string | null;
|
||||||
@@ -91,10 +111,14 @@ export type RoomRetentionNoticeProps = {
|
|||||||
|
|
||||||
export type RoomHeaderProps = Pick<
|
export type RoomHeaderProps = Pick<
|
||||||
PokerRoom,
|
PokerRoom,
|
||||||
'id' | 'title' | 'join_code' | 'is_favorite'
|
'id' | 'title' | 'join_code' | 'is_favorite' | 'players'
|
||||||
> & {
|
> & {
|
||||||
canFavorite: boolean;
|
canFavorite: boolean;
|
||||||
|
canManageParticipants: boolean;
|
||||||
|
currentPlayerId: number;
|
||||||
presenterMode: boolean;
|
presenterMode: boolean;
|
||||||
|
canLogout: boolean;
|
||||||
|
playerName: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RoomHeaderEmits = {
|
export type RoomHeaderEmits = {
|
||||||
@@ -132,17 +156,38 @@ export type RoomVoteDeckProps = {
|
|||||||
presenterMode: boolean;
|
presenterMode: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomVoteDeckEmits = {
|
||||||
|
'vote-changed': [value: string | null];
|
||||||
|
};
|
||||||
|
|
||||||
export type RoomStateChange =
|
export type RoomStateChange =
|
||||||
| 'player_joined'
|
| 'player_joined'
|
||||||
|
| 'player_updated'
|
||||||
|
| 'player_kicked'
|
||||||
|
| 'player_instance_replaced'
|
||||||
| 'vote_changed'
|
| 'vote_changed'
|
||||||
| 'cards_revealed'
|
| 'cards_revealed'
|
||||||
| 'votes_reset'
|
| 'votes_reset'
|
||||||
| 'next_round'
|
| 'next_round'
|
||||||
| 'room_reopened'
|
| 'room_reopened'
|
||||||
| 'room_closed'
|
| 'room_closed'
|
||||||
| 'room_deleted';
|
| 'room_deleted'
|
||||||
|
| 'room_settings_updated';
|
||||||
|
|
||||||
export type RoomStateChangedPayload = {
|
export type RoomStateChangedPayload = {
|
||||||
version: number;
|
version: number;
|
||||||
change: RoomStateChange;
|
change: RoomStateChange;
|
||||||
|
state: RoomRealtimeState | null;
|
||||||
|
affected_player_id?: number;
|
||||||
|
affected_instance_id?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomRealtimeState = Pick<
|
||||||
|
PokerRoom,
|
||||||
|
| 'current_round'
|
||||||
|
| 'revealed'
|
||||||
|
| 'state_version'
|
||||||
|
| 'allow_participants_to_manage_rounds'
|
||||||
|
| 'statistics'
|
||||||
|
| 'players'
|
||||||
|
>;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\EmbeddedLogoutController;
|
||||||
|
use App\Http\Controllers\EmbeddedRoomController;
|
||||||
use App\Http\Controllers\FavoriteRoomController;
|
use App\Http\Controllers\FavoriteRoomController;
|
||||||
use App\Http\Controllers\RoomController;
|
use App\Http\Controllers\RoomController;
|
||||||
use App\Http\Controllers\RoomEmoteController;
|
use App\Http\Controllers\RoomEmoteController;
|
||||||
use App\Http\Controllers\RoomJoinController;
|
use App\Http\Controllers\RoomJoinController;
|
||||||
use App\Http\Controllers\RoomLifecycleController;
|
use App\Http\Controllers\RoomLifecycleController;
|
||||||
use App\Http\Controllers\RoomPlayerController;
|
use App\Http\Controllers\RoomPlayerController;
|
||||||
|
use App\Http\Controllers\RoomPlayerKickController;
|
||||||
|
use App\Http\Controllers\RoomSettingsController;
|
||||||
use App\Http\Controllers\RoundController;
|
use App\Http\Controllers\RoundController;
|
||||||
use App\Http\Controllers\VoteController;
|
use App\Http\Controllers\VoteController;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
@@ -21,7 +25,18 @@ Route::get('/room/join', RoomJoinController::class)->name('room.join');
|
|||||||
Route::post('room/join', [RoomPlayerController::class, 'join'])->name('room.code');
|
Route::post('room/join', [RoomPlayerController::class, 'join'])->name('room.code');
|
||||||
Route::post('/room', [RoomController::class, 'store'])->name('room.store');
|
Route::post('/room', [RoomController::class, 'store'])->name('room.store');
|
||||||
|
|
||||||
|
Route::get('/embedded/scrum-poker', EmbeddedRoomController::class)
|
||||||
|
->name('embedded.room');
|
||||||
|
|
||||||
|
Route::post('/embedded/scrum-poker/logout', EmbeddedLogoutController::class)
|
||||||
|
->middleware('auth')
|
||||||
|
->name('embedded.logout');
|
||||||
|
|
||||||
Route::middleware(['auth', 'verified'])->group(function () {
|
Route::middleware(['auth', 'verified'])->group(function () {
|
||||||
|
Route::get('/rooms/{room}/settings', [RoomSettingsController::class, 'edit'])
|
||||||
|
->name('room.settings.edit');
|
||||||
|
Route::patch('/rooms/{room}/settings', [RoomSettingsController::class, 'update'])
|
||||||
|
->name('room.settings.update');
|
||||||
Route::post('/rooms/{room}/reopen', [RoomLifecycleController::class, 'reopen'])
|
Route::post('/rooms/{room}/reopen', [RoomLifecycleController::class, 'reopen'])
|
||||||
->name('room.reopen');
|
->name('room.reopen');
|
||||||
Route::delete('/rooms/{room}', [RoomLifecycleController::class, 'destroy'])
|
Route::delete('/rooms/{room}', [RoomLifecycleController::class, 'destroy'])
|
||||||
@@ -30,6 +45,9 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
->name('room.favorite');
|
->name('room.favorite');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::delete('/rooms/{room}/players/{player}', RoomPlayerKickController::class)
|
||||||
|
->name('room.player.destroy');
|
||||||
|
|
||||||
Route::middleware('room.player')->group(function () {
|
Route::middleware('room.player')->group(function () {
|
||||||
Route::get('/rooms/{room}', [RoomController::class, 'show'])->name('room.show');
|
Route::get('/rooms/{room}', [RoomController::class, 'show'])->name('room.show');
|
||||||
Route::post('/rooms/{room}/votes', [VoteController::class, 'store'])
|
Route::post('/rooms/{room}/votes', [VoteController::class, 'store'])
|
||||||
|
|||||||
@@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\RoomStateChange;
|
||||||
|
use App\Events\RoomStateChanged;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
|
|
||||||
|
function createEmbeddedRoom(array $attributes = []): Room
|
||||||
|
{
|
||||||
|
return Room::create([
|
||||||
|
'title' => 'Fillibri Planning',
|
||||||
|
'deck_config' => [
|
||||||
|
'name' => 'Fibonacci',
|
||||||
|
'cards' => [
|
||||||
|
['key' => '3', 'label' => '3'],
|
||||||
|
['key' => '5', 'label' => '5'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
...$attributes,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a guest automatically joins the embedded room', function () {
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$response = $this->get(route('embedded.room', [
|
||||||
|
'join_code' => strtolower($room->join_code),
|
||||||
|
'player_name' => ' Nico ',
|
||||||
|
]))
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Room')
|
||||||
|
->where('room.id', $room->id)
|
||||||
|
->where('currentPlayer.name', 'Nico'));
|
||||||
|
|
||||||
|
$player = $room->players()->sole();
|
||||||
|
|
||||||
|
expect($player->user_id)->toBeNull()
|
||||||
|
->and($player->is_moderator)->toBeFalse();
|
||||||
|
|
||||||
|
$response->assertSessionHas("room_players.{$room->id}", $player->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('embedded guest access reuses the session player and applies a changed display name', function () {
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'name' => 'Old name',
|
||||||
|
'inactive_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $player->id])
|
||||||
|
->get(route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'New name',
|
||||||
|
]))
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($room->players()->count())->toBe(1)
|
||||||
|
->and($player->fresh()->name)->toBe('New name')
|
||||||
|
->and($player->fresh()->inactive_at)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an authenticated user automatically joins the embedded room', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$room = createEmbeddedRoom(['allow_participants_to_manage_rounds' => true]);
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->get(route('embedded.room', [
|
||||||
|
'join_code' => strtolower($room->join_code),
|
||||||
|
'player_name' => ' Nico ',
|
||||||
|
]))
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Room')
|
||||||
|
->where('room.id', $room->id)
|
||||||
|
->where('room.allow_participants_to_manage_rounds', true)
|
||||||
|
->where('currentPlayer.name', 'Nico'))
|
||||||
|
->assertSessionHas("room_players.{$room->id}");
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('players', [
|
||||||
|
'room_id' => $room->id,
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Nico',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('embedded access reuses the user player and applies a changed display name', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Old name',
|
||||||
|
'inactive_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->get(route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'New name',
|
||||||
|
]))
|
||||||
|
->assertOk();
|
||||||
|
|
||||||
|
expect($room->players()->count())->toBe(1)
|
||||||
|
->and($player->fresh()->name)->toBe('New name')
|
||||||
|
->and($player->fresh()->inactive_at)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an embedded guest keeps the same player after logging in separately', function () {
|
||||||
|
$user = User::factory()->create([
|
||||||
|
'email' => 'nico@example.com',
|
||||||
|
]);
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$url = route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get($url)->assertOk();
|
||||||
|
|
||||||
|
$player = $room->players()->sole();
|
||||||
|
|
||||||
|
$this->post(route('login.store'), [
|
||||||
|
'email' => 'nico@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
])->assertRedirect();
|
||||||
|
|
||||||
|
$this->get($url)->assertOk();
|
||||||
|
|
||||||
|
expect($room->players()->count())->toBe(1)
|
||||||
|
->and($player->fresh()->user_id)->toBe($user->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('embedded guest access shows a dedicated error when the display name is taken', function () {
|
||||||
|
$user = User::factory()->create([
|
||||||
|
'email' => 'nico@example.com',
|
||||||
|
]);
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$room->players()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Nico',
|
||||||
|
]);
|
||||||
|
$url = route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get($url)
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Error')
|
||||||
|
->where('message', 'Dieser Anzeigename ist in dem Raum bereits vorhanden.')
|
||||||
|
->where('showLoginAction', true))
|
||||||
|
->assertSessionHas('url.intended', $url);
|
||||||
|
|
||||||
|
$this->post(route('login.store'), [
|
||||||
|
'email' => 'nico@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
])->assertRedirect($url);
|
||||||
|
|
||||||
|
$this->get($url)
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Room')
|
||||||
|
->where('currentPlayer.name', 'Nico'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a new account instance takes over the embedded player and kicks the previous instance', function () {
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Nico',
|
||||||
|
'active_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
|
]);
|
||||||
|
$url = route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->withSession([
|
||||||
|
'room_player_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c17',
|
||||||
|
])
|
||||||
|
->get($url)
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->where('currentPlayer.id', $player->id)
|
||||||
|
->where('currentPlayer.instance_id', '019b8f80-37c4-71a3-b415-5f2697332c17'));
|
||||||
|
|
||||||
|
expect($player->fresh()->active_instance_id)
|
||||||
|
->toBe('019b8f80-37c4-71a3-b415-5f2697332c17');
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
fn (RoomStateChanged $event): bool => $event->change === RoomStateChange::PlayerInstanceReplaced
|
||||||
|
&& $event->affectedPlayerId === $player->id
|
||||||
|
&& $event->affectedInstanceId === '019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->withSession([
|
||||||
|
"room_players.{$room->id}" => $player->id,
|
||||||
|
'room_player_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
|
])
|
||||||
|
->post(route('room.vote.store', $room), ['value' => '5'])
|
||||||
|
->assertRedirect(route('room.join', ['join_code' => $room->join_code]));
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('votes', 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('embedded access shows a dedicated error for an unknown room code', function () {
|
||||||
|
$this->get(route('embedded.room', [
|
||||||
|
'join_code' => 'ABC234',
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]))
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Error')
|
||||||
|
->where('message', 'Dieser Raumcode existiert nicht.')
|
||||||
|
->where('showLoginAction', false));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('embedded logout returns to the same room as a guest without duplicating the player', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$room = createEmbeddedRoom();
|
||||||
|
$url = route('embedded.room', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user)->get($url)->assertOk();
|
||||||
|
|
||||||
|
$player = $room->players()->sole();
|
||||||
|
|
||||||
|
$this
|
||||||
|
->followingRedirects()
|
||||||
|
->post(route('embedded.logout', [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Nico',
|
||||||
|
]))
|
||||||
|
->assertOk()
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('embedded/Room')
|
||||||
|
->where('currentPlayer.id', $player->id));
|
||||||
|
|
||||||
|
$this->assertGuest()
|
||||||
|
->assertDatabaseCount('players', 1);
|
||||||
|
});
|
||||||
@@ -5,6 +5,7 @@ use App\Events\RoomStateChanged;
|
|||||||
use App\Jobs\CloseInactiveRooms;
|
use App\Jobs\CloseInactiveRooms;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
||||||
@@ -23,18 +24,20 @@ function createBroadcastRoom(array $attributes = []): Room
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
test('room state broadcasts expose only invalidation metadata', function () {
|
test('room state broadcasts synchronously expose sanitized state', function () {
|
||||||
$event = new RoomStateChanged(
|
$event = new RoomStateChanged(
|
||||||
'019b8f80-37c4-71a3-b415-5f2697332c16',
|
'019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
7,
|
7,
|
||||||
RoomStateChange::VoteChanged,
|
RoomStateChange::VoteChanged,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect($event->broadcastAs())->toBe('room.state.changed')
|
expect($event)->toBeInstanceOf(ShouldBroadcastNow::class)
|
||||||
|
->and($event->broadcastAs())->toBe('room.state.changed')
|
||||||
->and($event->broadcastOn()->name)->toBe('rooms.019b8f80-37c4-71a3-b415-5f2697332c16')
|
->and($event->broadcastOn()->name)->toBe('rooms.019b8f80-37c4-71a3-b415-5f2697332c16')
|
||||||
->and($event->broadcastWith())->toBe([
|
->and($event->broadcastWith())->toBe([
|
||||||
'version' => 7,
|
'version' => 7,
|
||||||
'change' => 'vote_changed',
|
'change' => 'vote_changed',
|
||||||
|
'state' => null,
|
||||||
])
|
])
|
||||||
->and($event->broadcastWith())->not->toHaveKeys([
|
->and($event->broadcastWith())->not->toHaveKeys([
|
||||||
'player_name',
|
'player_name',
|
||||||
@@ -42,6 +45,25 @@ test('room state broadcasts expose only invalidation metadata', function () {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('player instance replacement broadcasts the displaced instance', function () {
|
||||||
|
$event = new RoomStateChanged(
|
||||||
|
'019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
|
8,
|
||||||
|
RoomStateChange::PlayerInstanceReplaced,
|
||||||
|
null,
|
||||||
|
42,
|
||||||
|
'019b8f80-37c4-71a3-b415-5f2697332c17',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect($event->broadcastWith())->toBe([
|
||||||
|
'version' => 8,
|
||||||
|
'change' => 'player_instance_replaced',
|
||||||
|
'state' => null,
|
||||||
|
'affected_player_id' => 42,
|
||||||
|
'affected_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c17',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('joining a room broadcasts the new room version', function () {
|
test('joining a room broadcasts the new room version', function () {
|
||||||
Event::fake([RoomStateChanged::class]);
|
Event::fake([RoomStateChanged::class]);
|
||||||
$room = createBroadcastRoom();
|
$room = createBroadcastRoom();
|
||||||
@@ -68,23 +90,23 @@ test('voting and round actions broadcast their state changes', function () {
|
|||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.vote.store', $room), ['value' => '5'])
|
->post(route('room.vote.store', $room), ['value' => '5'])
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.reveal', $room))
|
->post(route('room.reveal', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.next-round', $room))
|
->post(route('room.next-round', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.vote.store', $room), ['value' => '3'])
|
->post(route('room.vote.store', $room), ['value' => '3'])
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.reset', $room))
|
->post(route('room.reset', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
foreach ([
|
foreach ([
|
||||||
RoomStateChange::VoteChanged,
|
RoomStateChange::VoteChanged,
|
||||||
@@ -98,6 +120,35 @@ test('voting and round actions broadcast their state changes', function () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
function (RoomStateChanged $event) use ($moderator): bool {
|
||||||
|
if ($event->change !== RoomStateChange::VoteChanged || $event->state === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = collect($event->state['players'])->firstWhere('id', $moderator->id);
|
||||||
|
|
||||||
|
return $event->state['revealed'] === false
|
||||||
|
&& $player['has_voted'] === true
|
||||||
|
&& $player['vote'] === null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
function (RoomStateChanged $event) use ($moderator): bool {
|
||||||
|
if ($event->change !== RoomStateChange::CardsRevealed || $event->state === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$player = collect($event->state['players'])->firstWhere('id', $moderator->id);
|
||||||
|
|
||||||
|
return $event->state['revealed'] === true
|
||||||
|
&& $player['vote'] === '5';
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Event::assertDispatchedTimes(RoomStateChanged::class, 5);
|
Event::assertDispatchedTimes(RoomStateChanged::class, 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,58 @@ test('a participant can throw a realtime paper ball at another player', function
|
|||||||
->and($room->state_version)->toBe($stateVersion);
|
->and($room->state_version)->toBe($stateVersion);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('moderator paper ball throws are not rate limited', function () {
|
||||||
|
Event::fake([PaperBallThrown::class]);
|
||||||
|
$room = createEmoteRoom();
|
||||||
|
$moderator = $room->players()->create([
|
||||||
|
'name' => 'Eric',
|
||||||
|
'is_moderator' => true,
|
||||||
|
]);
|
||||||
|
$target = $room->players()->create([
|
||||||
|
'name' => 'Anna',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
for ($throwCount = 0; $throwCount < 11; $throwCount++) {
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
||||||
|
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||||
|
'target_player_id' => $target->id,
|
||||||
|
])
|
||||||
|
->assertNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::assertDispatchedTimes(PaperBallThrown::class, 11);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('participant paper ball throws remain rate limited', function () {
|
||||||
|
Event::fake([PaperBallThrown::class]);
|
||||||
|
$room = createEmoteRoom();
|
||||||
|
$moderator = $room->players()->create([
|
||||||
|
'name' => 'Eric',
|
||||||
|
'is_moderator' => true,
|
||||||
|
]);
|
||||||
|
$participant = $room->players()->create([
|
||||||
|
'name' => 'Anna',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
for ($throwCount = 0; $throwCount < 10; $throwCount++) {
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $participant->id])
|
||||||
|
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||||
|
'target_player_id' => $moderator->id,
|
||||||
|
])
|
||||||
|
->assertNoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $participant->id])
|
||||||
|
->postJson(route('room.emote.paper-ball.store', $room), [
|
||||||
|
'target_player_id' => $moderator->id,
|
||||||
|
])
|
||||||
|
->assertTooManyRequests();
|
||||||
|
|
||||||
|
Event::assertDispatchedTimes(PaperBallThrown::class, 10);
|
||||||
|
});
|
||||||
|
|
||||||
test('a participant cannot throw a paper ball at themselves', function () {
|
test('a participant cannot throw a paper ball at themselves', function () {
|
||||||
Event::fake([PaperBallThrown::class]);
|
Event::fake([PaperBallThrown::class]);
|
||||||
$room = createEmoteRoom();
|
$room = createEmoteRoom();
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\RoomStateChange;
|
||||||
|
use App\Events\RoomStateChanged;
|
||||||
use App\Jobs\CloseInactiveRooms;
|
use App\Jobs\CloseInactiveRooms;
|
||||||
use App\Models\Deck;
|
use App\Models\Deck;
|
||||||
use App\Models\Room;
|
use App\Models\Room;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Vote;
|
use App\Models\Vote;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Inertia\Testing\AssertableInertia as Assert;
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
|
|
||||||
function createLifecycleRoom(array $attributes = []): Room
|
function createLifecycleRoom(array $attributes = []): Room
|
||||||
@@ -156,6 +159,36 @@ test('an authenticated player rejoins with the existing room identity', function
|
|||||||
$response->assertSessionHas("room_players.{$room->id}", $player->id);
|
$response->assertSessionHas("room_players.{$room->id}", $player->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a new account instance takes over the player during a regular room join', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$room = createLifecycleRoom();
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Room nickname',
|
||||||
|
'active_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c16',
|
||||||
|
]);
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->withSession([
|
||||||
|
'room_player_instance_id' => '019b8f80-37c4-71a3-b415-5f2697332c17',
|
||||||
|
])
|
||||||
|
->post(route('room.code'), [
|
||||||
|
'join_code' => $room->join_code,
|
||||||
|
'player_name' => 'Room nickname',
|
||||||
|
])
|
||||||
|
->assertRedirect(route('room.show', $room));
|
||||||
|
|
||||||
|
expect($player->fresh()->active_instance_id)
|
||||||
|
->toBe('019b8f80-37c4-71a3-b415-5f2697332c17');
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
fn (RoomStateChanged $event): bool => $event->change === RoomStateChange::PlayerInstanceReplaced
|
||||||
|
&& $event->affectedPlayerId === $player->id,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('an authenticated player can restore room access without the previous session', function () {
|
test('an authenticated player can restore room access without the previous session', function () {
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$room = createLifecycleRoom(['owner_id' => $user->id]);
|
$room = createLifecycleRoom(['owner_id' => $user->id]);
|
||||||
@@ -238,7 +271,7 @@ test('meaningful game actions update the explicit activity timestamp', function
|
|||||||
|
|
||||||
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
||||||
->post(route('room.vote.store', $room), ['value' => '5'])
|
->post(route('room.vote.store', $room), ['value' => '5'])
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
expect($room->fresh()->last_activity_at->equalTo(now()))->toBeTrue();
|
expect($room->fresh()->last_activity_at->equalTo(now()))->toBeTrue();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\RoomStateChange;
|
||||||
|
use App\Events\RoomStateChanged;
|
||||||
|
use App\Models\Player;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
|
|
||||||
|
function createRoomForPlayerKick(User $owner, array $attributes = []): Room
|
||||||
|
{
|
||||||
|
return Room::create([
|
||||||
|
'owner_id' => $owner->id,
|
||||||
|
'title' => 'Team Planning',
|
||||||
|
'current_round' => 1,
|
||||||
|
'deck_config' => [
|
||||||
|
'name' => 'Fibonacci',
|
||||||
|
'cards' => [
|
||||||
|
['key' => '3', 'label' => '3'],
|
||||||
|
['key' => '5', 'label' => '5'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
...$attributes,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPlayerToKickRoom(
|
||||||
|
Room $room,
|
||||||
|
string $name,
|
||||||
|
?User $user = null,
|
||||||
|
bool $isModerator = false,
|
||||||
|
): Player {
|
||||||
|
return $room->players()->create([
|
||||||
|
'user_id' => $user?->id,
|
||||||
|
'name' => $name,
|
||||||
|
'is_moderator' => $isModerator,
|
||||||
|
'last_seen_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('the room owner sees active room players on the dashboard', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner);
|
||||||
|
$moderator = addPlayerToKickRoom($room, 'Moderator', $owner, true);
|
||||||
|
$participant = addPlayerToKickRoom($room, 'Anna');
|
||||||
|
addPlayerToKickRoom($room, 'Inactive')->update(['inactive_at' => now()]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->get(route('dashboard'))
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->has('rooms.0.players', 2)
|
||||||
|
->where('rooms.0.players.0.id', $moderator->id)
|
||||||
|
->where('rooms.0.players.0.is_moderator', true)
|
||||||
|
->where('rooms.0.players.0.is_owner', true)
|
||||||
|
->where('rooms.0.players.1.id', $participant->id)
|
||||||
|
->where('rooms.0.players.1.is_moderator', false)
|
||||||
|
->where('rooms.0.players.1.is_owner', false));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the room owner can kick an active participant', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner);
|
||||||
|
addPlayerToKickRoom($room, 'Moderator', $owner, true);
|
||||||
|
$participant = addPlayerToKickRoom($room, 'Anna');
|
||||||
|
$remainingPlayer = addPlayerToKickRoom($room, 'Ben');
|
||||||
|
$remainingPlayer->votes()->create([
|
||||||
|
'room_id' => $room->id,
|
||||||
|
'round' => $room->current_round,
|
||||||
|
'value' => '5',
|
||||||
|
]);
|
||||||
|
$previousVersion = $room->fresh()->state_version;
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->delete(route('room.player.destroy', [$room, $participant]))
|
||||||
|
->assertRedirect();
|
||||||
|
|
||||||
|
expect($participant->fresh()->inactive_at)->not->toBeNull()
|
||||||
|
->and($room->fresh()->state_version)->toBe($previousVersion + 1);
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
function (RoomStateChanged $event) use ($participant, $remainingPlayer, $room): bool {
|
||||||
|
if (
|
||||||
|
$event->roomId !== $room->id
|
||||||
|
|| $event->change !== RoomStateChange::PlayerKicked
|
||||||
|
|| $event->affectedPlayerId !== $participant->id
|
||||||
|
|| $event->state === null
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remainingPlayerState = collect($event->state['players'])
|
||||||
|
->firstWhere('id', $remainingPlayer->id);
|
||||||
|
|
||||||
|
return collect($event->state['players'])->doesntContain('id', $participant->id)
|
||||||
|
&& $remainingPlayerState['has_voted'] === true
|
||||||
|
&& $remainingPlayerState['vote'] === null
|
||||||
|
&& $event->broadcastWith()['affected_player_id'] === $participant->id;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Event::assertDispatchedTimes(RoomStateChanged::class, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the room moderator can kick an active participant without shared management', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner, ['owner_id' => null]);
|
||||||
|
$moderator = addPlayerToKickRoom($room, 'Moderator', null, true);
|
||||||
|
$target = addPlayerToKickRoom($room, 'Anna');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
||||||
|
->delete(route('room.player.destroy', [$room, $target]))
|
||||||
|
->assertRedirect();
|
||||||
|
|
||||||
|
expect($target->fresh()->inactive_at)->not->toBeNull();
|
||||||
|
Event::assertDispatchedTimes(RoomStateChanged::class, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a participant cannot kick another player when participant management is disabled', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participantUser = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner);
|
||||||
|
addPlayerToKickRoom($room, 'Moderator', $owner, true);
|
||||||
|
$participant = addPlayerToKickRoom($room, 'Anna', $participantUser);
|
||||||
|
$target = addPlayerToKickRoom($room, 'Ben');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->actingAs($participantUser)
|
||||||
|
->withSession(["room_players.{$room->id}" => $participant->id])
|
||||||
|
->delete(route('room.player.destroy', [$room, $target]))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($target->fresh()->inactive_at)->toBeNull();
|
||||||
|
Event::assertNotDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a participant can kick another player when participant management is enabled', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner, [
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
]);
|
||||||
|
addPlayerToKickRoom($room, 'Moderator', $owner, true);
|
||||||
|
$participant = addPlayerToKickRoom($room, 'Anna');
|
||||||
|
$target = addPlayerToKickRoom($room, 'Ben');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $participant->id])
|
||||||
|
->delete(route('room.player.destroy', [$room, $target]))
|
||||||
|
->assertRedirect();
|
||||||
|
|
||||||
|
expect($target->fresh()->inactive_at)->not->toBeNull();
|
||||||
|
Event::assertDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a participant cannot kick themselves when participant management is enabled', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner, [
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
]);
|
||||||
|
$participant = addPlayerToKickRoom($room, 'Anna');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $participant->id])
|
||||||
|
->delete(route('room.player.destroy', [$room, $participant]))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($participant->fresh()->inactive_at)->toBeNull();
|
||||||
|
Event::assertNotDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an anonymous visitor without a room session cannot kick from an ownerless room', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner, [
|
||||||
|
'owner_id' => null,
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
]);
|
||||||
|
addPlayerToKickRoom($room, 'Moderator', null, true);
|
||||||
|
$target = addPlayerToKickRoom($room, 'Ben');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->delete(route('room.player.destroy', [$room, $target]))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($target->fresh()->inactive_at)->toBeNull();
|
||||||
|
Event::assertNotDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the room owner cannot kick their own player', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner);
|
||||||
|
$moderator = addPlayerToKickRoom($room, 'Moderator', $owner, true);
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->delete(route('room.player.destroy', [$room, $moderator]))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($moderator->fresh()->inactive_at)->toBeNull();
|
||||||
|
Event::assertNotDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the room owner cannot kick a player from another room', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$otherOwner = User::factory()->create();
|
||||||
|
$room = createRoomForPlayerKick($owner);
|
||||||
|
$otherRoom = createRoomForPlayerKick($otherOwner, ['title' => 'Other room']);
|
||||||
|
$target = addPlayerToKickRoom($otherRoom, 'Anna');
|
||||||
|
|
||||||
|
Event::fake([RoomStateChanged::class]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->delete(route('room.player.destroy', [$room, $target]))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($target->fresh()->inactive_at)->toBeNull();
|
||||||
|
Event::assertNotDispatched(RoomStateChanged::class);
|
||||||
|
});
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Enums\RoomStateChange;
|
||||||
|
use App\Events\RoomStateChanged;
|
||||||
|
use App\Jobs\CloseInactiveRooms;
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Inertia\Testing\AssertableInertia as Assert;
|
||||||
|
|
||||||
|
function createSettingsRoom(array $attributes = []): Room
|
||||||
|
{
|
||||||
|
return Room::create([
|
||||||
|
'title' => 'Teamraum',
|
||||||
|
'deck_config' => [
|
||||||
|
'name' => 'Fibonacci',
|
||||||
|
'cards' => [
|
||||||
|
['key' => '3', 'label' => '3'],
|
||||||
|
['key' => '5', 'label' => '5'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
...$attributes,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('room settings default to moderator control and normal retention', function () {
|
||||||
|
$room = createSettingsRoom();
|
||||||
|
|
||||||
|
expect($room->allow_participants_to_manage_rounds)->toBeFalse()
|
||||||
|
->and($room->is_persistent)->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the owner can view and update room settings', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createSettingsRoom(['owner_id' => $owner->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->get(route('room.settings.edit', $room))
|
||||||
|
->assertInertia(fn (Assert $page) => $page
|
||||||
|
->component('rooms/Settings')
|
||||||
|
->where('room.id', $room->id)
|
||||||
|
->where('room.allow_participants_to_manage_rounds', false)
|
||||||
|
->where('room.is_persistent', false));
|
||||||
|
|
||||||
|
Event::fake();
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->patch(route('room.settings.update', $room), [
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
'is_persistent' => true,
|
||||||
|
])
|
||||||
|
->assertRedirect();
|
||||||
|
|
||||||
|
$room->refresh();
|
||||||
|
|
||||||
|
expect($room->allow_participants_to_manage_rounds)->toBeTrue()
|
||||||
|
->and($room->is_persistent)->toBeTrue()
|
||||||
|
->and($room->state_version)->toBe(2);
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
fn (RoomStateChanged $event): bool => $event->change === RoomStateChange::RoomSettingsUpdated
|
||||||
|
&& $event->state['allow_participants_to_manage_rounds'] === true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a user who does not own a room cannot manage its settings', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$otherUser = User::factory()->create();
|
||||||
|
$room = createSettingsRoom(['owner_id' => $owner->id]);
|
||||||
|
|
||||||
|
$this->actingAs($otherUser)
|
||||||
|
->get(route('room.settings.edit', $room))
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
$this->actingAs($otherUser)
|
||||||
|
->patch(route('room.settings.update', $room), [
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
'is_persistent' => true,
|
||||||
|
])
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($room->fresh()->allow_participants_to_manage_rounds)->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('all active participants can manage rounds when the room setting is enabled', function () {
|
||||||
|
$room = createSettingsRoom(['allow_participants_to_manage_rounds' => true]);
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'name' => 'Anna',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $player->id])
|
||||||
|
->post(route('room.reveal', $room))
|
||||||
|
->assertNoContent();
|
||||||
|
|
||||||
|
expect($room->fresh()->revealed_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('normal participants remain unable to manage rounds when the setting is disabled', function () {
|
||||||
|
$room = createSettingsRoom();
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'name' => 'Anna',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->withSession(["room_players.{$room->id}" => $player->id])
|
||||||
|
->post(route('room.reveal', $room))
|
||||||
|
->assertForbidden();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('persistent rooms are excluded from automatic closing', function () {
|
||||||
|
$persistentRoom = createSettingsRoom([
|
||||||
|
'owner_id' => User::factory()->create()->id,
|
||||||
|
'is_persistent' => true,
|
||||||
|
'last_activity_at' => now()->subDays(60),
|
||||||
|
]);
|
||||||
|
$expiringRoom = createSettingsRoom([
|
||||||
|
'owner_id' => User::factory()->create()->id,
|
||||||
|
'last_activity_at' => now()->subDays(60),
|
||||||
|
]);
|
||||||
|
|
||||||
|
(new CloseInactiveRooms)->handle();
|
||||||
|
|
||||||
|
expect($persistentRoom->fresh()->closed_at)->toBeNull()
|
||||||
|
->and($expiringRoom->fresh()->closed_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('room settings broadcasts never expose hidden vote values', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$room = createSettingsRoom(['owner_id' => $owner->id]);
|
||||||
|
$player = $room->players()->create([
|
||||||
|
'name' => 'Anna',
|
||||||
|
'is_moderator' => false,
|
||||||
|
]);
|
||||||
|
$player->votes()->create([
|
||||||
|
'room_id' => $room->id,
|
||||||
|
'round' => 1,
|
||||||
|
'value' => '5',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Event::fake();
|
||||||
|
|
||||||
|
$this->actingAs($owner)->patch(route('room.settings.update', $room), [
|
||||||
|
'allow_participants_to_manage_rounds' => true,
|
||||||
|
'is_persistent' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
RoomStateChanged::class,
|
||||||
|
function (RoomStateChanged $event) use ($player): bool {
|
||||||
|
$broadcastPlayer = collect($event->state['players'])->firstWhere('id', $player->id);
|
||||||
|
|
||||||
|
return $broadcastPlayer['has_voted'] === true
|
||||||
|
&& $broadcastPlayer['vote'] === null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -40,7 +40,7 @@ test('a participant can vote and change their vote in the current round', functi
|
|||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.vote.store', $room), ['value' => '5'])
|
->post(route('room.vote.store', $room), ['value' => '5'])
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->assertDatabaseHas('votes', [
|
$this->assertDatabaseHas('votes', [
|
||||||
'room_id' => $room->id,
|
'room_id' => $room->id,
|
||||||
@@ -51,7 +51,7 @@ test('a participant can vote and change their vote in the current round', functi
|
|||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.vote.store', $room), ['value' => '8'])
|
->post(route('room.vote.store', $room), ['value' => '8'])
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
expect(Vote::query()->count())->toBe(1);
|
expect(Vote::query()->count())->toBe(1);
|
||||||
expect(Vote::query()->value('value'))->toBe('8')
|
expect(Vote::query()->value('value'))->toBe('8')
|
||||||
@@ -91,7 +91,7 @@ test('other votes stay hidden until the moderator reveals the round', function (
|
|||||||
|
|
||||||
$this->withSession($session)
|
$this->withSession($session)
|
||||||
->post(route('room.reveal', $room))
|
->post(route('room.reveal', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
expect($room->fresh()->last_activity_at->greaterThan($previousActivity))->toBeTrue();
|
expect($room->fresh()->last_activity_at->greaterThan($previousActivity))->toBeTrue();
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ test('starting the next round clears the revealed state', function () {
|
|||||||
|
|
||||||
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
||||||
->post(route('room.next-round', $room))
|
->post(route('room.next-round', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$room->refresh();
|
$room->refresh();
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ test('the moderator can reset only the votes from the current round', function (
|
|||||||
|
|
||||||
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
$this->withSession(["room_players.{$room->id}" => $moderator->id])
|
||||||
->post(route('room.reset', $room))
|
->post(route('room.reset', $room))
|
||||||
->assertRedirect();
|
->assertNoContent();
|
||||||
|
|
||||||
$this->assertDatabaseHas('votes', [
|
$this->assertDatabaseHas('votes', [
|
||||||
'room_id' => $room->id,
|
'room_id' => $room->id,
|
||||||
|
|||||||
Reference in New Issue
Block a user