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,
+20
View File
@@ -30,6 +30,26 @@ export class AppStorage {
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 ----
static canReportPwaEvent(todayString: string): Promise<ResultT<boolean>> {
+1
View File
@@ -26,6 +26,7 @@ export const StorageKeys = {
// pwa / app info
lastPwaDialogShown: "last_pwa_dialog_shown",
lastExternalBrowserDialogShown: "last_external_browser_dialog_shown",
lastPwaEventReported: "last_pwa_event_reported",
lastAppInfoReported: "last_app_info_reported",
} as const;