diff --git a/src/structures/Message.js b/src/structures/Message.js index d5c1e4f..1930ff1 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -313,32 +313,39 @@ class Message extends Base { if (msg.mediaData.mediaStage != 'RESOLVED') { // try to resolve media - await msg.downloadMedia(true, 1); + await msg.downloadMedia({ + downloadEvenIfExpensive: true, + rmrReason: 1 + }); } - if (msg.mediaData.mediaStage.includes('ERROR')) { + if (msg.mediaData.mediaStage.includes('ERROR') || msg.mediaData.mediaStage === 'FETCHING') { // media could not be downloaded return undefined; } - const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({ - directPath: msg.directPath, - encFilehash: msg.encFilehash, - filehash: msg.filehash, - mediaKey: msg.mediaKey, - mediaKeyTimestamp: msg.mediaKeyTimestamp, - type: msg.type, - signal: (new AbortController).signal - }); - - const data = window.WWebJS.arrayBufferToBase64(decryptedMedia); - - return { - data, - mimetype: msg.mimetype, - filename: msg.filename - }; - + try { + const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({ + directPath: msg.directPath, + encFilehash: msg.encFilehash, + filehash: msg.filehash, + mediaKey: msg.mediaKey, + mediaKeyTimestamp: msg.mediaKeyTimestamp, + type: msg.type, + signal: (new AbortController).signal + }); + + const data = window.WWebJS.arrayBufferToBase64(decryptedMedia); + + return { + data, + mimetype: msg.mimetype, + filename: msg.filename + }; + } catch (e) { + if(e.status && e.status === 404) return undefined; + throw e; + } }, this.id._serialized); if (!result) return undefined;