This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/domain/session/room/timeline/tiles/ImageTile.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

import {MessageTile} from "./MessageTile.js";
2019-03-09 05:10:03 +05:30
2020-05-09 23:32:08 +05:30
const MAX_HEIGHT = 300;
const MAX_WIDTH = 400;
export class ImageTile extends MessageTile {
2020-05-09 23:32:08 +05:30
constructor(options, room) {
2019-03-09 05:10:03 +05:30
super(options);
2020-05-09 23:32:08 +05:30
this._room = room;
}
2019-03-09 05:10:03 +05:30
2020-05-09 23:32:08 +05:30
get thumbnailUrl() {
const mxcUrl = this._getContent().url;
return this._room.mxcUrlThumbnail(mxcUrl, this.thumbnailWidth, this.thumbnailHeigth, "scale");
2019-03-09 05:10:03 +05:30
}
2020-05-09 23:32:08 +05:30
get url() {
const mxcUrl = this._getContent().url;
return this._room.mxcUrl(mxcUrl);
2019-03-09 05:10:03 +05:30
}
2020-05-09 23:32:08 +05:30
_scaleFactor() {
const {info} = this._getContent();
const scaleHeightFactor = MAX_HEIGHT / info.h;
const scaleWidthFactor = MAX_WIDTH / info.w;
// take the smallest scale factor, to respect all constraints
// we should not upscale images, so limit scale factor to 1 upwards
return Math.min(scaleWidthFactor, scaleHeightFactor, 1);
2019-03-09 05:10:03 +05:30
}
2020-05-09 23:32:08 +05:30
get thumbnailWidth() {
const {info} = this._getContent();
return Math.round(info.w * this._scaleFactor());
}
get thumbnailHeigth() {
const {info} = this._getContent();
return Math.round(info.h * this._scaleFactor());
2019-03-09 05:10:03 +05:30
}
get label() {
2020-05-09 23:32:08 +05:30
return this._getContent().body;
}
get shape() {
return "image";
}
2019-03-09 05:10:03 +05:30
}