Rich message rendering #24
5 changed files with 40 additions and 22 deletions
|
@ -1,13 +1,17 @@
|
|||
const {MatrixEvent} = require("./event")
|
||||
const {ejs} = require("../basic")
|
||||
|
||||
class EncryptedMessage extends MatrixEvent {
|
||||
render() {
|
||||
this.clearChildren()
|
||||
this.child(
|
||||
ejs("i").text("Carbon cannot render encrypted messages yet")
|
||||
)
|
||||
super.render()
|
||||
return this.text("Carbon cannot render encrypted messages yet")
|
||||
}
|
||||
|
||||
static canRender(event) {
|
||||
return event.type == "m.room.encrypted"
|
||||
static canRender(eventData) {
|
||||
return eventData.type === "m.room.encrypted"
|
||||
}
|
||||
|
||||
canGroup() {
|
||||
|
|
|
@ -46,7 +46,7 @@ class MatrixEvent extends ElemJS {
|
|||
return this
|
||||
}
|
||||
|
||||
static canRender(_event) {
|
||||
static canRender(eventData) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +1,54 @@
|
|||
const {MatrixEvent} = require("./event")
|
||||
const {ejs} = require("../basic")
|
||||
|
||||
class MembershipEvent extends MatrixEvent {
|
||||
static canRender(event) {
|
||||
return event.type == "m.room.member"
|
||||
static canRender(eventData) {
|
||||
return eventData.type === "m.room.member"
|
||||
bad marked this conversation as resolved
Outdated
|
||||
}
|
||||
|
||||
renderText(text) {
|
||||
this.clearChildren()
|
||||
this.child(
|
||||
ejs("i").text(text)
|
||||
)
|
||||
super.render()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class JoinedEvent extends MembershipEvent {
|
||||
static canRender(event) {
|
||||
return super.canRender(event) && event.content.membership === "join"
|
||||
static canRender(eventData) {
|
||||
return super.canRender(eventData) && eventData.content.membership === "join"
|
||||
}
|
||||
|
||||
render() {
|
||||
super.render()
|
||||
return this.text("joined the room")
|
||||
this.renderText("joined the room")
|
||||
}
|
||||
}
|
||||
|
||||
class InvitedEvent extends MembershipEvent {
|
||||
static canRender(event) {
|
||||
return super.canRender(event) && event.content.membership === "invite"
|
||||
static canRender(eventData) {
|
||||
return super.canRender(eventData) && eventData.content.membership === "invite"
|
||||
}
|
||||
|
||||
render() {
|
||||
super.render()
|
||||
return this.text(`invited ${this.data.content.displayname}`)
|
||||
this.renderText(`invited ${this.data.content.displayname}`)
|
||||
}
|
||||
}
|
||||
|
||||
class LeaveEvent extends MembershipEvent {
|
||||
static canRender(event) {
|
||||
return super.canRender(event) && event.content.membership === "leave"
|
||||
static canRender(eventData) {
|
||||
return super.canRender(eventData) && eventData.content.membership === "leave"
|
||||
}
|
||||
|
||||
render() {
|
||||
super.render()
|
||||
return this.text(`left the room`)
|
||||
this.renderText("left the room")
|
||||
}
|
||||
}
|
||||
|
||||
class UnknownMembership extends MembershipEvent {
|
||||
render() {
|
||||
super.render()
|
||||
return this.text("unknown membership event")
|
||||
this.renderText("unknown membership event")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
const {MatrixEvent} = require("./event")
|
||||
const {ejs} = require("../basic")
|
||||
|
||||
class UnknownEvent extends MatrixEvent {
|
||||
static canRender() {
|
||||
return true
|
||||
}
|
||||
|
||||
render() {
|
||||
this.clearChildren()
|
||||
this.child(
|
||||
ejs("i").text(`Unknown event of type ${this.data.type}`)
|
||||
)
|
||||
super.render()
|
||||
return this.text(`cannot render event`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = [UnknownEvent]
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ const {Anchor} = require("./anchor.js")
|
|||
const {Sender} = require("./sender.js")
|
||||
const lsm = require("./lsm.js")
|
||||
const {resolveMxc} = require("./functions.js")
|
||||
const {renderEvent} = require("./events/renderEvent")
|
||||
const {renderEvent} = require("./events/render-event")
|
||||
const {dateFormatter} = require("./date-formatter")
|
||||
|
||||
let debug = false
|
||||
|
|
Loading…
Reference in a new issue
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.