Remove the simple event shorthand
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Bad 2020-10-29 11:31:08 +01:00
parent f80bf36991
commit 20bacce068
3 changed files with 55 additions and 24 deletions

View file

@ -51,17 +51,4 @@ class MatrixEvent extends ElemJS {
} }
} }
function simpleEvent(filter, render) { module.exports = {MatrixEvent}
return class extends MatrixEvent {
render() {
super.render()
return this.text(render(this.data))
}
static canRender(event) {
return filter(event)
}
}
}
module.exports = {MatrixEvent, simpleEvent}

View file

@ -1,13 +1,47 @@
const {simpleEvent} = require("./event") const {MatrixEvent} = require("./event")
const UnknownMembership = simpleEvent((e) => e.type == "m.room.member", (e) => "unknown membership event") class MembershipEvent extends MatrixEvent {
static canRender(event) {
function createMembershipEvent(membership, message) { return event.type == "m.room.member"
return simpleEvent((e) => e.type == "m.room.member" && e.content.membership === membership, message) }
} }
const JoinedEvent = createMembershipEvent("join", (e) => "joined the room")
const InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`) class JoinedEvent extends MembershipEvent {
const LeaveEvent = createMembershipEvent("leave", () => "left the room") static canRender(event) {
return super.canRender(event) && event.content.membership === "join"
}
render() {
super.render()
return this.text("joined the room")
}
}
class InvitedEvent extends MembershipEvent {
static canRender(event) {
return super.canRender(event) && event.content.membership === "invite"
}
render() {
super.render()
return this.text(`invited ${this.data.content.displayname}`)
}
}
class LeaveEvent extends MembershipEvent {
static canRender(event) {
return super.canRender(event) && event.content.membership === "leave"
}
render() {
super.render()
return this.text(`left the room`)
}
}
class UnknownMembership extends MembershipEvent {
render() {
super.render()
return this.text("unknown membership event")
}
}
module.exports = [JoinedEvent, InvitedEvent, LeaveEvent, UnknownMembership] module.exports = [JoinedEvent, InvitedEvent, LeaveEvent, UnknownMembership]

View file

@ -1,3 +1,13 @@
const {simpleEvent} = require("./event") const {MatrixEvent} = require("./event")
const UnknownEvent = simpleEvent(() => true, () => "Cannot render event")
class UnknownEvent extends MatrixEvent {
static canRender() {
return true
}
render() {
super.render()
return this.text(`cannot render event`)
}
}
module.exports = [UnknownEvent] module.exports = [UnknownEvent]