( client: any, sourceChat: ResolvedChat, sourceUser: ResolvedSourceUser, requestedCount: number, manualScanLimit?: number, )
| 372 | manualScanLimit?: number, |
| 373 | ): Promise<DigestRecord[]> { |
| 374 | const records: DigestRecord[] = []; |
| 375 | const iterParams: Record<string, any> = { |
| 376 | limit: sourceUser.manualMode |
| 377 | ? (manualScanLimit ?? |
| 378 | Math.min( |
| 379 | Math.max(requestedCount * 20, requestedCount + 50), |
| 380 | MAX_SCAN_LIMIT, |
| 381 | )) |
| 382 | : requestedCount, |
| 383 | }; |
| 384 | |
| 385 | if (!sourceUser.manualMode) { |
| 386 | iterParams.fromUser = sourceUser.entity; |
| 387 | } |
| 388 | |
| 389 | const iterator = client.iterMessages(sourceChat.entity, iterParams); |
| 390 | |
| 391 | for await (const message of iterator) { |
| 392 | const current = message as any; |
| 393 | |
| 394 | if (sourceUser.manualMode) { |
| 395 | const matched = await matchesManualSelector(current, sourceUser); |
| 396 | if (!matched) continue; |
| 397 | } |
| 398 | |
| 399 | const { day, time } = formatDateParts(current?.date); |
| 400 | records.push({ |
| 401 | day, |
| 402 | time, |
| 403 | text: compactMessageText(buildMessageText(current)), |
| 404 | link: buildChatMessageLink(sourceChat.entity, Number(current?.id)), |
| 405 | }); |
| 406 | |
| 407 | if (records.length >= requestedCount) break; |
| 408 | } |
| 409 | |
| 410 | return records.reverse(); |
| 411 | } |
| 412 | |
| 413 | async function collectMessages( |
| 414 | client: any, |
| 415 | sourceChat: ResolvedChat, |
| 416 | sourceUser: ResolvedSourceUser, |
| 417 | requestedCount: number, |
| 418 | ): Promise<DigestRecord[]> { |
| 419 | const initialRecords = await collectMessagesOnce( |
| 420 | client, |
| 421 | sourceChat, |
no test coverage detected