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 {
|
class TextMessage extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
this.clearChildren()
|
this.clearChildren()
|
||||||
|
this.class("c-message--plain")
|
||||||
const fragment = autoLinkText(this.data.content.body)
|
const fragment = autoLinkText(this.data.content.body)
|
||||||
this.child(fragment)
|
this.child(fragment)
|
||||||
super.render()
|
super.render()
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
|
const imageEvent = require("./image")
|
||||||
const messageEvent = require("./message")
|
const messageEvent = require("./message")
|
||||||
const encryptedEvent = require("./encrypted")
|
const encryptedEvent = require("./encrypted")
|
||||||
const membershipEvent = require("./membership")
|
const membershipEvent = require("./membership")
|
||||||
const unknownEvent = require("./unknown")
|
const unknownEvent = require("./unknown")
|
||||||
|
|
||||||
const events = [
|
const events = [
|
||||||
|
...imageEvent,
|
||||||
...messageEvent,
|
...messageEvent,
|
||||||
...encryptedEvent,
|
...encryptedEvent,
|
||||||
...membershipEvent,
|
...membershipEvent,
|
||||||
|
|
|
@ -49,8 +49,15 @@
|
||||||
overflow-wrap: anywhere
|
overflow-wrap: anywhere
|
||||||
opacity: 1
|
opacity: 1
|
||||||
transition: opacity 0.2s ease-out
|
transition: opacity 0.2s ease-out
|
||||||
|
|
||||||
|
&--plain
|
||||||
white-space: pre-wrap
|
white-space: pre-wrap
|
||||||
|
|
||||||
|
&--media
|
||||||
|
// fix whitespace
|
||||||
|
font-size: 0
|
||||||
|
margin-top: 8px
|
||||||
|
|
||||||
&--pending
|
&--pending
|
||||||
opacity: 0.5
|
opacity: 0.5
|
||||||
|
|
||||||
|
@ -68,6 +75,12 @@
|
||||||
&:hover
|
&:hover
|
||||||
background-color: c.$darker
|
background-color: c.$darker
|
||||||
|
|
||||||
|
&__image
|
||||||
|
width: auto
|
||||||
|
height: auto
|
||||||
|
max-width: 400px
|
||||||
|
max-height: 300px
|
||||||
|
|
||||||
// message formatting rules
|
// message formatting rules
|
||||||
|
|
||||||
code, pre
|
code, pre
|
||||||
|
|
Loading…
Reference in a new issue