| 561 | } |
| 562 | |
| 563 | async function collectMessages( |
| 564 | client: any, |
| 565 | peer: any, |
| 566 | startId: number, |
| 567 | desiredCount: number |
| 568 | ) { |
| 569 | const messageIds: number[] = []; |
| 570 | const MAX_SEARCH_LIMIT = 500; |
| 571 | const maxSearch = Math.min(desiredCount * 3, MAX_SEARCH_LIMIT); |
| 572 | let currentId = startId; |
| 573 | |
| 574 | while (messageIds.length < desiredCount && currentId < startId + maxSearch) { |
| 575 | try { |
| 576 | const fetched = await safeGetMessages(client, peer, { |
| 577 | ids: [currentId], |
| 578 | }); |
| 579 | const candidate = Array.isArray(fetched) ? fetched[0] : fetched; |
| 580 | if (candidate && candidate.id) { |
| 581 | messageIds.push(candidate.id); |
| 582 | } |
| 583 | } catch (error) { |
| 584 | console.warn(`[bs] 获取消息 ${currentId} 失败`, error); |
| 585 | } |
| 586 | currentId += 1; |
| 587 | } |
| 588 | |
| 589 | return { messageIds }; |
| 590 | } |
| 591 | |
| 592 | async function sendSourceFeedback(options: { |
| 593 | msg: Api.Message; |