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")
function createMembershipEvent(membership, text) {
function createMembershipEvent(membership, message) {
return class extends Event {
render() {
super.render()
bad marked this conversation as resolved Outdated

Again here. I think a better way would be to have a base class like MembershipEvent, and then for each kind of membership we subclass it and only implement the canRender method on each.

Again here. I think a better way would be to have a base class like MembershipEvent, and then for each kind of membership we subclass it and only implement the canRender method on each.
return this.text(text(this.data))
return this.text(message(this.data))
}
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 InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`)
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
module.exports = [JoinedEvent, InvitedEvent, LeaveEvent]
module.exports = [JoinedEvent, InvitedEvent, LeaveEvent, UnknownMembership]