2020-04-21 00:56:39 +05:30
|
|
|
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;
|
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
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;
|
2020-05-10 00:51:55 +05:30
|
|
|
return this._room.mxcUrlThumbnail(mxcUrl, this.thumbnailWidth, this.thumbnailHeight, "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());
|
|
|
|
}
|
|
|
|
|
2020-05-10 00:51:55 +05:30
|
|
|
get thumbnailHeight() {
|
2020-05-09 23:32:08 +05:30
|
|
|
const {info} = this._getContent();
|
|
|
|
return Math.round(info.h * this._scaleFactor());
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
2019-06-02 03:33:55 +05:30
|
|
|
|
|
|
|
get label() {
|
2020-05-09 23:32:08 +05:30
|
|
|
return this._getContent().body;
|
|
|
|
}
|
|
|
|
|
|
|
|
get shape() {
|
|
|
|
return "image";
|
2019-06-02 03:33:55 +05:30
|
|
|
}
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|