Rich message rendering #24
1 changed files with 14 additions and 3 deletions
|
@ -1,10 +1,10 @@
|
||||||
const {Event} = require("./event")
|
const {Event} = require("./event")
|
||||||
|
|
||||||
function createMembershipEvent(membership, text) {
|
function createMembershipEvent(membership, message) {
|
||||||
return class extends Event {
|
return class extends Event {
|
||||||
render() {
|
render() {
|
||||||
super.render()
|
super.render()
|
||||||
return this.text(text(this.data))
|
return this.text(message(this.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
static canRender(event) {
|
static canRender(event) {
|
||||||
|
@ -13,9 +13,20 @@ function createMembershipEvent(membership, text) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class UnknownMembership extends Event {
|
||||||
|
render() {
|
||||||
|
super.render()
|
||||||
|
return this.text("Unsupported membership event")
|
||||||
|
}
|
||||||
|
|
||||||
|
static canRender(event) {
|
||||||
|
return event.type == "m.room.member"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const JoinedEvent = createMembershipEvent("join", () => "joined the room")
|
const JoinedEvent = createMembershipEvent("join", () => "joined the room")
|
||||||
const InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`)
|
const InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`)
|
||||||
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
|
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
|
||||||
|
|
||||||
module.exports = [JoinedEvent, InvitedEvent, LeaveEvent]
|
module.exports = [JoinedEvent, InvitedEvent, LeaveEvent, UnknownMembership]
|
||||||
|
|
Loading…
Reference in a new issue