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