/** * @file app/(app)/servers/[serverId]/channels/[channelId]/page.tsx * @description Server channel chat page component handling authentication guards, parallel data fetching for server and messages, and rendering the channel layout. */ import { auth } from "@/auth"; import { redirect } from "next/navigation"; import { AppHeader } from "@/components/layout/AppHeader"; import { ChatInput } from "@/components/chat/ChatInput"; import { ChatMessages } from "@/components/chat/ChatMessages"; import { getChannelById } from "@/lib/services/channel.service"; import { getChannelMessages } from "@/lib/services/message.service"; import { getServerById } from "@/lib/services/server.service"; import { isValidUuid } from "@/lib/utils"; import { getUserFriendships } from "@/lib/services/friends.service"; import AppFooter from "@/components/layout/AppFooter"; /** Renders the channel chat view by validating parameters, checking user session, fetching channel data, friendships, and displaying headers, messages, and input controls. */ export default async function ChannelPage({ params, }: { params: Promise<{ serverId: string; channelId: string }>; }) { const { serverId, channelId } = await params; // 1. Check the UUID format for BOTH parameters if (!isValidUuid(serverId) || !isValidUuid(channelId)) { redirect("/"); } // 2. Auth Guard const session = await auth(); if (!session?.user?.id) { redirect("/login"); } // 3. Parallel Loading of Data const [server, channel, channelMessages, friendships] = await Promise.all([ getServerById(serverId), getChannelById(channelId), getChannelMessages(channelId), getUserFriendships(session.user.id), ]); if (!channel || !server) { redirect("/"); } return (