( msg?: Api.Message, )
| 784 | |
| 785 | const getMessageImageParts = async ( |
| 786 | msg?: Api.Message, |
| 787 | ): Promise<AIContentPart[]> => { |
| 788 | if (!msg?.client) return []; |
| 789 | |
| 790 | const parts: AIContentPart[] = []; |
| 791 | |
| 792 | const rawGroupedId = (msg as any).groupedId; |
| 793 | const groupedId = rawGroupedId ? rawGroupedId.toString() : undefined; |
| 794 | |
| 795 | if (!groupedId) { |
| 796 | await collectImagePartsFromSingleMessage(msg, parts); |
| 797 | return parts; |
| 798 | } |
| 799 | |
| 800 | const peer = msg.chatId || msg.peerId; |
| 801 | const sameGroupMessages: Api.Message[] = []; |
| 802 | |
| 803 | for await (const m of msg.client.iterMessages(peer, { limit: 50 })) { |
| 804 | if (!(m instanceof Api.Message)) continue; |
| 805 | |
| 806 | const g = (m as any).groupedId; |
| 807 | if (!g) continue; |
| 808 | |
| 809 | if (g.toString() !== groupedId) continue; |
| 810 | |
| 811 | sameGroupMessages.push(m); |
| 812 | } |
| 813 | |
| 814 | sameGroupMessages.sort((a, b) => Number(a.id) - Number(b.id)); |
| 815 | |
| 816 | for (const m of sameGroupMessages) { |
| 817 | await collectImagePartsFromSingleMessage(m, parts); |
| 818 | } |
| 819 | |
| 820 | return parts; |
| 821 | }; |
| 822 | |
| 823 | const getGroupedMessageIds = async (msg: Api.Message): Promise<number[]> => { |
| 824 | if (!msg?.client) return []; |
| 825 | const rawGroupedId = (msg as any).groupedId; |
no test coverage detected