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 40 additions and 22 deletions
Showing only changes of commit 8ba9d73b33 - Show all commits

View file

@ -1,13 +1,17 @@
const {MatrixEvent} = require("./event") const {MatrixEvent} = require("./event")
const {ejs} = require("../basic")
class EncryptedMessage extends MatrixEvent { class EncryptedMessage extends MatrixEvent {
render() { render() {
this.clearChildren()
this.child(
ejs("i").text("Carbon cannot render encrypted messages yet")
)
super.render() super.render()
return this.text("Carbon cannot render encrypted messages yet")
} }
static canRender(event) { static canRender(eventData) {
return event.type == "m.room.encrypted" return eventData.type === "m.room.encrypted"
} }
canGroup() { canGroup() {

View file

@ -46,7 +46,7 @@ class MatrixEvent extends ElemJS {
return this return this
} }
static canRender(_event) { static canRender(eventData) {
return false return false
} }
} }

View file

@ -1,46 +1,54 @@
const {MatrixEvent} = require("./event") const {MatrixEvent} = require("./event")
const {ejs} = require("../basic")
class MembershipEvent extends MatrixEvent { class MembershipEvent extends MatrixEvent {
static canRender(event) { static canRender(eventData) {
return event.type == "m.room.member" return eventData.type === "m.room.member"
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.
}
renderText(text) {
this.clearChildren()
this.child(
ejs("i").text(text)
)
super.render()
} }
} }
class JoinedEvent extends MembershipEvent { class JoinedEvent extends MembershipEvent {
static canRender(event) { static canRender(eventData) {
return super.canRender(event) && event.content.membership === "join" return super.canRender(eventData) && eventData.content.membership === "join"
} }
render() { render() {
super.render() this.renderText("joined the room")
return this.text("joined the room")
} }
} }
class InvitedEvent extends MembershipEvent { class InvitedEvent extends MembershipEvent {
static canRender(event) { static canRender(eventData) {
return super.canRender(event) && event.content.membership === "invite" return super.canRender(eventData) && eventData.content.membership === "invite"
} }
render() { render() {
super.render() this.renderText(`invited ${this.data.content.displayname}`)
return this.text(`invited ${this.data.content.displayname}`)
} }
} }
class LeaveEvent extends MembershipEvent { class LeaveEvent extends MembershipEvent {
static canRender(event) { static canRender(eventData) {
return super.canRender(event) && event.content.membership === "leave" return super.canRender(eventData) && eventData.content.membership === "leave"
} }
render() { render() {
super.render() this.renderText("left the room")
return this.text(`left the room`)
} }
} }
class UnknownMembership extends MembershipEvent { class UnknownMembership extends MembershipEvent {
render() { render() {
super.render() this.renderText("unknown membership event")
return this.text("unknown membership event")
} }
} }

View file

@ -1,13 +1,19 @@
const {MatrixEvent} = require("./event") const {MatrixEvent} = require("./event")
const {ejs} = require("../basic")
class UnknownEvent extends MatrixEvent { class UnknownEvent extends MatrixEvent {
static canRender() { static canRender() {
return true return true
} }
render() { render() {
this.clearChildren()
this.child(
ejs("i").text(`Unknown event of type ${this.data.type}`)
)
super.render() super.render()
return this.text(`cannot render event`)
} }
} }
module.exports = [UnknownEvent] module.exports = [UnknownEvent]

View file

@ -5,7 +5,7 @@ const {Anchor} = require("./anchor.js")
const {Sender} = require("./sender.js") const {Sender} = require("./sender.js")
const lsm = require("./lsm.js") const lsm = require("./lsm.js")
const {resolveMxc} = require("./functions.js") const {resolveMxc} = require("./functions.js")
const {renderEvent} = require("./events/renderEvent") const {renderEvent} = require("./events/render-event")
const {dateFormatter} = require("./date-formatter") const {dateFormatter} = require("./date-formatter")
let debug = false let debug = false