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
+26 -5
View File
@@ -7,10 +7,11 @@ import Image from "next/image";
import { useAuthState } from "@/stores/auth/auth-context"; import { useAuthState } from "@/stores/auth/auth-context";
import type { LoginStatus } from "@/data/dto/auth"; import type { LoginStatus } from "@/data/dto/auth";
import { AppStorage } from "@/data/storage/app/app_storage";
import { AuthStorage } from "@/data/storage/auth/auth_storage"; import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { UserStorage } from "@/data/storage/user/user_storage"; import { UserStorage } from "@/data/storage/user/user_storage";
import { useChatState } from "@/stores/chat/chat-context"; 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 { ROUTE_BUILDERS, ROUTES } from "@/router/routes";
import { MobileShell } from "@/app/_components/core"; import { MobileShell } from "@/app/_components/core";
@@ -56,16 +57,36 @@ export function ChatScreen() {
useEffect(() => { useEffect(() => {
if (!authState.hasInitialized || authState.isLoading) return; if (!authState.hasInitialized || authState.isLoading) return;
if (authState.loginStatus !== "facebook") return; const isDev = AppEnvUtil.isDevelopment();
const canTriggerPrompt =
isDev ||
(authState.loginStatus === "facebook" && BrowserDetector.isInAppBrowser());
if (!canTriggerPrompt) return;
let mounted = true;
let timer: number | undefined;
const init = async () => {
if (externalBrowserPromptShownRef.current) return; if (externalBrowserPromptShownRef.current) return;
if (!BrowserDetector.isInAppBrowser()) return;
const today = todayString();
const canShowResult = await AppStorage.canShowExternalBrowserDialog(today);
if (!mounted || !canShowResult.success || !canShowResult.data) return;
externalBrowserPromptShownRef.current = true; externalBrowserPromptShownRef.current = true;
const timer = window.setTimeout(() => { timer = window.setTimeout(() => {
if (!mounted) return;
setShowExternalBrowserDialog(true); setShowExternalBrowserDialog(true);
void AppStorage.recordExternalBrowserDialogShown(today);
}, 3000); }, 3000);
};
return () => window.clearTimeout(timer); void init();
return () => {
mounted = false;
if (timer !== undefined) window.clearTimeout(timer);
};
}, [ }, [
authState.hasInitialized, authState.hasInitialized,
authState.isLoading, authState.isLoading,
+20
View File
@@ -30,6 +30,26 @@ export class AppStorage {
return SpAsyncUtil.setString(StorageKeys.lastPwaDialogShown, todayString); return SpAsyncUtil.setString(StorageKeys.lastPwaDialogShown, todayString);
} }
// ---- external browser dialog ----
static async canShowExternalBrowserDialog(
todayString: string,
): Promise<ResultT<boolean>> {
return AppStorage.canReportKey(
StorageKeys.lastExternalBrowserDialogShown,
todayString,
);
}
static recordExternalBrowserDialogShown(
todayString: string,
): Promise<ResultT<void>> {
return SpAsyncUtil.setString(
StorageKeys.lastExternalBrowserDialogShown,
todayString,
);
}
// ---- PWA event reporting ---- // ---- PWA event reporting ----
static canReportPwaEvent(todayString: string): Promise<ResultT<boolean>> { static canReportPwaEvent(todayString: string): Promise<ResultT<boolean>> {
+1
View File
@@ -26,6 +26,7 @@ export const StorageKeys = {
// pwa / app info // pwa / app info
lastPwaDialogShown: "last_pwa_dialog_shown", lastPwaDialogShown: "last_pwa_dialog_shown",
lastExternalBrowserDialogShown: "last_external_browser_dialog_shown",
lastPwaEventReported: "last_pwa_event_reported", lastPwaEventReported: "last_pwa_event_reported",
lastAppInfoReported: "last_app_info_reported", lastAppInfoReported: "last_app_info_reported",
} as const; } as const;