diff --git a/app/features/sendouq-match/actions/q.match.$id.server.ts b/app/features/sendouq-match/actions/q.match.$id.server.ts index 961bb66a8..175956af1 100644 --- a/app/features/sendouq-match/actions/q.match.$id.server.ts +++ b/app/features/sendouq-match/actions/q.match.$id.server.ts @@ -184,7 +184,6 @@ export const action = defineAction( await SQGroupRepository.insertFromPrevious({ previousGroupId: body.previousGroupId, memberUserIds: previousGroup.members.map((m) => m.id), - status: "ACTIVE", }); await refreshSendouQInstance(); @@ -259,7 +258,6 @@ export const action = defineAction( await SQGroupRepository.insertFromPrevious({ previousGroupId: viewerGroup.id, memberUserIds: survivors.map((m) => m.id), - status: "ACTIVE", }); } catch (error) { // a concurrent voter may have already created the successor diff --git a/app/features/sendouq/SQGroupRepository.server.test.ts b/app/features/sendouq/SQGroupRepository.server.test.ts index 064dd16e8..d8495a84d 100644 --- a/app/features/sendouq/SQGroupRepository.server.test.ts +++ b/app/features/sendouq/SQGroupRepository.server.test.ts @@ -221,7 +221,6 @@ describe("insert", () => { await SQGroupRepository.insertFromPrevious({ previousGroupId: alphaGroupId, memberUserIds: alphaMembers.map((member) => member.id), - status: "ACTIVE", }); const votesBefore = await fetchVotes(alphaGroupId); diff --git a/app/features/sendouq/SQGroupRepository.server.ts b/app/features/sendouq/SQGroupRepository.server.ts index c582efd32..72729859e 100644 --- a/app/features/sendouq/SQGroupRepository.server.ts +++ b/app/features/sendouq/SQGroupRepository.server.ts @@ -114,7 +114,7 @@ export async function findCurrentGroups() { vc: eb.ref("User.vc"), }).as("members"), ]) - // != INACTIVE (same set as ACTIVE or PREPARING) so the partial + // != INACTIVE (same set as ACTIVE, PREPARING or READY_CHECK) so the partial // group_status_active index applies .where("Group.status", "!=", "INACTIVE") .groupBy("Group.id") @@ -179,13 +179,10 @@ export async function insert(args: CreateGroupArgs) { type CreateGroupFromPreviousGroupArgs = { previousGroupId: number; memberUserIds: number[]; - status?: Exclude; }; export async function insertFromPrevious( args: CreateGroupFromPreviousGroupArgs, ) { - const status = args.status ?? "PREPARING"; - return db.transaction().execute(async (trx) => { const previousGroup = await trx .selectFrom("Group") @@ -226,7 +223,7 @@ export async function insertFromPrevious( .values({ chatRoomId, inviteCode: shortNanoid(), - status, + status: "ACTIVE", matchmade: previousGroup.matchmade, }) .returning("id") diff --git a/app/features/sendouq/actions/q.looking.server.ts b/app/features/sendouq/actions/q.looking.server.ts index 9d5fba4d4..35faaf043 100644 --- a/app/features/sendouq/actions/q.looking.server.ts +++ b/app/features/sendouq/actions/q.looking.server.ts @@ -154,7 +154,6 @@ export const action = defineAction( if (!ourGroup || !theirGroup) return null; const { id: survivingGroupId } = groupAfterMorph({ - liker: "THEM", ourGroup, theirGroup, }); diff --git a/app/features/sendouq/core/SendouQ.server.test.ts b/app/features/sendouq/core/SendouQ.server.test.ts index a85760309..aa20de1cb 100644 --- a/app/features/sendouq/core/SendouQ.server.test.ts +++ b/app/features/sendouq/core/SendouQ.server.test.ts @@ -198,51 +198,6 @@ describe("SendouQ", () => { }); }); - describe("currentViewByUserId", () => { - beforeEach(async () => { - await users.create(8); - }); - - test("returns 'default' when user not in any group", async () => { - await refreshSendouQInstance(); - - const view = SendouQ.currentViewByUserId(users.id(1)); - - expect(view).toBe("default"); - }); - - test("returns 'preparing' when user in PREPARING group", async () => { - await createGroup([1], { status: "PREPARING" }); - await refreshSendouQInstance(); - - const view = SendouQ.currentViewByUserId(users.id(1)); - - expect(view).toBe("preparing"); - }); - - test("returns 'match' when user in ACTIVE group with matchId", async () => { - await SQMatchFactory.create({ - alphaUserIds: userIds([1, 2, 3, 4]), - bravoUserIds: userIds([5, 6, 7, 8]), - }); - - await refreshSendouQInstance(); - - const view = SendouQ.currentViewByUserId(users.id(1)); - - expect(view).toBe("match"); - }); - - test("returns 'looking' when user in ACTIVE group without matchId", async () => { - await createGroup([1], { status: "ACTIVE" }); - await refreshSendouQInstance(); - - const view = SendouQ.currentViewByUserId(users.id(1)); - - expect(view).toBe("looking"); - }); - }); - describe("findOwnGroup", () => { beforeEach(async () => { await users.create(8); diff --git a/app/features/sendouq/core/SendouQ.server.ts b/app/features/sendouq/core/SendouQ.server.ts index 7043525e6..dcdc6e0d3 100644 --- a/app/features/sendouq/core/SendouQ.server.ts +++ b/app/features/sendouq/core/SendouQ.server.ts @@ -113,18 +113,6 @@ class SendouQClass { })); } - /** The current view state for a user based on their group status. */ - currentViewByUserId(userId: number) { - const ownGroup = this.findOwnGroup(userId); - - if (!ownGroup) return "default"; - if (ownGroup.status === "PREPARING") return "preparing"; - if (ownGroup.matchId) return "match"; - if (ownGroup.status === "READY_CHECK") return "ready"; - - return "looking"; - } - /** The user's group, or undefined if not in one. */ findOwnGroup(userId: number) { return this.groups.find((group) => diff --git a/app/features/sendouq/core/groups.ts b/app/features/sendouq/core/groups.ts index af465e124..85300753b 100644 --- a/app/features/sendouq/core/groups.ts +++ b/app/features/sendouq/core/groups.ts @@ -1,34 +1,20 @@ import type { Tables } from "~/db/tables"; import { databaseTimestampToDate } from "~/utils/dates"; import type { GroupExpiryStatus } from "../q-types"; -import type { SQGroup } from "./SendouQ.server"; // group expires in 30min without actions performed const GROUP_EXPIRES_IN_MS = 30 * 60 * 1000; const GROUP_EXPIRING_SOON_IN_MS = 10 * 60 * 1000; -/** Whose settings two morphing groups keep: the bigger group's, or at equal size the liked group's. */ -export function groupAfterMorph({ +/** Whose settings two morphing groups keep: the bigger group's, or at equal size ours (the liked group's). */ +export function groupAfterMorph({ ourGroup, theirGroup, - liker, }: { - ourGroup: SQGroup; - theirGroup: SQGroup; - liker: "US" | "THEM"; + ourGroup: Group; + theirGroup: Group; }) { - const ourMembers = ourGroup.members ?? []; - const theirMembers = theirGroup.members ?? []; - - if (ourMembers.length > theirMembers.length) { - return ourGroup; - } - - if (theirMembers.length > ourMembers.length) { - return theirGroup; - } - - if (liker === "US") { + if (theirGroup.members.length > ourGroup.members.length) { return theirGroup; }