refactor(chat): remove redundant auth state management from ChatScreen documentation
refactor(chat): update guest chat quota logic to use isProduction utility fix(user): add TODO for user initialization event on login status change
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
/**
|
||||
* ChatScreen 编排层
|
||||
*
|
||||
* 职责(本文件):
|
||||
* - 订阅 auth 状态机(loginStatus)—— 派生 isGuest / 派鉴权生命周期事件给 chat 机器
|
||||
* - 屏幕生命周期事件(init / visible / invisible)
|
||||
* - 不直接管理 WebSocket / 不直接读 AuthStorage(除 token 取值)
|
||||
*
|
||||
* 子组件职责:
|
||||
* - ChatHeader:顶部栏(游客 banner / 菜单按钮)
|
||||
* - ChatArea:消息列表
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
type GuestChatQuotaInput,
|
||||
type GuestChatQuotaData,
|
||||
} from "@/data/schemas/chat/guest_chat_quota";
|
||||
import { isProduction } from "@/utils/app-env";
|
||||
|
||||
export class GuestChatQuota {
|
||||
// 静态常量
|
||||
@@ -13,7 +14,7 @@ export class GuestChatQuota {
|
||||
static readonly maxQuotaPerDayTest = 4;
|
||||
|
||||
static readonly defaultTotalQuota = 50;
|
||||
static readonly defaultTotalQuotaDev = 5;
|
||||
static readonly defaultTotalQuotaTest = 5;
|
||||
static readonly quotaExhausted = 0;
|
||||
|
||||
declare readonly remaining: number;
|
||||
@@ -40,29 +41,22 @@ export class GuestChatQuota {
|
||||
return GuestChatQuota.quotaExhausted;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否处于开发环境
|
||||
*/
|
||||
static get isDevelopment(): boolean {
|
||||
return process.env.NODE_ENV !== "production";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前环境的每日最大配额
|
||||
*/
|
||||
static get threshold(): number {
|
||||
return GuestChatQuota.isDevelopment
|
||||
? GuestChatQuota.maxQuotaPerDayTest
|
||||
: GuestChatQuota.maxQuotaPerDay;
|
||||
return isProduction()
|
||||
? GuestChatQuota.maxQuotaPerDay
|
||||
: GuestChatQuota.maxQuotaPerDayTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前环境的总配额默认值
|
||||
*/
|
||||
static get totalQuotaDefault(): number {
|
||||
return GuestChatQuota.isDevelopment
|
||||
? GuestChatQuota.defaultTotalQuotaDev
|
||||
: GuestChatQuota.defaultTotalQuota;
|
||||
return isProduction()
|
||||
? GuestChatQuota.defaultTotalQuota
|
||||
: GuestChatQuota.defaultTotalQuotaTest;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ export function UserAuthSync() {
|
||||
const userDispatch = useUserDispatch();
|
||||
const lastInitializedStatusRef = useRef<string | null>(null);
|
||||
|
||||
//TODO 在测位栏界面监听变化,监听登录状态的变化若发生变化,则需要分发 user init 事件
|
||||
useEffect(() => {
|
||||
if (loginStatus === "notLoggedIn" || loginStatus === "guest") {
|
||||
lastInitializedStatusRef.current = null;
|
||||
|
||||
Reference in New Issue
Block a user