load image in timeline from when it is partially visible

This commit is contained in:
Bruno Windels 2022-01-14 13:57:11 +01:00
parent 1ed8d48ced
commit 1f9be978b7
2 changed files with 13 additions and 4 deletions

View file

@ -25,10 +25,8 @@ export class BaseMediaTile extends BaseMessageTile {
super(options);
this._decryptedThumbnail = null;
this._decryptedFile = null;
this._isVisible = false;
this._error = null;
if (!this.isPending) {
this._tryLoadEncryptedThumbnail();
}
}
get isUploading() {
@ -60,6 +58,9 @@ export class BaseMediaTile extends BaseMessageTile {
}
get thumbnailUrl() {
if (!this._isVisible) {
return "";
}
if (this._decryptedThumbnail) {
return this._decryptedThumbnail.url;
} else {
@ -85,6 +86,15 @@ export class BaseMediaTile extends BaseMessageTile {
return "";
}
notifyVisible() {
super.notifyVisible();
this._isVisible = true;
this.emitChange("thumbnailUrl");
if (!this.isPending) {
this._tryLoadEncryptedThumbnail();
}
}
get width() {
const info = this._getContent()?.info;
return Math.round(info?.w * this._scaleFactor());

View file

@ -19,7 +19,6 @@ import {BaseMediaView} from "./BaseMediaView.js";
export class ImageView extends BaseMediaView {
renderMedia(t, vm) {
const img = t.img({
loading: "lazy",
src: vm => vm.thumbnailUrl,
alt: vm => vm.label,
title: vm => vm.label,