feat: 后台增加开放消息开关
关闭后前台隐藏私聊/群聊入口并由后端拦截;同步去掉公告页重复计数胶囊。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import { onDocumentVisible } from "@/lib/visibilityReconcile";
|
||||
import NotificationBell from "./NotificationBell";
|
||||
import ThemeToggle from "./ThemeToggle";
|
||||
import Avatar from "./Avatar";
|
||||
import { useAllowMessages } from "./MessagesPolicyProvider";
|
||||
|
||||
export default function Header({
|
||||
initialUser,
|
||||
@@ -47,6 +48,7 @@ export default function Header({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const allowMessages = useAllowMessages();
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
// 登录态以 SSR 直出为初始值,F5 无切换闪动;router.refresh() 后随 props 校正
|
||||
const [user, setUser] = useState<User | null>(initialUser);
|
||||
@@ -105,7 +107,7 @@ export default function Header({
|
||||
|
||||
// 实时未读:chat:unread 推送给所有成员(含未打开会话页);在当前会话页则忽略
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
if (!user || !allowMessages) return;
|
||||
const off = realtime.on<RtChatUnreadData>(RT_CHAT_UNREAD, (data) => {
|
||||
if (!data || typeof data.room_id !== "number") return;
|
||||
if (pathname === `/chat/${data.room_id}`) return;
|
||||
@@ -113,11 +115,11 @@ export default function Header({
|
||||
setChatUnread((c) => Math.max(0, c + delta));
|
||||
});
|
||||
return off;
|
||||
}, [user, pathname]);
|
||||
}, [user, pathname, allowMessages]);
|
||||
|
||||
// 会话内已读 / 回前台:合并对账(短时间多次 markRead 只打一次 summary)
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
if (!user || !allowMessages) return;
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const pullSummary = () => {
|
||||
apiChatUnreadSummary()
|
||||
@@ -135,7 +137,7 @@ export default function Header({
|
||||
window.removeEventListener("j13-chat-unread-sync", onSync);
|
||||
offVisible();
|
||||
};
|
||||
}, [user]);
|
||||
}, [user, allowMessages]);
|
||||
|
||||
const handleSearch = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -271,7 +273,7 @@ export default function Header({
|
||||
className={`${iconBtn} hidden lg:inline-flex`}
|
||||
style={iconBtnStyle}
|
||||
/>
|
||||
{user && (
|
||||
{user && allowMessages && (
|
||||
<Link
|
||||
href="/chat"
|
||||
prefetch={false}
|
||||
@@ -359,7 +361,7 @@ export default function Header({
|
||||
<div className="flex flex-col">
|
||||
<MobileLink href="/" active={pathname === "/"}>首页</MobileLink>
|
||||
{user && <MobileLink href="/compose">发帖</MobileLink>}
|
||||
{user && (
|
||||
{user && allowMessages && (
|
||||
<MobileLink href="/chat" active={pathname?.startsWith("/chat") ?? false}>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<MessageSquare size={15} /> 消息
|
||||
|
||||
Reference in New Issue
Block a user