Rich message rendering #24
3 changed files with 20 additions and 39 deletions
|
@ -50,6 +50,17 @@ class MatrixEvent extends ElemJS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function simpleEvent(filter, render) {
|
||||||
|
return class extends MatrixEvent {
|
||||||
|
render() {
|
||||||
|
super.render()
|
||||||
|
return this.text(render(this.data))
|
||||||
|
}
|
||||||
|
|
||||||
|
static canRender(event) {
|
||||||
|
return filter(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {MatrixEvent}
|
module.exports = {MatrixEvent, simpleEvent}
|
||||||
|
|
|
@ -1,31 +1,12 @@
|
||||||
const {MatrixEvent} = require("./event")
|
const {simpleEvent} = require("./event")
|
||||||
|
|
||||||
|
const UnknownMembership = simpleEvent((e) => e.type == "m.room.member", (e) => "unknown membership event")
|
||||||
|
|
||||||
function createMembershipEvent(membership, message) {
|
function createMembershipEvent(membership, message) {
|
||||||
return class extends MatrixEvent {
|
return simpleEvent((e) => e.type == "m.room.member" && e.content.membership === membership, message)
|
||||||
render() {
|
|
||||||
super.render()
|
|
||||||
return this.text(message(this.data))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static canRender(event) {
|
const JoinedEvent = createMembershipEvent("join", (e) => {console.log(e); return "joined the room"})
|
||||||
return event.type == "m.room.member" && event.content.membership == membership
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class UnknownMembership extends MatrixEvent {
|
|
||||||
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 InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`)
|
||||||
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
|
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
const {MatrixEvent} = require("./event")
|
const {simpleEvent} = require("./event")
|
||||||
|
const UnknownEvent = simpleEvent(() => true, () => "Cannot render event")
|
||||||
class UnknownEvent extends MatrixEvent {
|
console.log(UnknownEvent)
|
||||||
render() {
|
|
||||||
super.render()
|
|
||||||
this.text("Cannot render event")
|
|
||||||
}
|
|
||||||
|
|
||||||
static canRender(_event) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = [UnknownEvent]
|
module.exports = [UnknownEvent]
|
||||||
|
|
Loading…
Reference in a new issue