refactor(chat): decouple chat state from auth and gate quota alerts to guests

- Remove ChatAuthStatusChanged dispatch from auth login flow; chat screen now subscribes directly to auth state machine (loginStatus) to derive isGuest and drive WS lifecycle
- Gate quota-exceeded and warning dialogs to guests only (non-guests have no message limit)
- Dispatch ChatLoadMoreHistory for non-guest initial load vs ChatInit for guests
- Fix AppConstants import path from @/core/constants/app_constants to @/core/app_constants
- Add defensive isGuest checks in quota effects to prevent non-guest quota triggers
This commit is contained in:
2026-06-11 18:31:08 +08:00
parent e3d069e49f
commit ed4ccddae3
11 changed files with 233 additions and 63 deletions
@@ -8,7 +8,6 @@ import { MobileShell } from "@/app/_components/core/mobile-shell";
import { SettingsSection } from "@/app/_components/core/settings-section";
import { useUserDispatch, useUserState } from "@/stores/user/user-context";
import { useAuthDispatch } from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { ROUTES } from "@/router/routes";
import type { UserView } from "@/models/user/user";
@@ -23,7 +22,6 @@ import styles from "./sidebar-screen.module.css";
export function SidebarScreen() {
const user = useUserState();
const userDispatch = useUserDispatch();
const chatDispatch = useChatDispatch();
const authDispatch = useAuthDispatch();
const router = useRouter();
@@ -34,17 +32,18 @@ export function SidebarScreen() {
// 等价 Dart: BlocConsumer<UserBloc> 的 listenerprofile_view.dart:24-34
// 仅在 currentUser 由非 null 跳到 null 时触发清理
// 注:chat 机器**不**再需要 `ChatAuthStatusChanged` 通知(已**删**)—— chat-screen
// 通过 `useAuthState()` 主动订阅 loginStatus;这里只需重置 auth + 跳 /chat
const prevUserRef = useRef<UserView | null>(user.currentUser);
useEffect(() => {
const wasLoggedIn = prevUserRef.current != null;
const isNowLoggedOut = user.currentUser == null;
prevUserRef.current = user.currentUser;
if (wasLoggedIn && isNowLoggedOut) {
chatDispatch({ type: "ChatAuthStatusChanged" });
authDispatch({ type: "AuthReset" });
router.replace(ROUTES.chat);
}
}, [user.currentUser, chatDispatch, authDispatch, router]);
}, [user.currentUser, authDispatch, router]);
return (
<MobileShell>