This commit is contained in:
parent
327290e971
commit
4acd806e66
4 changed files with 49 additions and 1 deletions
32
src/js/events/image.js
Normal file
32
src/js/events/image.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const {ejs, ElemJS} = require("../basic")
|
||||
const {resolveMxc} = require("../functions")
|
||||
const {MatrixEvent} = require("./event")
|
||||
|
||||
class Image extends MatrixEvent {
|
||||
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]
|
|
@ -142,6 +142,7 @@ function autoLinkText(text) {
|
|||
class TextMessage extends MatrixEvent {
|
||||
render() {
|
||||
this.clearChildren()
|
||||
this.class("c-message--plain")
|
||||
const fragment = autoLinkText(this.data.content.body)
|
||||
this.child(fragment)
|
||||
super.render()
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const imageEvent = require("./image")
|
||||
const messageEvent = require("./message")
|
||||
const encryptedEvent = require("./encrypted")
|
||||
const membershipEvent = require("./membership")
|
||||
const unknownEvent = require("./unknown")
|
||||
|
||||
const events = [
|
||||
...imageEvent,
|
||||
...messageEvent,
|
||||
...encryptedEvent,
|
||||
...membershipEvent,
|
||||
|
|
|
@ -49,7 +49,14 @@
|
|||
overflow-wrap: anywhere
|
||||
opacity: 1
|
||||
transition: opacity 0.2s ease-out
|
||||
white-space: pre-wrap
|
||||
|
||||
&--plain
|
||||
white-space: pre-wrap
|
||||
|
||||
&--media
|
||||
// fix whitespace
|
||||
font-size: 0
|
||||
margin-top: 8px
|
||||
|
||||
&--pending
|
||||
opacity: 0.5
|
||||
|
@ -68,6 +75,12 @@
|
|||
&:hover
|
||||
background-color: c.$darker
|
||||
|
||||
&__image
|
||||
width: auto
|
||||
height: auto
|
||||
max-width: 400px
|
||||
max-height: 300px
|
||||
|
||||
// message formatting rules
|
||||
|
||||
code, pre
|
||||
|
|
Loading…
Reference in a new issue