From 699f25155908d0475a7e3ce66cdb8713a4e8c9d2 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:37:54 +0300 Subject: [PATCH] Censor groups if own expired --- app/features/sendouq/core/groups.server.ts | 19 ++++++++++++++++++- app/features/sendouq/q-types.ts | 2 ++ app/features/sendouq/routes/q.looking.tsx | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/features/sendouq/core/groups.server.ts b/app/features/sendouq/core/groups.server.ts index ed8e4cb24..32dbccfb3 100644 --- a/app/features/sendouq/core/groups.server.ts +++ b/app/features/sendouq/core/groups.server.ts @@ -14,6 +14,7 @@ import { FULL_GROUP_SIZE } from "../q-constants"; import type { DividedGroups, DividedGroupsUncensored, + GroupExpiryStatus, LookingGroup, LookingGroupWithInviteCode, } from "../q-types"; @@ -459,7 +460,7 @@ function resolveGroupSkill({ export function groupExpiryStatus( group?: Pick, -): null | "EXPIRING_SOON" | "EXPIRED" { +): null | GroupExpiryStatus { if (!group) return null; // group expires in 30min without actions performed @@ -481,6 +482,22 @@ export function groupExpiryStatus( return null; } +export function censorGroupsIfOwnExpired({ + groups, + ownGroupExpiryStatus, +}: { + groups: DividedGroups; + ownGroupExpiryStatus: GroupExpiryStatus | null; +}): DividedGroups { + if (ownGroupExpiryStatus !== "EXPIRED") return groups; + + return { + own: groups.own, + likesReceived: [], + neutral: [], + }; +} + const allTiersOrdered = TIERS.flatMap((tier) => [ { name: tier.name, isPlus: true }, { name: tier.name, isPlus: false }, diff --git a/app/features/sendouq/q-types.ts b/app/features/sendouq/q-types.ts index 56d8fea29..6ec63bbb1 100644 --- a/app/features/sendouq/q-types.ts +++ b/app/features/sendouq/q-types.ts @@ -69,3 +69,5 @@ export interface DividedGroupsUncensored { neutral: LookingGroupWithInviteCode[]; likesReceived: LookingGroupWithInviteCode[]; } + +export type GroupExpiryStatus = "EXPIRING_SOON" | "EXPIRED"; diff --git a/app/features/sendouq/routes/q.looking.tsx b/app/features/sendouq/routes/q.looking.tsx index 80ee6181d..03050d803 100644 --- a/app/features/sendouq/routes/q.looking.tsx +++ b/app/features/sendouq/routes/q.looking.tsx @@ -55,6 +55,7 @@ import { addSkillRangeToGroups, addSkillsToGroups, censorGroups, + censorGroupsIfOwnExpired, divideGroups, groupExpiryStatus, membersNeededForFull, @@ -502,8 +503,13 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { userId: user?.id, }); + const expiryStatus = groupExpiryStatus(currentGroup); + return { - groups: sortedGroups, + groups: censorGroupsIfOwnExpired({ + groups: sortedGroups, + ownGroupExpiryStatus: expiryStatus, + }), role: currentGroup ? currentGroup.role : ("PREVIEWER" as const), chatCode: currentGroup?.chatCode, lastUpdated: new Date().getTime(),