fix(chat): limit external browser prompt daily

This commit is contained in:
2026-06-18 14:23:31 +08:00
parent d190de4dda
commit cf54bc742d
3 changed files with 51 additions and 9 deletions
+30 -9
View File
@@ -7,10 +7,11 @@ import Image from "next/image";
import { useAuthState } from "@/stores/auth/auth-context";
import type { LoginStatus } from "@/data/dto/auth";
import { AppStorage } from "@/data/storage/app/app_storage";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { UserStorage } from "@/data/storage/user/user_storage";
import { useChatState } from "@/stores/chat/chat-context";
import { AppEnvUtil, BrowserDetector, UrlLauncherUtil } from "@/utils";
import { AppEnvUtil, BrowserDetector, todayString, UrlLauncherUtil } from "@/utils";
import { ROUTE_BUILDERS, ROUTES } from "@/router/routes";
import { MobileShell } from "@/app/_components/core";
@@ -56,16 +57,36 @@ export function ChatScreen() {
useEffect(() => {
if (!authState.hasInitialized || authState.isLoading) return;
if (authState.loginStatus !== "facebook") return;
if (externalBrowserPromptShownRef.current) return;
if (!BrowserDetector.isInAppBrowser()) return;
const isDev = AppEnvUtil.isDevelopment();
const canTriggerPrompt =
isDev ||
(authState.loginStatus === "facebook" && BrowserDetector.isInAppBrowser());
if (!canTriggerPrompt) return;
externalBrowserPromptShownRef.current = true;
const timer = window.setTimeout(() => {
setShowExternalBrowserDialog(true);
}, 3000);
let mounted = true;
let timer: number | undefined;
return () => window.clearTimeout(timer);
const init = async () => {
if (externalBrowserPromptShownRef.current) return;
const today = todayString();
const canShowResult = await AppStorage.canShowExternalBrowserDialog(today);
if (!mounted || !canShowResult.success || !canShowResult.data) return;
externalBrowserPromptShownRef.current = true;
timer = window.setTimeout(() => {
if (!mounted) return;
setShowExternalBrowserDialog(true);
void AppStorage.recordExternalBrowserDialogShown(today);
}, 3000);
};
void init();
return () => {
mounted = false;
if (timer !== undefined) window.clearTimeout(timer);
};
}, [
authState.hasInitialized,
authState.isLoading,