fix: correctly resolve media that hasn't been downloaded (#763)

* fix: correctly abort if media does not exist

* catch 404s

* dont throw for media that cant be fetched
This commit is contained in:
Pedro S. Lopez
2021-08-01 23:29:06 -04:00
committed by GitHub
parent 628b6e4d49
commit d9ccb6f276

View File

@@ -313,14 +313,18 @@ class Message extends Base {
if (msg.mediaData.mediaStage != 'RESOLVED') { if (msg.mediaData.mediaStage != 'RESOLVED') {
// try to resolve media // 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 // media could not be downloaded
return undefined; return undefined;
} }
try {
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({ const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
directPath: msg.directPath, directPath: msg.directPath,
encFilehash: msg.encFilehash, encFilehash: msg.encFilehash,
@@ -338,7 +342,10 @@ class Message extends Base {
mimetype: msg.mimetype, mimetype: msg.mimetype,
filename: msg.filename filename: msg.filename
}; };
} catch (e) {
if(e.status && e.status === 404) return undefined;
throw e;
}
}, this.id._serialized); }, this.id._serialized);
if (!result) return undefined; if (!result) return undefined;