(client: TelegramClient, userId: number)
| 359 | if (username) usernameCache.set(id, username); |
| 360 | } |
| 361 | |
| 362 | async function fetchUserInfo(client: TelegramClient, userId: number): Promise<any | null> { |
| 363 | try { |
| 364 | const e = await client.getEntity(userId) as any; |
| 365 | cacheUserFromSender(e); |
| 366 | return e; |
| 367 | } catch {} |
| 368 | |
| 369 | try { |
| 370 | const input = await client.getInputEntity(bigInt(userId)); |
| 371 | if (input instanceof Api.InputPeerUser) { |
| 372 | const res = await client.invoke(new Api.users.GetUsers({ |
| 373 | id: [new Api.InputUser({ userId: input.userId, accessHash: input.accessHash })] |
| 374 | })) as any[]; |
| 375 | const user = res?.[0]; |
| 376 | if (user && !(user instanceof Api.UserEmpty)) { |
| 377 | cacheUserFromSender(user); |
| 378 | return user; |
| 379 | } |
| 380 | } |
| 381 | } catch {} |
| 382 | |
| 383 | return null; |
| 384 | } |
| 385 | |
| 386 | async function getDisplayName(client: TelegramClient, userId: number): Promise<string> { |
| 387 | if (nameCache.has(userId)) return nameCache.get(userId)!; |
| 388 | const user = await fetchUserInfo(client, userId); |
| 389 | if (user) { |
| 390 | const name = [user.firstName, user.lastName].filter(Boolean).join(" ").trim() || "Unknown"; |
no test coverage detected