refactor(chat): clean stale mocks and external browser helpers
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
"use client";
|
||||
|
||||
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 { ROUTE_BUILDERS, ROUTES } from "@/router/routes";
|
||||
import { AppEnvUtil, BrowserDetector, todayString, UrlLauncherUtil } from "@/utils";
|
||||
import { ROUTE_BUILDERS } from "@/router/routes";
|
||||
import { AppEnvUtil, BrowserDetector } from "@/utils";
|
||||
|
||||
export interface ExternalBrowserPromptState {
|
||||
hasInitialized: boolean;
|
||||
@@ -33,51 +30,6 @@ export function shouldStartExternalBrowserPrompt({
|
||||
);
|
||||
}
|
||||
|
||||
export async function resolveExternalBrowserPromptEligibility(): Promise<{
|
||||
canShow: boolean;
|
||||
today: string;
|
||||
}> {
|
||||
const today = todayString();
|
||||
const result = await AppStorage.canShowExternalBrowserDialog(today);
|
||||
return {
|
||||
canShow: result.success && result.data,
|
||||
today,
|
||||
};
|
||||
}
|
||||
|
||||
export function recordExternalBrowserPromptShown(today: string): Promise<unknown> {
|
||||
return AppStorage.recordExternalBrowserDialogShown(today);
|
||||
}
|
||||
|
||||
export async function openChatInExternalBrowser(): Promise<void> {
|
||||
const authStorage = AuthStorage.getInstance();
|
||||
const userStorage = UserStorage.getInstance();
|
||||
const [deviceIdR, facebookIdR, avatarUrlR] = await Promise.all([
|
||||
authStorage.getDeviceId(),
|
||||
authStorage.getFacebookId(),
|
||||
userStorage.getAvatarUrl(),
|
||||
]);
|
||||
|
||||
const deviceId = deviceIdR.success ? deviceIdR.data : null;
|
||||
const facebookId = facebookIdR.success ? facebookIdR.data : null;
|
||||
const avatarUrl = avatarUrlR.success ? avatarUrlR.data : null;
|
||||
|
||||
if (deviceId && facebookId) {
|
||||
UrlLauncherUtil.openUrlWithExternalBrowser(
|
||||
ROUTE_BUILDERS.chatDeviceId(deviceId),
|
||||
{
|
||||
queryParams: {
|
||||
fbid: facebookId,
|
||||
...(avatarUrl ? { avatarUrl } : {}),
|
||||
},
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
UrlLauncherUtil.openUrlWithExternalBrowser(ROUTES.splash);
|
||||
}
|
||||
|
||||
export function getChatPaywallSubscriptionUrl(): string {
|
||||
return ROUTE_BUILDERS.subscription("vip", {
|
||||
returnTo: "chat",
|
||||
|
||||
@@ -7,6 +7,11 @@ import { useRouter } from "next/navigation";
|
||||
import { useAuthState } from "@/stores/auth/auth-context";
|
||||
import { useChatDispatch, useChatState } from "@/stores/chat/chat-context";
|
||||
import { useUserState } from "@/stores/user/user-context";
|
||||
import {
|
||||
openChatInExternalBrowser,
|
||||
recordExternalBrowserPromptShown,
|
||||
resolveExternalBrowserPromptEligibility,
|
||||
} from "@/lib/chat/chat_external_browser";
|
||||
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
|
||||
@@ -25,9 +30,6 @@ import {
|
||||
getChatPaywallNavigationUrl,
|
||||
getInsufficientCreditsSubscriptionType,
|
||||
isChatDevelopmentEnvironment,
|
||||
openChatInExternalBrowser,
|
||||
recordExternalBrowserPromptShown,
|
||||
resolveExternalBrowserPromptEligibility,
|
||||
shouldStartExternalBrowserPrompt,
|
||||
} from "./chat-screen.helpers";
|
||||
import styles from "./components/chat-screen.module.css";
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"success": true,
|
||||
"data": {
|
||||
"reply": "",
|
||||
"audioUrl": "",
|
||||
"messageId": "msg_blocked_daily_001",
|
||||
"isGuest": false,
|
||||
"timestamp": 1782180665000,
|
||||
"image": {
|
||||
"type": null,
|
||||
"url": null
|
||||
},
|
||||
"lockDetail": {
|
||||
"locked": true,
|
||||
"showContent": false,
|
||||
"showUpgrade": true,
|
||||
"reason": "daily_limit",
|
||||
"hint": "免费消息额度已用完,开通会员后可以继续聊天。",
|
||||
"detail": {
|
||||
"type": "daily_msg_limit",
|
||||
"usedToday": 20,
|
||||
"limit": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"success": true,
|
||||
"data": {
|
||||
"reply": "",
|
||||
"audioUrl": "",
|
||||
"messageId": "",
|
||||
"isGuest": true,
|
||||
"timestamp": 1782197944984,
|
||||
"image": {
|
||||
"type": null,
|
||||
"url": null
|
||||
},
|
||||
"lockDetail": {
|
||||
"locked": true,
|
||||
"showContent": false,
|
||||
"showUpgrade": true,
|
||||
"reason": "daily_limit",
|
||||
"hint": "Log in to get more free chat messages.",
|
||||
"detail": {
|
||||
"type": "daily_msg_limit",
|
||||
"usedToday": 5,
|
||||
"limit": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"success": true,
|
||||
"data": {
|
||||
"unlocked": false,
|
||||
"content": null,
|
||||
"showUpgrade": true,
|
||||
"paywallTriggered": true,
|
||||
"privateFreeLimit": 1,
|
||||
"privateUsedToday": 1,
|
||||
"reason": "quota_exceeded"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"type": "sentence",
|
||||
"data": {
|
||||
"index": 0,
|
||||
"text": "I am listening.",
|
||||
"total": 2,
|
||||
"done": false
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"type": "connected",
|
||||
"data": {
|
||||
"userId": "user_mock_001"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"type": "error",
|
||||
"data": {
|
||||
"message": "WebSocket connection interrupted."
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"type": "image",
|
||||
"data": {
|
||||
"image": {
|
||||
"type": "elio_schedule",
|
||||
"url": "https://cdn.cozsweet.com/mock/chat/elio-schedule-001.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"type": "paywall_status",
|
||||
"data": {
|
||||
"lockDetail": {
|
||||
"locked": true,
|
||||
"showContent": false,
|
||||
"showUpgrade": true,
|
||||
"reason": "daily_limit",
|
||||
"hint": "免费消息额度已用完,开通会员后可以继续聊天。",
|
||||
"detail": {
|
||||
"type": "daily_msg_limit",
|
||||
"usedToday": 20,
|
||||
"limit": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
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 { ROUTE_BUILDERS, ROUTES } from "@/router/routes";
|
||||
import { todayString, UrlLauncherUtil } from "@/utils";
|
||||
|
||||
export async function resolveExternalBrowserPromptEligibility(): Promise<{
|
||||
canShow: boolean;
|
||||
today: string;
|
||||
}> {
|
||||
const today = todayString();
|
||||
const result = await AppStorage.canShowExternalBrowserDialog(today);
|
||||
return {
|
||||
canShow: result.success && result.data,
|
||||
today,
|
||||
};
|
||||
}
|
||||
|
||||
export function recordExternalBrowserPromptShown(
|
||||
today: string,
|
||||
): Promise<unknown> {
|
||||
return AppStorage.recordExternalBrowserDialogShown(today);
|
||||
}
|
||||
|
||||
export async function openChatInExternalBrowser(): Promise<void> {
|
||||
const authStorage = AuthStorage.getInstance();
|
||||
const userStorage = UserStorage.getInstance();
|
||||
const [deviceIdR, facebookIdR, avatarUrlR] = await Promise.all([
|
||||
authStorage.getDeviceId(),
|
||||
authStorage.getFacebookId(),
|
||||
userStorage.getAvatarUrl(),
|
||||
]);
|
||||
|
||||
const deviceId = deviceIdR.success ? deviceIdR.data : null;
|
||||
const facebookId = facebookIdR.success ? facebookIdR.data : null;
|
||||
const avatarUrl = avatarUrlR.success ? avatarUrlR.data : null;
|
||||
|
||||
if (deviceId && facebookId) {
|
||||
UrlLauncherUtil.openUrlWithExternalBrowser(
|
||||
ROUTE_BUILDERS.chatDeviceId(deviceId),
|
||||
{
|
||||
queryParams: {
|
||||
fbid: facebookId,
|
||||
...(avatarUrl ? { avatarUrl } : {}),
|
||||
},
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
UrlLauncherUtil.openUrlWithExternalBrowser(ROUTES.splash);
|
||||
}
|
||||
Reference in New Issue
Block a user