Rich message rendering #24

Merged
cadence merged 28 commits from rich-messages into princess 2020-11-07 10:46:48 +00:00
Showing only changes of commit 1a8427925c - Show all commits

View file

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