Rich message rendering #24
5 changed files with 12 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
||||||
const {Event} = require("./event")
|
const {MatrixEvent} = require("./event")
|
||||||
|
|
||||||
class EncryptedMessage extends Event {
|
class EncryptedMessage extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
return this.text("Carbon cannot render encrypted messages yet")
|
return this.text("Carbon cannot render encrypted messages yet")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const {ElemJS, ejs} = require("../basic")
|
const {ElemJS, ejs} = require("../basic")
|
||||||
const {dateFormatter} = require("../dateFormatter")
|
const {dateFormatter} = require("../dateFormatter")
|
||||||
|
|
||||||
class Event extends ElemJS {
|
class MatrixEvent extends ElemJS {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
super("div")
|
super("div")
|
||||||
this.class("c-message")
|
this.class("c-message")
|
||||||
|
@ -52,8 +52,4 @@ class Event extends ElemJS {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function renderEvent(event) {
|
module.exports = {MatrixEvent}
|
||||||
return new events.find(e => e.canRender(event))(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {renderEvent, Event}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const {Event} = require("./event")
|
const {MatrixEvent} = require("./event")
|
||||||
|
|
||||||
function createMembershipEvent(membership, message) {
|
function createMembershipEvent(membership, message) {
|
||||||
return class extends Event {
|
return class extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
return this.text(message(this.data))
|
return this.text(message(this.data))
|
||||||
|
@ -13,7 +13,7 @@ function createMembershipEvent(membership, message) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class UnknownMembership extends Event {
|
class UnknownMembership extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
return this.text("Unsupported membership event")
|
return this.text("Unsupported membership event")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const {ejs} = require("../basic")
|
const {ejs} = require("../basic")
|
||||||
const DOMPurify = require("dompurify")
|
const DOMPurify = require("dompurify")
|
||||||
const {resolveMxc} = require("../functions")
|
const {resolveMxc} = require("../functions")
|
||||||
const {Event} = require("./event")
|
const {MatrixEvent} = require("./event")
|
||||||
|
|
||||||
const purifier = DOMPurify()
|
const purifier = DOMPurify()
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ function sanitize(html) {
|
||||||
return purifier.sanitize(html)
|
return purifier.sanitize(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
class HTMLMessage extends Event {
|
class HTMLMessage extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
let html = this.data.content.formatted_body
|
let html = this.data.content.formatted_body
|
||||||
|
@ -89,7 +89,7 @@ class HTMLMessage extends Event {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TextMessage extends Event {
|
class TextMessage extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
return this.text(this.data.content.body)
|
return this.text(this.data.content.body)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {Event} = require("./event")
|
const {MatrixEvent} = require("./event")
|
||||||
|
|
||||||
class UnknownEvent extends Event {
|
class UnknownEvent extends MatrixEvent {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
this.text("Cannot render event")
|
this.text("Cannot render event")
|
||||||
|
|
Loading…
Reference in a new issue