From 6b5db7c8b9fefb9ce60427c8040c079cf96c3a0f Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 4 Mar 2026 13:57:31 +0700 Subject: [PATCH] zalouser: handle legacy fetchAccountInfo shape --- extensions/zalouser/src/zalo-js.ts | 20 ++++++++++++++++++-- extensions/zalouser/src/zca-client.ts | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/extensions/zalouser/src/zalo-js.ts b/extensions/zalouser/src/zalo-js.ts index de3fc4973b6..75653f870fd 100644 --- a/extensions/zalouser/src/zalo-js.ts +++ b/extensions/zalouser/src/zalo-js.ts @@ -65,6 +65,8 @@ type ActiveZaloListener = { const activeListeners = new Map(); const groupContextCache = new Map(); +type AccountInfoResponse = Awaited>; + type ApiTypingCapability = { sendTypingEvent: ( threadId: string, @@ -157,6 +159,20 @@ function toStringValue(value: unknown): string { return ""; } +function normalizeAccountInfoUser(info: AccountInfoResponse): User | null { + if (!info || typeof info !== "object") { + return null; + } + if ("profile" in info) { + const profile = (info as { profile?: unknown }).profile; + if (profile && typeof profile === "object") { + return profile as User; + } + return null; + } + return info as User; +} + function toInteger(value: unknown, fallback = 0): number { if (typeof value === "number" && Number.isFinite(value)) { return Math.trunc(value); @@ -801,7 +817,7 @@ export async function getZaloUserInfo(profileInput?: string | null): Promise { try { const info = await api.fetchAccountInfo(); - const resolved = toNumberId(info.profile?.userId); + const resolved = toNumberId(normalizeAccountInfoUser(info)?.userId); if (resolved) { return resolved; } diff --git a/extensions/zalouser/src/zca-client.ts b/extensions/zalouser/src/zca-client.ts index ffcedd4edb1..cab838481bb 100644 --- a/extensions/zalouser/src/zca-client.ts +++ b/extensions/zalouser/src/zca-client.ts @@ -138,7 +138,7 @@ export type API = { cookies: unknown[]; }; }; - fetchAccountInfo(): Promise<{ profile: User }>; + fetchAccountInfo(): Promise; getAllFriends(): Promise; getOwnId(): string; getAllGroups(): Promise<{