fix(core): findDialogs failing with just one unknown id

This commit is contained in:
alina 🌸 2024-10-09 11:55:15 +03:00
parent fefc8d38a7
commit 9b32cf9c4a
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -55,23 +55,21 @@ export async function findDialogs(client: ITelegramClient, peers: MaybeArray<str
foundIdxToOriginalIdx.set(foundInputPeers.length - 1, i) foundIdxToOriginalIdx.set(foundInputPeers.length - 1, i)
} }
if (foundInputPeers.length === 0) { const ret: Dialog[] = Array.from({ length: peers.length })
// we didn't find anything, we can't even fetch the dialogs
throw new MtPeerNotFoundError(`Could not find dialogs with peers: ${peers.join(', ')}`)
}
if (foundInputPeers.length !== 0) {
// we have some input peers, try to fetch them
const dialogs = await getPeerDialogs(client, foundInputPeers) const dialogs = await getPeerDialogs(client, foundInputPeers)
if (foundInputPeers.length === peers.length) { if (foundInputPeers.length === peers.length) {
return dialogs return dialogs
} }
const ret: Dialog[] = Array.from({ length: peers.length })
// populate found dialogs // populate found dialogs
for (const [idx, origIdx] of foundIdxToOriginalIdx) { for (const [idx, origIdx] of foundIdxToOriginalIdx) {
ret[origIdx] = dialogs[idx] ret[origIdx] = dialogs[idx]
} }
}
// now we need to iterate over all dialogs and try to find the rest // now we need to iterate over all dialogs and try to find the rest
for await (const dialog of iterDialogs(client, { for await (const dialog of iterDialogs(client, {