Compare commits

...

2 commits

Author SHA1 Message Date
Bad
20bacce068 Remove the simple event shorthand
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2020-10-29 11:31:08 +01:00
Bad
f80bf36991 Style fixes 2020-10-29 11:09:15 +01:00
4 changed files with 58 additions and 28 deletions

View file

@ -14,7 +14,6 @@ class MatrixEvent extends ElemJS {
// predicates
canGroup() {
//return this.data.type === "m.room.message"
return false
}
@ -52,17 +51,4 @@ 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, simpleEvent}
module.exports = {MatrixEvent}

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")
function createMembershipEvent(membership, message) {
return simpleEvent((e) => e.type == "m.room.member" && e.content.membership === membership, message)
class MembershipEvent extends MatrixEvent {
static canRender(event) {
return event.type == "m.room.member"
}
}
const JoinedEvent = createMembershipEvent("join", (e) => "joined the room")
const InvitedEvent = createMembershipEvent("invite", (e) => `invited ${e.content.displayname} the room`)
const LeaveEvent = createMembershipEvent("leave", () => "left the room")
class JoinedEvent extends MembershipEvent {
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]

View file

@ -8,7 +8,7 @@ const {MatrixEvent} = require("./event")
const purifier = DOMPurify()
purifier.addHook("uponSanitizeAttribute", (node, hookevent, config) => {
//If purifier already rejected an attribute there is no point in checking it
// If purifier already rejected an attribute there is no point in checking it
if (hookevent.keepAttr === false) return;
const allowedElementAttributes = {
@ -24,8 +24,8 @@ purifier.addHook("uponSanitizeAttribute", (node, hookevent, config) => {
hookevent.keepAttr = allowed_attributes.indexOf(hookevent.attrName) > -1;
})
//Remove bad classes from our code element
purifier.addHook("uponSanitizeElement", (node, hookevent, config) => {
// Remove bad classes from our code element
if (node.tagName == "CODE") {
node.classList.forEach(c => {
if (!c.startsWith("language-")) {
@ -53,7 +53,7 @@ function cleanHTML(html) {
return purifier.sanitize(html)
}
//Here we put all the processing of the messages that isn't as likely to potentially lead to security issues
// Here we put all the processing of the messages that isn't as likely to potentially lead to security issues
function postProcessElements(rootNode) {
const element = rootNode.element
element.querySelectorAll("code").forEach((n) => rootNode.child(new HighlightedCode(n)))

View file

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