mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-05 20:56:13 -05:00
Move some setMetadata to actions
This commit is contained in:
parent
aeb7667638
commit
4299a2a517
|
|
@ -1,13 +1,11 @@
|
|||
import type { LoaderFunctionArgs } from "react-router";
|
||||
import { getUser } from "~/features/auth/core/user.server";
|
||||
import * as ChatSystemMessage from "~/features/chat/ChatSystemMessage.server";
|
||||
import { SendouQ } from "~/features/sendouq/core/SendouQ.server";
|
||||
import * as PrivateUserNoteRepository from "~/features/sendouq/PrivateUserNoteRepository.server";
|
||||
import { reportedWeaponsToArrayOfArrays } from "~/features/sendouq-match/core/reported-weapons.server";
|
||||
import * as ReportedWeaponRepository from "~/features/sendouq-match/ReportedWeaponRepository.server";
|
||||
import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server";
|
||||
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
||||
import { sendouQMatchPage } from "~/utils/urls";
|
||||
import { qMatchPageParamsSchema } from "../q-match-schemas";
|
||||
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
|
|
@ -34,21 +32,6 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|||
? await ReportedWeaponRepository.findByMatchId(matchId)
|
||||
: null;
|
||||
|
||||
const participantIds = [
|
||||
...matchUnmapped.groupAlpha.members,
|
||||
...matchUnmapped.groupBravo.members,
|
||||
].map((m) => m.id);
|
||||
if (match.chatCode && !match.isLocked) {
|
||||
ChatSystemMessage.setMetadata({
|
||||
chatCode: match.chatCode,
|
||||
header: `Match #${matchId}`,
|
||||
subtitle: "SendouQ",
|
||||
url: sendouQMatchPage(matchId),
|
||||
participantUserIds: participantIds,
|
||||
expiresAfter: { hours: 2 },
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
match,
|
||||
reportedWeapons: match.reportedAt
|
||||
|
|
@ -60,8 +43,9 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|||
})
|
||||
: null,
|
||||
rawReportedWeapons,
|
||||
// xxx: as a safety measure, it'd be good to send chat code also when user is in the match
|
||||
chatCode:
|
||||
user?.roles.includes("STAFF") && !participantIds.includes(user.id)
|
||||
user?.roles.includes("STAFF") && !matchUsers.includes(user.id)
|
||||
? match.chatCode
|
||||
: null,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { refreshSendouQInstance, SendouQ } from "../core/SendouQ.server";
|
|||
import * as PrivateUserNoteRepository from "../PrivateUserNoteRepository.server";
|
||||
import { lookingSchema } from "../q-schemas.server";
|
||||
import { resolveFutureMatchModes } from "../q-utils";
|
||||
import { SendouQError } from "../q-utils.server";
|
||||
import { SendouQError, setGroupChatMetadata } from "../q-utils.server";
|
||||
|
||||
// this function doesn't throw normally because we are assuming
|
||||
// if there is a validation error the user saw stale data
|
||||
|
|
@ -128,6 +128,15 @@ export const action: ActionFunction = async ({ request }) => {
|
|||
ChatSystemMessage.removeRoom(theirGroup.chatCode);
|
||||
}
|
||||
|
||||
const survivingGroup =
|
||||
SendouQ.findUncensoredGroupById(survivingGroupId);
|
||||
if (survivingGroup?.chatCode) {
|
||||
setGroupChatMetadata({
|
||||
chatCode: survivingGroup.chatCode,
|
||||
members: survivingGroup.members,
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "MATCH_UP": {
|
||||
|
|
@ -169,6 +178,20 @@ export const action: ActionFunction = async ({ request }) => {
|
|||
|
||||
await refreshSendouQInstance();
|
||||
|
||||
if (createdMatch.chatCode) {
|
||||
ChatSystemMessage.setMetadata({
|
||||
chatCode: createdMatch.chatCode,
|
||||
header: `Match #${createdMatch.id}`,
|
||||
subtitle: "SendouQ",
|
||||
url: sendouQMatchPage(createdMatch.id),
|
||||
participantUserIds: [
|
||||
...ownGroup.members.map((m) => m.id),
|
||||
...theirGroup.members.map((m) => m.id),
|
||||
],
|
||||
expiresAfter: { hours: 2 },
|
||||
});
|
||||
}
|
||||
|
||||
if (ownGroup.chatCode && theirGroup.chatCode) {
|
||||
ChatSystemMessage.send([
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { refreshSendouQInstance, SendouQ } from "../core/SendouQ.server";
|
|||
import { JOIN_CODE_SEARCH_PARAM_KEY } from "../q-constants";
|
||||
import { frontPageSchema } from "../q-schemas.server";
|
||||
import { userCanJoinQueueAt } from "../q-utils";
|
||||
import { setGroupChatMetadata } from "../q-utils.server";
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
const user = requireUser();
|
||||
|
|
@ -36,6 +37,14 @@ export const action: ActionFunction = async ({ request }) => {
|
|||
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const createdGroup = SendouQ.findOwnGroup(user.id);
|
||||
if (createdGroup?.chatCode) {
|
||||
setGroupChatMetadata({
|
||||
chatCode: createdGroup.chatCode,
|
||||
members: createdGroup.members,
|
||||
});
|
||||
}
|
||||
|
||||
return redirect(
|
||||
data.direct === "true" ? SENDOUQ_LOOKING_PAGE : SENDOUQ_PREPARING_PAGE,
|
||||
);
|
||||
|
|
@ -61,6 +70,14 @@ export const action: ActionFunction = async ({ request }) => {
|
|||
|
||||
await refreshSendouQInstance();
|
||||
|
||||
const joinedGroup = SendouQ.findOwnGroup(user.id);
|
||||
if (joinedGroup?.chatCode) {
|
||||
setGroupChatMetadata({
|
||||
chatCode: joinedGroup.chatCode,
|
||||
members: joinedGroup.members,
|
||||
});
|
||||
}
|
||||
|
||||
return redirect(
|
||||
groupInvitedTo.status === "PREPARING"
|
||||
? SENDOUQ_PREPARING_PAGE
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import type { LoaderFunctionArgs } from "react-router";
|
||||
import { requireUser } from "~/features/auth/core/user.server";
|
||||
import * as ChatSystemMessage from "~/features/chat/ChatSystemMessage.server";
|
||||
import * as SQGroupRepository from "~/features/sendouq/SQGroupRepository.server";
|
||||
import { cachedStreams } from "~/features/sendouq-streams/core/streams.server";
|
||||
import { SENDOUQ_LOOKING_PAGE } from "~/utils/urls";
|
||||
import { groupExpiryStatus } from "../core/groups";
|
||||
import { SendouQ } from "../core/SendouQ.server";
|
||||
import * as PrivateUserNoteRepository from "../PrivateUserNoteRepository.server";
|
||||
|
|
@ -34,19 +32,6 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (ownGroup?.chatCode) {
|
||||
const memberIds = ownGroup.members.map((m: { id: number }) => m.id);
|
||||
|
||||
ChatSystemMessage.setMetadata({
|
||||
chatCode: ownGroup.chatCode,
|
||||
header: `Group (${memberIds.length}/4)`,
|
||||
subtitle: "SendouQ",
|
||||
url: SENDOUQ_LOOKING_PAGE,
|
||||
participantUserIds: memberIds,
|
||||
expiresAfter: { hours: 2 },
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
groups:
|
||||
ownGroup && groupExpiryStatus(ownGroup.latestActionAt) === "EXPIRED"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { redirect } from "react-router";
|
||||
import * as ChatSystemMessage from "~/features/chat/ChatSystemMessage.server";
|
||||
import { TIERS } from "~/features/mmr/mmr-constants";
|
||||
import type { TieredSkill } from "~/features/mmr/tiered.server";
|
||||
import {
|
||||
|
|
@ -46,6 +47,20 @@ export function sqRedirectIfNeeded({
|
|||
throw redirect(newLocation);
|
||||
}
|
||||
|
||||
export function setGroupChatMetadata(group: {
|
||||
chatCode: string;
|
||||
members: { id: number }[];
|
||||
}) {
|
||||
ChatSystemMessage.setMetadata({
|
||||
chatCode: group.chatCode,
|
||||
header: `Group (${group.members.length}/4)`,
|
||||
subtitle: "SendouQ",
|
||||
url: SENDOUQ_LOOKING_PAGE,
|
||||
participantUserIds: group.members.map((m) => m.id),
|
||||
expiresAfter: { hours: 2 },
|
||||
});
|
||||
}
|
||||
|
||||
const allTiersOrdered = TIERS.flatMap((t) => [
|
||||
{ name: t.name, isPlus: true },
|
||||
{ name: t.name, isPlus: false },
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user