forked from mystiq/hydrogen-web
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
2 changed files with 10 additions and 3 deletions
|
@ -72,7 +72,7 @@ export class BaseMediaTile extends MessageTile {
|
||||||
const attachment = this._entry.pendingEvent.getAttachment("info.thumbnail_url");
|
const attachment = this._entry.pendingEvent.getAttachment("info.thumbnail_url");
|
||||||
return attachment && attachment.localPreview.url;
|
return attachment && attachment.localPreview.url;
|
||||||
}
|
}
|
||||||
if (this.mimeType?.startsWith("image/")) {
|
if (this._isMainResourceImage()) {
|
||||||
if (this._decryptedFile) {
|
if (this._decryptedFile) {
|
||||||
return this._decryptedFile.url;
|
return this._decryptedFile.url;
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,7 +111,6 @@ export class BaseMediaTile extends MessageTile {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async _loadEncryptedFile(file) {
|
async _loadEncryptedFile(file) {
|
||||||
const blob = await this._mediaRepository.downloadEncryptedFile(file, true);
|
const blob = await this._mediaRepository.downloadEncryptedFile(file, true);
|
||||||
if (this.isDisposed) {
|
if (this.isDisposed) {
|
||||||
|
@ -128,7 +127,7 @@ export class BaseMediaTile extends MessageTile {
|
||||||
if (thumbnailFile) {
|
if (thumbnailFile) {
|
||||||
this._decryptedThumbnail = await this._loadEncryptedFile(thumbnailFile);
|
this._decryptedThumbnail = await this._loadEncryptedFile(thumbnailFile);
|
||||||
this.emitChange("thumbnailUrl");
|
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._decryptedFile = await this._loadEncryptedFile(file);
|
||||||
this.emitChange("thumbnailUrl");
|
this.emitChange("thumbnailUrl");
|
||||||
}
|
}
|
||||||
|
@ -146,4 +145,8 @@ export class BaseMediaTile extends MessageTile {
|
||||||
// we should not upscale images, so limit scale factor to 1 upwards
|
// we should not upscale images, so limit scale factor to 1 upwards
|
||||||
return Math.min(scaleWidthFactor, scaleHeightFactor, 1);
|
return Math.min(scaleWidthFactor, scaleHeightFactor, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isMainResourceImage() {
|
||||||
|
return true; // overwritten in VideoTile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,4 +40,8 @@ export class VideoTile extends BaseMediaTile {
|
||||||
get shape() {
|
get shape() {
|
||||||
return "video";
|
return "video";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isMainResourceImage() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue