import type { Metadata } from "next"; import { getFollowersList, getFollowingList, getMe, getTopFriends, getUserProfile, getUserThoughts, Me, } from "@/lib/api"; interface ProfilePageProps { params: Promise<{ username: string }>; } export async function generateMetadata({ params, }: ProfilePageProps): Promise { const { username } = await params; const user = await getUserProfile(username, null).catch(() => null); if (!user) return { title: username }; const name = user.displayName || user.username; const description = user.bio || `Follow ${name} on Thoughts and across the Fediverse.`; return { title: `${name} (@${user.username})`, description, openGraph: { type: "profile", title: `${name} (@${user.username})`, description, images: user.avatarUrl ? [{ url: user.avatarUrl }] : [], }, twitter: { card: "summary", title: `${name} (@${user.username})`, description, images: user.avatarUrl ? [user.avatarUrl] : [], }, }; } import { UserAvatar } from "@/components/user-avatar"; import { Calendar, Settings } from "lucide-react"; import { Card } from "@/components/ui/card"; import { notFound } from "next/navigation"; import { cookies } from "next/headers"; import { FollowButton } from "@/components/follow-button"; import { TopFriends } from "@/components/top-friends"; import { buildThoughtThreads } from "@/lib/utils"; import { ThoughtThread } from "@/components/thought-thread"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { PendingRequests } from "@/components/federation/pending-requests"; interface ProfilePageProps { params: Promise<{ username: string }>; } export default async function ProfilePage({ params }: ProfilePageProps) { const { username } = await params; const token = (await cookies()).get("auth_token")?.value ?? null; const userProfilePromise = getUserProfile(username, token); const thoughtsPromise = getUserThoughts(username, token); const mePromise = token ? getMe(token) : Promise.resolve(null); const followersPromise = getFollowersList(username, token); const followingPromise = getFollowingList(username, token); const [ userResult, thoughtsResult, meResult, followersResult, followingResult, ] = await Promise.allSettled([ userProfilePromise, thoughtsPromise, mePromise, followersPromise, followingPromise, ]); if (userResult.status === "rejected") { notFound(); } const user = userResult.value; const me = meResult.status === "fulfilled" ? (meResult.value as Me) : null; const thoughts = thoughtsResult.status === "fulfilled" ? thoughtsResult.value.items : []; const thoughtThreads = buildThoughtThreads(thoughts); const followersCount = followersResult.status === "fulfilled" ? followersResult.value.total : 0; const followingCount = followingResult.status === "fulfilled" ? followingResult.value.total : 0; const isOwnProfile = me?.username === user.username; const isFollowing = user.isFollowedByViewer; const apiDomain = process.env.NEXT_PUBLIC_API_URL ? new URL(process.env.NEXT_PUBLIC_API_URL).hostname : null; const fediverseHandle = user.local && apiDomain ? `@${user.username}@${apiDomain}` : null; const authorDetails = new Map(); authorDetails.set(user.username, { avatarUrl: user.avatarUrl }); // Show who the profile owner follows (uses the already-fetched followingResult). const friends = followingResult.status === "fulfilled" ? followingResult.value.items.map((u) => u.username) : []; const topFriendsData = await getTopFriends(username, token).catch(() => ({ topFriends: [] })); const shouldDisplayTopFriends = topFriendsData.topFriends.length > 0; return (
{user.customCss && (