43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import "server-only";
|
|
import { admin, required } from "./supabase";
|
|
import type { ProfileAppearance } from "@/shared/profile-appearance";
|
|
|
|
export async function multiplayerAppearance(room: string, ids: string[]) {
|
|
const db = admin(),
|
|
result = new Map<string, { name: string; appearance: ProfileAppearance }>();
|
|
if (!ids.length) return result;
|
|
const players = required(
|
|
await db
|
|
.from("multiplayer_players")
|
|
.select("id,account_id")
|
|
.eq("room_id", room)
|
|
.in("id", [...new Set(ids)]),
|
|
);
|
|
const accounts = [
|
|
...new Set(
|
|
players.flatMap((player) =>
|
|
player.account_id ? [player.account_id] : [],
|
|
),
|
|
),
|
|
];
|
|
if (!accounts.length) return result;
|
|
const profiles = required(
|
|
await db
|
|
.from("profiles")
|
|
.select(
|
|
"id,display_name,name_glow,glow_color,role,bug_finder,custom_prefix,custom_prefix_icon",
|
|
)
|
|
.in("id", accounts),
|
|
);
|
|
for (const player of players) {
|
|
const profile = profiles.find(
|
|
(profile) => profile.id === player.account_id,
|
|
);
|
|
if (profile) {
|
|
const { id, display_name, ...appearance } = profile;
|
|
result.set(player.id, { name: display_name, appearance });
|
|
}
|
|
}
|
|
return result;
|
|
}
|