69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
/**
|
||
* Chat 状态机:事件联合
|
||
*
|
||
* 事件名与原 Dart ChatEvent 对齐。
|
||
*
|
||
* 历史:原本有 `ChatAuthStatusChanged`(chat 机器刷新 isGuest)—— 已删。
|
||
* 鉴权状态变化(loginStatus)由 <ChatAuthSync /> 通过 `useAuthState()` 订阅,
|
||
* chat 机器不感知鉴权。
|
||
*
|
||
* 鉴权生命周期事件(本轮新增):
|
||
* - `ChatGuestLogin`:游客进入 /chat —— 拉服务器端首屏
|
||
* - `ChatUserLogin`:其他登录用户进入 /chat —— 拉服务器端首屏
|
||
* - `ChatLogout`:正式登录用户登出 —— 清消息
|
||
*
|
||
* 设计:所有历史 / 配额相关副作用全部通过派发事件给 chat 机器处理,
|
||
* chat-screen 不直接读 AuthStorage(除 token 取值)。
|
||
*/
|
||
import type { PendingChatUnlockKind } from "@/lib/navigation/chat_unlock_session";
|
||
import type { ChatLockType } from "@/data/schemas/chat";
|
||
import type { PendingChatPromotion } from "@/data/storage/navigation";
|
||
|
||
export type ChatEvent =
|
||
// 鉴权生命周期(登录态变化后由 ChatAuthSync 派)
|
||
| { type: "ChatGuestLogin" }
|
||
| { type: "ChatUserLogin"; token: string }
|
||
| { type: "ChatLogout" }
|
||
| {
|
||
type: "ChatLocalHistoryLoaded";
|
||
output: import("./chat-history-sync").LocalHistorySnapshotOutput;
|
||
}
|
||
| {
|
||
type: "ChatNetworkHistoryLoaded";
|
||
output: import("./chat-history-sync").NetworkHistorySyncOutput;
|
||
}
|
||
| { type: "ChatHistoryLoadFailed"; error: unknown }
|
||
| { type: "ChatLoadMoreHistoryRequested" }
|
||
| {
|
||
type: "ChatOlderHistoryLoaded";
|
||
output: import("./machine/actors/history").LoadMoreHistoryOutput;
|
||
}
|
||
| { type: "ChatOlderHistoryLoadFailed"; error: unknown }
|
||
// 业务事件
|
||
| { type: "ChatSendMessage"; content: string }
|
||
| { type: "ChatSendImage"; imageBase64: string }
|
||
| {
|
||
type: "ChatPromotionInjected";
|
||
promotion: PendingChatPromotion;
|
||
messageId?: string;
|
||
}
|
||
| { type: "ChatPromotionCleared" }
|
||
| {
|
||
type: "ChatUnlockMessageRequested";
|
||
messageId: string;
|
||
remoteMessageId?: string;
|
||
kind: PendingChatUnlockKind;
|
||
lockType?: ChatLockType;
|
||
clientLockId?: string;
|
||
}
|
||
| { type: "ChatUnlockPaywallNavigationConsumed" }
|
||
| { type: "ChatPaymentSucceeded" }
|
||
| { type: "ChatUnlockHistoryConfirmed" }
|
||
| { type: "ChatUnlockHistoryDismissed" }
|
||
| { type: "ChatQueuedSendStarted" }
|
||
| {
|
||
type: "ChatQueuedHttpDone";
|
||
output: import("./helper/send-state").HttpSendOutput;
|
||
}
|
||
| { type: "ChatQueuedSendError"; content: string; errorMessage: string };
|