Small refactors
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

- "event" -> "eventData"
- create renderText method
- italics
This commit is contained in:
Cadence Ember 2020-11-05 16:44:22 +13:00
parent 9cf0952d3a
commit 8ba9d73b33
Signed by: cadence
GPG key ID: BC1C2C61CF521B17
5 changed files with 40 additions and 22 deletions

View file

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

View file

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

View file

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

View file

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

View file

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