Keep pregame lobby chat open for an hour after the game ends

The chat used to disappear the moment a session left CREATED status.
Sessions now record a finishedAt timestamp when they're won or lost,
and the lobby (with chat) stays reachable via /game/{session} for an
hour afterward instead of immediately redirecting to the win/lose
feedback page. The lobby template shows a distinct "game finished"
header with a link to that feedback page during this window.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Frank
2026-08-10 16:47:57 +02:00
co-authored by Claude Sonnet 5
parent 846cfbc44a
commit 2bfc2aca1a
8 changed files with 112 additions and 26 deletions
@@ -35,6 +35,7 @@ final class GameAdminSessionController extends AbstractController
}
$session->setStatus(SessionStatus::LOST);
$session->setFinishedAt(new \DateTime());
$em->flush();
$this->addFlash('success', sprintf('Session #%d closed.', $session->getId()));
@@ -43,6 +43,7 @@ final class GameApiController extends AbstractController
if ($session->getStatus() === SessionStatus::PLAYING) {
if ($session->getTimer() !== null && $now >= $session->getTimer()) {
$session->setStatus(SessionStatus::LOST);
$session->setFinishedAt(new \DateTime());
$this->entityManager->persist($session);
$this->entityManager->flush();
$isFinished = true;
+1 -1
View File
@@ -149,7 +149,7 @@ final class GameController extends AbstractController
// Lazily pick up readiness changes from other players since our last request
$dashboardService->checkAllPlayersReady($session);
if ($session->getStatus() === SessionStatus::CREATED) {
if ($dashboardService->isLobbyChatOpen($session)) {
return $this->render('game/lobby.html.twig', [
'session' => $session,
'messages' => $dashboardService->getLobbyMessages($session),
+15
View File
@@ -31,6 +31,9 @@ class Session
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $created = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $finishedAt = null;
#[ORM\OneToMany(mappedBy: 'session', targetEntity: Player::class)]
private Collection $players;
@@ -97,6 +100,18 @@ class Session
return $this;
}
public function getFinishedAt(): ?\DateTimeInterface
{
return $this->finishedAt;
}
public function setFinishedAt(?\DateTimeInterface $finishedAt): static
{
$this->finishedAt = $finishedAt;
return $this;
}
/**
* @return Collection<int, Player>
*/
+25 -1
View File
@@ -24,6 +24,7 @@ final class GameDashboardService
{
private const READY_TIMEOUT_SECONDS = 60;
private const LOBBY_MESSAGE_MAX_LENGTH = 500;
private const LOBBY_CHAT_GRACE_PERIOD_SECONDS = 3600;
public function __construct(
private readonly GameRepository $gameRepository,
@@ -302,9 +303,32 @@ final class GameDashboardService
return $this->lobbyMessageRepository->findForSession($session);
}
/**
* The lobby chat is open while a session is still gathering players, and stays
* open for a grace period after the game ends so players can wrap up the
* conversation before it disappears.
*/
public function isLobbyChatOpen(Session $session): bool
{
if ($session->getStatus() === SessionStatus::CREATED) {
return true;
}
if (!in_array($session->getStatus(), [SessionStatus::WON, SessionStatus::LOST], true)) {
return false;
}
$finishedAt = $session->getFinishedAt();
if ($finishedAt === null) {
return false;
}
return (new \DateTime())->getTimestamp() - $finishedAt->getTimestamp() < self::LOBBY_CHAT_GRACE_PERIOD_SECONDS;
}
public function postLobbyMessage(Session $session, User $user, string $content): ?LobbyMessage
{
if ($session->getStatus() !== SessionStatus::CREATED) {
if (!$this->isLobbyChatOpen($session)) {
return null;
}
+1
View File
@@ -1118,6 +1118,7 @@ class GameResponseService
}
$session->setStatus(SessionStatus::WON);
$session->setFinishedAt(new \DateTime());
$this->entityManager->persist($session);
$this->entityManager->flush();