From e5daa2dc206207791bdcaacd1b5ae1a086e6ae5d Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:53:00 +0200 Subject: [PATCH] Avatar: Ignore some errors when loading (#4902) --- src/api/gramjs/methods/client.ts | 8 +++++ src/lib/gramjs/client/TelegramClient.js | 47 ++++++------------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/api/gramjs/methods/client.ts b/src/api/gramjs/methods/client.ts index f6434f55e..b568f4c21 100644 --- a/src/api/gramjs/methods/client.ts +++ b/src/api/gramjs/methods/client.ts @@ -337,6 +337,14 @@ export async function downloadMedia( } } + if (err.message === 'FILE_ID_INVALID' && args.url.includes('avatar')) { + if (DEBUG) { + // eslint-disable-next-line no-console + console.warn('Inaccessible avatar image', args.url); + } + return undefined; + } + if (DEBUG) { // eslint-disable-next-line no-console console.error('Failed to download media', args.url, err); diff --git a/src/lib/gramjs/client/TelegramClient.js b/src/lib/gramjs/client/TelegramClient.js index de691f133..97bc82d31 100644 --- a/src/lib/gramjs/client/TelegramClient.js +++ b/src/lib/gramjs/client/TelegramClient.js @@ -702,45 +702,18 @@ class TelegramClient { } downloadProfilePhoto(entity, isBig = false) { - // ('User', 'Chat', 'UserFull', 'ChatFull') - const ENTITIES = [0x2da17977, 0xc5af5d94, 0x1f4661b9, 0xd49a2697]; - // ('InputPeer', 'InputUser', 'InputChannel') - // const INPUTS = [0xc91c90b6, 0xe669bf46, 0x40f202fd] - // Todo account for input methods - const sizeType = isBig ? 'x' : 'm'; - let photo; - if (!(ENTITIES.includes(entity.SUBCLASS_OF_ID))) { - photo = entity; - } else { - if (!entity.photo) { - // Special case: may be a ChatFull with photo:Photo - if (!entity.chatPhoto) { - return undefined; - } + const photo = entity.photo; - return this._downloadPhoto( - entity.chatPhoto, { sizeType }, - ); - } - photo = entity.photo; - } + if (!(photo instanceof constructors.UserProfilePhoto + || photo instanceof constructors.ChatPhoto)) return undefined; + + const dcId = photo.dcId; + const loc = new constructors.InputPeerPhotoFileLocation({ + peer: utils.getInputPeer(entity), + photoId: photo.photoId, + big: isBig, + }); - let dcId; - let loc; - if (photo instanceof constructors.UserProfilePhoto || photo instanceof constructors.ChatPhoto) { - dcId = photo.dcId; - loc = new constructors.InputPeerPhotoFileLocation({ - peer: utils.getInputPeer(entity), - photoId: photo.photoId, - big: isBig, - }); - } else { - // It doesn't make any sense to check if `photo` can be used - // as input location, because then this method would be able - // to "download the profile photo of a message", i.e. its - // media which should be done with `download_media` instead. - return undefined; - } return this.downloadFile(loc, { dcId, });