Rich message rendering #24

Merged
cadence merged 28 commits from rich-messages into princess 2020-11-07 10:46:48 +00:00
5 changed files with 12 additions and 16 deletions
Showing only changes of commit d983385e16 - Show all commits

View file

@ -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")

View file

@ -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 {

Not sure how I feel about a function that creates classes. Can we inherit from a base class instead?

Not sure how I feel about a function that creates classes. Can we inherit from a base class instead?
Outdated
Review

That's a lot more verbose, which I don't really like, but sure

That's a lot more verbose, which I don't really like, but sure
function renderEvent(event) { module.exports = {MatrixEvent}
return new events.find(e => e.canRender(event))(event)
}
module.exports = {renderEvent, Event}

View file

@ -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()
bad marked this conversation as resolved Outdated

Again here. I think a better way would be to have a base class like MembershipEvent, and then for each kind of membership we subclass it and only implement the canRender method on each.

Again here. I think a better way would be to have a base class like MembershipEvent, and then for each kind of membership we subclass it and only implement the canRender method on each.
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")

View file

@ -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)

View file

@ -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")