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 {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"
}
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