sendou.ink/app/features/friends/friends-utils.server.ts
2026-04-09 20:26:23 +03:00

34 lines
923 B
TypeScript

import { groupExpiryStatus } from "~/features/sendouq/core/groups";
import { SendouQ } from "~/features/sendouq/core/SendouQ.server";
import { FULL_GROUP_SIZE } from "~/features/sendouq/q-constants";
import { SENDOUQ_ACTIVITY_LABEL } from "./friends-constants";
export function resolveFriendActivity(
friendId: number,
tournamentName: string | null,
teamMemberCount: number | null,
tournamentMinTeamSize: number | null,
) {
const ownGroup = SendouQ.findOwnGroup(friendId);
if (
ownGroup &&
ownGroup.members.length < FULL_GROUP_SIZE &&
groupExpiryStatus(ownGroup.latestActionAt) !== "EXPIRED"
) {
return {
subtitle: SENDOUQ_ACTIVITY_LABEL,
badge: `${ownGroup.members.length}/${FULL_GROUP_SIZE}`,
};
}
if (tournamentName) {
return {
subtitle: tournamentName,
badge: `${teamMemberCount ?? 1}/${tournamentMinTeamSize ?? FULL_GROUP_SIZE}`,
};
}
return { subtitle: null, badge: null };
}