don't rely on mime-types to decide to use main url for thumbnail

so it does not break when clients forget to set the mimetype
This commit is contained in:
Bruno Windels 2021-03-10 10:01:07 +01:00
parent c6ff56a942
commit 35e6dffd0b
2 changed files with 10 additions and 3 deletions

View file

@ -72,7 +72,7 @@ export class BaseMediaTile extends MessageTile {
const attachment = this._entry.pendingEvent.getAttachment("info.thumbnail_url");
return attachment && attachment.localPreview.url;
}
if (this.mimeType?.startsWith("image/")) {
if (this._isMainResourceImage()) {
if (this._decryptedFile) {
return this._decryptedFile.url;
} else {
@ -111,7 +111,6 @@ export class BaseMediaTile extends MessageTile {
return null;
}
async _loadEncryptedFile(file) {
const blob = await this._mediaRepository.downloadEncryptedFile(file, true);
if (this.isDisposed) {
@ -128,7 +127,7 @@ export class BaseMediaTile extends MessageTile {
if (thumbnailFile) {
this._decryptedThumbnail = await this._loadEncryptedFile(thumbnailFile);
this.emitChange("thumbnailUrl");
} else if (file && this.mimeType?.startsWith("image/")) { // is the main resource an image? then try that for a thumbnail
} else if (file && this._isMainResourceImage()) { // is the main resource an image? then try that for a thumbnail
this._decryptedFile = await this._loadEncryptedFile(file);
this.emitChange("thumbnailUrl");
}
@ -146,4 +145,8 @@ export class BaseMediaTile extends MessageTile {
// we should not upscale images, so limit scale factor to 1 upwards
return Math.min(scaleWidthFactor, scaleHeightFactor, 1);
}
_isMainResourceImage() {
return true; // overwritten in VideoTile
}
}

View file

@ -40,4 +40,8 @@ export class VideoTile extends BaseMediaTile {
get shape() {
return "video";
}
_isMainResourceImage() {
return false;
}
}