(client: TelegramClient, userId: number)
| 359 | inputPeerCache.set(id, new Api.InputPeerUser({ |
| 360 | userId: sender.id, |
| 361 | accessHash: sender.accessHash, |
| 362 | })); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | function cacheInputPeer(userId: number, peer: any): void { |
| 367 | if (userId > 0 && peer instanceof Api.InputPeerUser) { |
| 368 | inputPeerCache.set(userId, peer); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | async function resolveInputPeer(client: TelegramClient, userId: number): Promise<Api.TypeInputPeer> { |
| 373 | const cached = inputPeerCache.get(userId); |
| 374 | if (cached) return cached; |
| 375 | |
| 376 | const peer = await client.getInputEntity(bigInt(userId)); |
| 377 | cacheInputPeer(userId, peer); |
| 378 | return peer; |
| 379 | } |
| 380 | |
| 381 | function peerTarget(userId: number): Api.TypeInputPeer | number { |
| 382 | return inputPeerCache.get(userId) ?? userId; |
| 383 | } |
| 384 | |
| 385 | async function cachePeerFromMessage(message: Api.Message, userId: number): Promise<void> { |
| 386 | const directPeer = (message as any).inputChat; |
| 387 | if (directPeer) cacheInputPeer(userId, directPeer); |
| 388 | if (inputPeerCache.has(userId)) return; |
| 389 | |
| 390 | try { |
no test coverage detected