锁定视口避免双滚动;消息列表改用 flex-col-reverse,SSR/无 JS 默认贴最新消息。 Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
957 B
TypeScript
33 lines
957 B
TypeScript
import { redirect } from "next/navigation";
|
|
import { cookies } from "next/headers";
|
|
import type { Metadata } from "next";
|
|
import { authCookieHeader } from "@/lib/cookies";
|
|
import { getMeCached } from "@/lib/serverData";
|
|
import { fetchChatRooms } from "@/lib/api";
|
|
import ChatShell from "./ChatShell";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "消息",
|
|
description: "私聊与群聊,实时交流。",
|
|
};
|
|
|
|
export default async function ChatListPage() {
|
|
const cookie = authCookieHeader(await cookies());
|
|
const me = await getMeCached(cookie || undefined);
|
|
if (!me.user) {
|
|
redirect(`/login?redirect=${encodeURIComponent("/chat")}`);
|
|
}
|
|
|
|
let rooms: Awaited<ReturnType<typeof fetchChatRooms>>["rooms"] = [];
|
|
try {
|
|
const data = await fetchChatRooms(1, 50, "", cookie, "joined");
|
|
rooms = data.rooms || [];
|
|
} catch {
|
|
rooms = [];
|
|
}
|
|
|
|
return (
|
|
<ChatShell meId={me.user.id} initialRooms={rooms} activeRoomId={null} />
|
|
);
|
|
}
|