Carbon/src/js/events/image.js

33 lines
721 B
JavaScript

const {ejs, ElemJS} = require("../basic")
const {resolveMxc} = require("../functions")
const {GroupableEvent} = require("./event")
class Image extends GroupableEvent {
render() {
this.clearChildren()
this.class("c-message--media")
const image = (
ejs("img")
.class("c-message__image")
.attribute("src", resolveMxc(this.data.content.url))
)
const info = this.data.content.info
if (info && info.w && info.h) {
image.attribute("width", info.w)
image.attribute("height", info.h)
}
this.child(image)
super.render()
}
static canRender(event) {
return event.type === "m.room.message" && event.content.msgtype === "m.image"
}
canGroup() {
return true
}
}
module.exports = [Image]