mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 11:36:24 +01:00
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:
parent
c6ff56a942
commit
35e6dffd0b
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,8 @@ export class VideoTile extends BaseMediaTile {
|
||||
get shape() {
|
||||
return "video";
|
||||
}
|
||||
|
||||
_isMainResourceImage() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user