Forget lobby leavers who never played and delete lobbies left empty

This commit is contained in:
Kalle
2026-11-05 19:43:42 +02:00
parent 926db45a8e
commit 4bc1976d9c
20 changed files with 349 additions and 63 deletions

View File

@@ -1528,7 +1528,7 @@ interface LobbyKickedUser {
createdAt: Generated<number>;
}
/** Left the lobby (or was removed by it) without being kicked, keeps access to its chat. */
/** Left the lobby (or was removed by it) after playing a set without being kicked, keeps access to its chat. */
interface LobbyLeftUser {
lobbyId: number;
userId: number;

View File

@@ -322,10 +322,20 @@ describe("ChatRoomResolver LOBBY rooms", () => {
const hostId = () => users.id(2);
const memberId = () => users.id(3);
const setupLobby = async () => {
const setupLobby = async ({ hasPlayed = true } = {}) => {
const playerIds = users.ids(9).slice(1);
const lobby = await LobbyFactory.create(
{ hostUserId: hostId() },
{ signedUpUserIds: [memberId()] },
{
hostUserId: hostId(),
startsAt: dateToDatabaseTimestamp(subHours(new Date(), 1)),
},
hasPlayed
? {
signedUpUserIds: playerIds.slice(1),
checkedInUserIds: playerIds,
playedSetCount: 1,
}
: { signedUpUserIds: [memberId()] },
);
const { chatRoomId } = await db
.selectFrom("Lobby")
@@ -399,6 +409,15 @@ describe("ChatRoomResolver LOBBY rooms", () => {
);
});
test("a participant who left before playing loses it", async () => {
const { lobbyId, chatRoomId } = await setupLobby({ hasPlayed: false });
await leave(lobbyId);
const room = await resolveOrThrow(chatRoomId);
expect(hasPermission(room, "VIEW", { id: memberId() })).toBe(false);
});
test("lists a participant who left and rejoined once", async () => {
const { lobbyId, chatRoomId } = await setupLobby();
await leave(lobbyId);
@@ -406,9 +425,9 @@ describe("ChatRoomResolver LOBBY rooms", () => {
const room = await resolveOrThrow(chatRoomId);
expect(room.participantUserIds.sort(byId)).toEqual(
[hostId(), memberId()].sort(byId),
);
expect(
room.participantUserIds.filter((userId) => userId === memberId()),
).toEqual([memberId()]);
});
});

View File

@@ -278,7 +278,7 @@ async function resolveLobbyRooms(
titleParams: { name: owner.name },
url: lobbyPage(owner.id),
imageUrl: null,
// leaving keeps the chat, only a kick takes it away
// leaving after playing a set keeps the chat, only a kick takes it away
participantUserIds: R.unique(
[...owner.participants, ...owner.leftUsers].map(
(participant) => participant.userId,

View File

@@ -16,6 +16,7 @@ export type ChatRoomType =
export type SystemMessageType =
| "USER_JOINED"
| "USER_LEFT"
| "USER_LEFT_LOBBY"
| "LEAVING_AFTER_SET"
| "STAYING_AFTER_SET"
| "HOST_CHANGED"
@@ -50,6 +51,7 @@ export type PersistedSystemMessageType = Extract<
| "CANCEL_REFUSED"
| "USER_JOINED"
| "USER_LEFT"
| "USER_LEFT_LOBBY"
| "LEAVING_AFTER_SET"
| "STAYING_AFTER_SET"
| "HOST_CHANGED"

View File

@@ -77,6 +77,9 @@ export function MessageLog({
case "USER_LEFT": {
return t("common:chat.systemMsg.userLeft", { name });
}
case "USER_LEFT_LOBBY": {
return t("common:chat.systemMsg.userLeftLobby", { name });
}
case "LEAVING_AFTER_SET": {
return t("common:chat.systemMsg.leavingAfterSet", { name });
}

View File

@@ -109,9 +109,9 @@ describe("LobbyRepository visibility", () => {
});
test.each([
{ why: "one who left still sees it", isKicked: false, expected: true },
{ why: "one who was kicked doesn't", isKicked: true, expected: false },
])("link-only: $why", async ({ isKicked, expected }) => {
{ why: "one who left before playing doesn't see it", isKicked: false },
{ why: "one who was kicked doesn't see it", isKicked: true },
])("link-only: $why", async ({ isKicked }) => {
const lobby = await LobbyFactory.create(
{ hostUserId: hostId(), visibility: "LINK_ONLY" },
{ signedUpUserIds: [memberId()] },
@@ -131,8 +131,7 @@ describe("LobbyRepository visibility", () => {
LobbyRepository.findById(lobby.id),
);
expect(Boolean(found)).toBe(expected);
expect(Boolean(found?.hasViewerLeft)).toBe(expected);
expect(found).toBeUndefined();
});
test("link-only: a participant other than the host gets the share key", async () => {
@@ -377,6 +376,58 @@ describe("LobbyRepository.findAllForIndex", () => {
});
});
describe("LobbyRepository.removeParticipant", () => {
beforeEach(async () => {
await users.create(9);
});
const startedLobby = () =>
LobbyFactory.create(
{
hostUserId: hostId(),
startsAt: dateToDatabaseTimestamp(subMinutes(new Date(), 1)),
},
{
signedUpUserIds: users.ids(9).slice(1),
checkedInUserIds: users.ids(8),
playedSetCount: 1,
},
);
const leftUserIdsOf = async (lobbyId: number) =>
(
await withUserId(hostId(), () => LobbyRepository.findById(lobbyId))
)?.leftUsers.map((user) => user.id);
test("a player who played a set is listed as having left", async () => {
const lobby = await startedLobby();
const [set] = await LobbyMatchRepository.findAllSetsByLobbyId(lobby.id);
const leaverId = LobbySet.playersOf(set, "ALPHA").find(
(userId) => userId !== hostId(),
)!;
await LobbyRepository.removeParticipant({
lobbyId: lobby.id,
userId: leaverId,
unfinishedSetId: null,
});
expect(await leftUserIdsOf(lobby.id)).toEqual([leaverId]);
});
test("one who never played isn't listed as having left", async () => {
const lobby = await startedLobby();
await LobbyRepository.removeParticipant({
lobbyId: lobby.id,
userId: users.id(9),
unfinishedSetId: null,
});
expect(await leftUserIdsOf(lobby.id)).toEqual([]);
});
});
describe("LobbyRepository.end", () => {
beforeEach(async () => {
await users.create(9);

View File

@@ -38,8 +38,8 @@ export type LobbyById = NonNullable<Unwrapped<typeof findById>>;
/**
* The lobby with its participants, if the actor may see it: by its visibility, its share key, or as a participant
* or player of one of its sets or one who left it. `leftUsers` are those who left it and haven't signed up again,
* they keep its chat until kicked. `isViewerKicked` is whether the host kicked the actor out of it,
* or player of one of its sets or one who left it. `leftUsers` are those who left it after playing a set and haven't
* signed up again, they keep its chat until kicked. `isViewerKicked` is whether the host kicked the actor out of it,
* `hasViewerLeft` whether the actor left it at some point and so keeps its chat.
* `permissions.MANAGE` is the host. `shareKey` goes to the host and, as everyone in a link-only lobby already
* reached it through the link, to every viewer of one.
@@ -771,7 +771,7 @@ export async function updateParticipantsStatus({
.execute();
}
/** Removes the users from the lobby and from the lobby's ready checks. They keep the lobby's chat as having left it. */
/** Removes the users from the lobby and from the lobby's ready checks. Those who played a set keep the lobby's chat as having left it. */
export async function deleteParticipants(
{ lobbyId, userIds }: { lobbyId: number; userIds: number[] },
trx?: Transaction<DB>,
@@ -795,9 +795,21 @@ export async function deleteParticipants(
.where("LobbyReadyCheck.lobbyId", "=", lobbyId),
)
.execute();
const playedUserIds = await executor
.selectFrom("LobbySetParticipant")
.innerJoin("LobbySet", "LobbySet.id", "LobbySetParticipant.setId")
.select("LobbySetParticipant.userId")
.distinct()
.where("LobbySet.lobbyId", "=", lobbyId)
.where("LobbySetParticipant.userId", "in", userIds)
.where("LobbySetParticipant.side", "is not", null)
.execute();
if (playedUserIds.length === 0) return;
await executor
.insertInto("LobbyLeftUser")
.values(userIds.map((userId) => ({ lobbyId, userId })))
.values(playedUserIds.map(({ userId }) => ({ lobbyId, userId })))
.onConflict((oc) => oc.columns(["lobbyId", "userId"]).doNothing())
.execute();
}
@@ -936,6 +948,11 @@ export async function update(
.execute();
}
/** Deletes the lobby with everything of it, its chat room left to the orphaned rooms cleanup. */
export async function deleteById(id: number) {
await db.deleteFrom("Lobby").where("Lobby.id", "=", id).execute();
}
/**
* Ends the lobby. Its chat rooms become inactive, nobody counts as active in it anymore and sets that hadn't
* got a single map reported are dropped. The placements of its leaderboard are saved as the players' results.

View File

@@ -8,6 +8,7 @@ import * as ChatSystemMessage from "~/features/chat/ChatSystemMessage.server";
import { refreshSendouQInstance } from "~/features/sendouq/core/SendouQ.server";
import { dateToDatabaseTimestamp } from "~/utils/dates";
import { withUserId, wrappedAction } from "~/utils/Test";
import { lobbiesPage } from "~/utils/urls";
import * as LobbyActivity from "../core/LobbyActivity.server";
import * as LobbySet from "../core/LobbySet";
import * as LobbyMatchRepository from "../LobbyMatchRepository.server";
@@ -22,6 +23,7 @@ vi.mock("~/features/chat/ChatSystemMessage.server", async (importOriginal) => ({
typeof import("~/features/chat/ChatSystemMessage.server")
>()),
send: vi.fn(),
sendPersisted: vi.fn(),
}));
const lobbyAction = wrappedAction<typeof lobbyActionSchema>({ action });
@@ -275,14 +277,25 @@ describe("lobby action", () => {
});
test("the host kicks a player who left, taking away the lobby's chat", async () => {
const playerIds = users.ids(8);
const lobby = await LobbyFactory.create(
{ hostUserId: hostId() },
{ signedUpUserIds: [visitorId()] },
{
hostUserId: hostId(),
startsAt: dateToDatabaseTimestamp(subMinutes(new Date(), 30)),
},
{
signedUpUserIds: playerIds.slice(1),
checkedInUserIds: playerIds,
playedSetCount: 1,
},
);
await lobbyAction(
{ _action: "LEAVE" },
{ user: visitorId(), params: { id: String(lobby.id) } },
);
const leftUserIds = (
await withUserId(hostId(), () => LobbyRepository.findById(lobby.id))
)?.leftUsers.map((user) => user.id);
await lobbyAction(
{ _action: "KICK", userId: visitorId() },
@@ -292,10 +305,65 @@ describe("lobby action", () => {
const found = await withUserId(visitorId(), () =>
LobbyRepository.findById(lobby.id),
);
expect(leftUserIds).toEqual([visitorId()]);
expect(found?.isViewerKicked).toBe(true);
expect(found?.hasViewerLeft).toBe(false);
});
test("the last one leaving before the start deletes the lobby", async () => {
const lobby = await LobbyFactory.create({ hostUserId: hostId() });
const response = await lobbyAction(
{ _action: "LEAVE" },
{ user: hostId(), params: { id: String(lobby.id) } },
);
expect(response.status).toBe(302);
expect(response.headers.get("Location")).toBe(lobbiesPage());
expect(
await LobbyRepository.findProgressionStateById(lobby.id),
).toBeUndefined();
});
test("the last one leaving after the start ends the lobby", async () => {
const lobby = await LobbyFactory.create(
{
hostUserId: hostId(),
startsAt: dateToDatabaseTimestamp(subMinutes(new Date(), 1)),
},
{ checkedInUserIds: [hostId()] },
);
await lobbyAction(
{ _action: "LEAVE" },
{ user: hostId(), params: { id: String(lobby.id) } },
);
expect(
(await LobbyRepository.findProgressionStateById(lobby.id))?.endedAt,
).not.toBeNull();
});
test("leaving before playing is noted in the lobby's chat", async () => {
const lobby = await LobbyFactory.create(
{ hostUserId: hostId() },
{ signedUpUserIds: [visitorId()] },
);
vi.mocked(ChatSystemMessage.sendPersisted).mockClear();
await lobbyAction(
{ _action: "LEAVE" },
{ user: visitorId(), params: { id: String(lobby.id) } },
);
expect(ChatSystemMessage.sendPersisted).toHaveBeenCalledWith(
expect.objectContaining({
type: "USER_LEFT_LOBBY",
authorUserId: visitorId(),
}),
);
});
test("only the host confirms a disputed set", async () => {
const playerIds = users.ids(8);
const lobby = await LobbyFactory.create(

View File

@@ -1,3 +1,4 @@
import { redirect } from "react-router";
import type * as v from "valibot";
import { visibilityIssues } from "~/features/associations/associations-schemas";
import { requireUser } from "~/features/auth/core/user.server";
@@ -17,6 +18,7 @@ import {
} from "~/utils/remix.server";
import { idObject } from "~/utils/schema";
import { assertUnreachable } from "~/utils/types";
import { lobbiesPage } from "~/utils/urls";
import * as LobbyProgression from "../core/LobbyProgression.server";
import * as LobbySet from "../core/LobbySet";
import * as LobbyState from "../core/LobbyState";
@@ -198,11 +200,13 @@ export const action = defineAction(
userId: user.id,
unfinishedSetId: unfinishedSetIdOf(viewer),
});
sendSetEndingMessage({
chatRoomId: lobby.chatRoomId,
userId: user.id,
setEnding,
});
if (lobby.chatRoomId) {
void ChatSystemMessage.sendPersisted({
roomId: lobby.chatRoomId,
type: setEndingMessageType(setEnding) ?? "USER_LEFT_LOBBY",
authorUserId: user.id,
});
}
LobbyVoice.ejectLeavers({
lobby: {
chatRoomId: lobby.chatRoomId,
@@ -441,6 +445,11 @@ export const action = defineAction(
: [],
});
const isLobbyDeleted =
body._action === "LEAVE" &&
!(await LobbyRepository.findProgressionStateById(id));
if (isLobbyDeleted) return redirect(lobbiesPage());
return null;
},
);
@@ -454,16 +463,25 @@ function sendSetEndingMessage({
userId: number;
setEnding: LobbyMatchRepository.LeftSetEnding | null;
}) {
if (!chatRoomId) return;
if (setEnding !== "FORFEITED" && setEnding !== "CALLED_OFF") return;
const type = setEndingMessageType(setEnding);
if (!chatRoomId || !type) return;
void ChatSystemMessage.sendPersisted({
roomId: chatRoomId,
type: setEnding === "FORFEITED" ? "SET_FORFEITED" : "SET_CALLED_OFF",
type,
authorUserId: userId,
});
}
function setEndingMessageType(
setEnding: LobbyMatchRepository.LeftSetEnding | null,
) {
if (setEnding === "FORFEITED") return "SET_FORFEITED";
if (setEnding === "CALLED_OFF") return "SET_CALLED_OFF";
return null;
}
/** The latest set the user played a side of, the one whose weapons they report. */
function latestPlayedSetOf(
sets: LobbyMatchRepository.LobbySetWithGames[],

View File

@@ -7,10 +7,11 @@ import {
import { SendouTabPanel } from "~/components/elements/Tabs";
import { WeaponImage } from "~/components/Image";
import { TAB_KEYS } from "~/components/match-page/MatchTabs";
import { useHasPermission } from "~/modules/permissions/hooks";
import { useLobbyView } from "../lobbies-hooks";
import { LobbyHeadToHeadGrid } from "./LobbyHeadToHeadGrid";
import styles from "./LobbyLeaderboardTab.module.css";
import { LobbyLeftUserTable, LobbyParticipantTable } from "./LobbyParticipants";
import { LobbyParticipantTable } from "./LobbyParticipants";
import { LobbyPlayerTable } from "./LobbyPlayerTable";
const WEAPONS_SHOWN = 4;
@@ -117,3 +118,21 @@ export function LobbyLeaderboardTab() {
</SendouTabPanel>
);
}
/** For the host, players who left the lobby and so still have its chat, to kick them out of it. */
function LobbyLeftUserTable() {
const { t } = useTranslation(["lobbies"]);
const { data } = useLobbyView();
const isHost = useHasPermission(data.lobby, "MANAGE");
if (!isHost || data.lobby.endedAt !== null) return null;
return (
<LobbyPlayerTable
title={t("lobbies:leaderboard.left")}
rows={data.lobby.leftUsers.map((user) => ({ user }))}
rowTestId="lobby-left-user"
columns={[]}
/>
);
}

View File

@@ -1,6 +1,5 @@
import { useTranslation } from "react-i18next";
import { WeaponPool } from "~/components/match-page/WeaponPool";
import { useHasPermission } from "~/modules/permissions/hooks";
import type { LobbyParticipantStatus } from "../lobbies-constants";
import { useLobbyView } from "../lobbies-hooks";
import styles from "./LobbyParticipants.module.css";
@@ -45,29 +44,10 @@ export function LobbyParticipants() {
participants={withStatus("WAITLISTED")}
isNumbered
/>
<LobbyLeftUserTable />
</div>
);
}
/** For the host, those who left the lobby and so still have its chat, to kick them out of it. */
export function LobbyLeftUserTable() {
const { t } = useTranslation(["lobbies"]);
const { data } = useLobbyView();
const isHost = useHasPermission(data.lobby, "MANAGE");
if (!isHost || data.lobby.endedAt !== null) return null;
return (
<LobbyPlayerTable
title={t("lobbies:leaderboard.left")}
rows={data.lobby.leftUsers.map((user) => ({ user }))}
rowTestId="lobby-left-user"
columns={[]}
/>
);
}
/** Participants of the lobby a row each, with their weapon pool. */
export function LobbyParticipantTable({
title,

View File

@@ -31,9 +31,10 @@ import * as WeaponRoll from "./WeaponRoll";
/** Upper bound of transitions applied in one go, a backstop against a transition that doesn't settle. */
const MAX_TRANSITIONS = 50;
/** Transitions changing what the lobbies list shows: player counts, viewer statuses, host or the lobby ending. */
/** Transitions changing what the lobbies list shows: player counts, viewer statuses, host or the lobby ending or going away. */
const LISTING_TRANSITIONS = new Set<LobbyTransition.Transition["type"]>([
"END",
"DELETE",
"TRANSFER_HOST",
"PROMOTE",
"START",
@@ -216,6 +217,10 @@ async function apply({
roomsChanged(allUserIds);
break;
}
case "DELETE": {
await LobbyRepository.deleteById(lobby.id);
break;
}
case "TRANSFER_HOST": {
await LobbyRepository.update({
id: lobby.id,

View File

@@ -213,10 +213,17 @@ describe("LobbyTransition.next", () => {
expect(result).toEqual({ type: "END" });
});
test("ends once everyone has left", () => {
expect(
LobbyTransition.next(state({ participants: [] }), STARTS_AT),
).toEqual({ type: "END" });
test.each([
{ why: "ends once everyone has left", now: STARTS_AT, type: "END" },
{
why: "deletes once everyone has left before the start",
now: STARTS_AT - 1,
type: "DELETE",
},
])("$why", ({ now, type }) => {
expect(LobbyTransition.next(state({ participants: [] }), now)).toEqual({
type,
});
});
test("passes the host to the longest-tenured participant", () => {

View File

@@ -1,6 +1,6 @@
/**
* Decides the next change a lobby goes through (opening check-in, starting, promoting from the waitlist, filling the
* room, ready checks, starting a set, passing on the host, ending) from its current state. Pure,
* room, ready checks, starting a set, passing on the host, ending or deleting) from its current state. Pure,
* applied by `LobbyProgression`.
*/
import {
@@ -46,6 +46,8 @@ export interface ProgressionState {
/** A change to the lobby's state, applied by `LobbyProgression.advance` one at a time. */
export type Transition =
| { type: "END" }
/** Before the start: everyone left, nothing of the lobby is worth keeping */
| { type: "DELETE" }
| { type: "TRANSFER_HOST"; userId: number }
/** Marks check-in open for good, notifying those with a spot */
| { type: "OPEN_CHECK_IN" }
@@ -73,7 +75,7 @@ export function next(state: ProgressionState, now: number): Transition | null {
const isPlaying = latestSet !== null && !LobbySet.isFinished(latestSet);
if (participants.length === 0) {
return hasStarted ? { type: "END" } : null;
return hasStarted ? { type: "END" } : { type: "DELETE" };
}
if (!participants.some((p) => p.userId === lobby.hostUserId)) {

View File

@@ -0,0 +1,5 @@
---
navItem: lobbies
type: feature
---
Players leaving a lobby before playing are no longer listed as having left, the chat notes they left instead

View File

@@ -0,0 +1,5 @@
---
navItem: lobbies
type: feature
---
A lobby everyone leaves before its start is now deleted instead of staying listed empty

View File

@@ -9,6 +9,7 @@ import {
import { modesShort } from "~/modules/in-game-lists/modes";
import { stageIds } from "~/modules/in-game-lists/stage-ids";
import { dateToDatabaseTimestamp } from "~/utils/dates";
import { lobbiesPage } from "~/utils/urls";
import { chatHistoryStatus, openSecondUser } from "./helpers/chat";
import type { Factories } from "./helpers/factories";
import {
@@ -1605,16 +1606,18 @@ test.describe("Lobbies", () => {
});
/**
* The lobby's chat is shared by everyone in it and stays with those who leave, only a kick takes it
* away. While a set is played its two teams also get a chat of their own, fresh for every set.
* The lobby's chat is shared by everyone in it and stays with players who leave after playing a set, only a
* kick takes it away. While a set is played its two teams also get a chat of their own, fresh for every set.
*/
test.describe("Chat", () => {
test("leaving keeps the lobby's chat, being kicked takes it away", async ({
test("leaving before playing is noted in the chat and takes it away", async ({
page,
factories,
}) => {
const host = await factories.UserFactory.create();
const leaver = await factories.UserFactory.create();
const leaver = await factories.UserFactory.create({
discordName: "EarlyLeaver",
});
const lobby = await factories.LobbyFactory.create(
{ hostUserId: host.id },
{ signedUpUserIds: [leaver.id] },
@@ -1622,13 +1625,42 @@ test.describe("Lobbies", () => {
const lobbyPage = new LobbyPage(page);
const chat = new ChatSidebar(page);
await test.step("A participant leaves and still writes to the lobby", async () => {
await test.step("A participant leaves before playing and has no chat anymore", async () => {
await impersonate(page, leaver.id);
await lobbyPage.goto(lobby.id);
await expect(chat.locators.openChats).toHaveCount(1);
await lobbyPage.leave();
await expect(lobbyPage.locators.signUpButton).toBeVisible();
await isNotVisible(chat.locators.openChats);
});
await test.step("The host sees them leave in the chat only", async () => {
await impersonate(page, host.id);
await lobbyPage.goto(lobby.id);
await expect(
chat.chat().message("EarlyLeaver left the lobby"),
).toBeVisible();
await isNotVisible(lobbyPage.locators.leftUsers);
});
});
test("leaving after playing keeps the lobby's chat, being kicked takes it away", async ({
page,
factories,
}) => {
const { lobby, host, alphaPlayers } = await startedLobby(page, factories);
const leaver = alphaPlayers.find((player) => player.id !== host.id)!;
const lobbyPage = new LobbyPage(page);
const chat = new ChatSidebar(page);
await test.step("A player leaves mid-set and still writes to the lobby", async () => {
await impersonate(page, leaver.id);
await lobbyPage.goto(lobby.id, "action");
await lobbyPage.reportOwnTeamWin();
await lobbyPage.leaveMidSet();
await expect(lobbyPage.locators.signUpButton).toBeVisible();
await chat.chat().send("left but still here");
await expect(chat.chat().message("left but still here")).toBeVisible();
@@ -1645,11 +1677,11 @@ test.describe("Lobbies", () => {
await test.step("The host kicks the one who left", async () => {
await impersonate(page, host.id);
await lobbyPage.goto(lobby.id);
await lobbyPage.goto(lobby.id, "leaderboard");
await expect(chat.chat().message("left but still here")).toBeVisible();
await expect(lobbyPage.locators.leftUsers).toHaveCount(1);
await lobbyPage.kick(leaver.id);
await lobbyPage.kickLeftUser(leaver.id);
await expect(lobbyPage.locators.leftUsers).toHaveCount(0);
});
@@ -2085,6 +2117,33 @@ test.describe("Lobbies", () => {
await expect(lobbyPage.locators.endedStatus).toBeVisible();
});
test("a lobby everyone left before its start is deleted", async ({
page,
factories,
}) => {
const host = await factories.UserFactory.create();
const lobby = await factories.LobbyFactory.create({
hostUserId: host.id,
});
const lobbyPage = new LobbyPage(page);
await test.step("The host, the only one in it, leaves and lands on the lobby list", async () => {
await impersonate(page, host.id);
await lobbyPage.goto(lobby.id);
await lobbyPage.leave();
await expect(page).toHaveURL(lobbiesPage());
});
await test.step("The lobby is gone", async () => {
await lobbyPage.goto(lobby.id);
await expect(
new ErrorPage(page).locators.notFoundHeading,
).toBeVisible();
});
});
test("a started lobby everyone left ends", async ({ page, factories }) => {
const host = await factories.UserFactory.create();
const lobby = await factories.LobbyFactory.create(

View File

@@ -301,13 +301,22 @@ export class LobbyPage {
);
}
/** As the host, kicks the participant, or one who left, out of the lobby for good through their player menu. */
/** As the host, kicks the participant out of the lobby for good through their player menu. */
async kick(userId: number) {
await this.openPlayerMenu(userId);
await this.page.getByRole("menuitem", { name: "Kick" }).click();
await modalClickConfirmButton(this.page);
}
/** As the host, kicks a player who left out of the lobby's chat through their row of the Rankings tab's left table. */
async kickLeftUser(userId: number) {
await this.locators.leftUsers
.getByTestId(`lobby-player-menu-${userId}`)
.click();
await this.page.getByRole("menuitem", { name: "Kick" }).click();
await modalClickConfirmButton(this.page);
}
/** As the host, hands hosting over to the participant through their player menu, confirming it. */
async makeHost(userId: number) {
await this.openPlayerMenu(userId);

View File

@@ -420,6 +420,7 @@
"chat.systemMsg.cancelRefused": "{{name}} refused canceling the match",
"chat.systemMsg.userJoined": "{{name}} joined the lobby",
"chat.systemMsg.userLeft": "{{name}} left the group",
"chat.systemMsg.userLeftLobby": "{{name}} left the lobby",
"chat.systemMsg.leavingAfterSet": "{{name}} will leave after this set",
"chat.systemMsg.stayingAfterSet": "{{name}} changed their mind and will stay after this set",
"chat.systemMsg.hostChanged": "{{name}} is now the host",

View File

@@ -0,0 +1,16 @@
import { type Kysely, sql } from "kysely";
/** Only those who played a set of the lobby keep its chat after leaving. */
export async function up(db: Kysely<any>): Promise<void> {
await sql`
delete from "LobbyLeftUser"
where not exists (
select 1
from "LobbySetParticipant"
inner join "LobbySet" on "LobbySet"."id" = "LobbySetParticipant"."setId"
where "LobbySet"."lobbyId" = "LobbyLeftUser"."lobbyId"
and "LobbySetParticipant"."userId" = "LobbyLeftUser"."userId"
and "LobbySetParticipant"."side" is not null
)
`.execute(db);
}