refactor(chat): clean stale mocks and external browser helpers
This commit is contained in:
@@ -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