import Image from "next/image"; import Link from "next/link"; import { getTranslations } from "next-intl/server"; import { avatarImageUrl, excerpt } from "@/lib/format"; import { prisma } from "@/lib/prisma"; import { siteSettings } from "@/lib/services/site-settings"; interface UserViewProps { userId: number; username: string; look: string; } export default async function UserView({ userId, username, look, }: UserViewProps) { const t = await getTranslations("pages.home"); const hotelName = (await siteSettings.get("hotel_name", "Atom")) ?? "Atom"; const imager = (await siteSettings.get( "habbo_imaging_url", "https://www.habbo.com/habbo-imaging/avatarimage", )) ?? ""; let onlineFriends: Array<{ username: string; look: string }> = []; try { const friendships = await prisma.messengerFriendships.findMany({ where: { OR: [{ userOneId: userId }, { userTwoId: userId }] }, select: { userOneId: true, userTwoId: true }, }); const friendIds = friendships.map((f) => f.userOneId === userId ? f.userTwoId : f.userOneId, ); if (friendIds.length > 0) { onlineFriends = await prisma.user.findMany({ where: { id: { in: friendIds }, online: "1" }, take: 10, select: { username: true, look: true }, }); } } catch {} const [latestArticle] = await prisma.websiteArticles .findMany({ orderBy: { createdAt: "desc" }, take: 1, select: { slug: true, title: true, shortStory: true, image: true }, }) .catch(() => []); return (
{t("noFriendsOnline")}
) : ( onlineFriends.map((f) => ({excerpt(latestArticle.shortStory, 100)}
)}