import Link from "next/link"; import { redirect } from "next/navigation"; import { ContentCard, EmptyState, OnlineBadge } from "@/components/public/ui"; import { auth } from "@/lib/auth"; import { avatarImageUrl } from "@/lib/format"; import { prisma } from "@/lib/prisma"; import { siteSettings } from "@/lib/services/site-settings"; export const dynamic = "force-dynamic"; export default async function FriendsPage() { const session = await auth(); if (!session?.user?.id) redirect("/login"); const userId = Number(session.user.id); // Friendships are bidirectional and stored once: the session user can appear // as either user_one_id or user_two_id, with the *other* column being the // friend. Read both directions, then dedupe the friend ids. const friendships = await prisma.messengerFriendships .findMany({ where: { OR: [{ userOneId: userId }, { userTwoId: userId }], }, select: { userOneId: true, userTwoId: true }, }) .catch(() => []); const friendIds = Array.from( new Set( friendships .map((f) => (f.userOneId === userId ? f.userTwoId : f.userOneId)) .filter((id) => id && id !== userId), ), ); const [friends, imagerBase] = await Promise.all([ friendIds.length ? prisma.user .findMany({ where: { id: { in: friendIds } }, select: { id: true, username: true, look: true, motto: true, online: true }, orderBy: { username: "asc" }, }) .catch(() => []) : Promise.resolve([]), siteSettings.get( "habbo_imaging_url", "https://www.habbo.com/habbo-imaging/avatarimage", ), ]); return (
{friends.length === 0 ? ( Add friends in the hotel and they will show up here. ) : (
{friends.map((friend) => { const avatar = avatarImageUrl(imagerBase ?? "", friend.look, { size: "s", headOnly: true, }); const isOnline = friend.online === "1"; return (
{/* eslint-disable-next-line @next/next/no-img-element */} {`${friend.username}

{friend.username}

{friend.motto || "No motto"}

); })}
)}
); }