You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
815 B
JavaScript

"use strict";
const dotty = require("dotty");
const addCommonFields = require("../event-add-common-fields");
function noop() {
return {};
}
module.exports = function mapMaybeRedacted(event, handler) {
let { redacted, notRedacted } = (typeof handler === "function")
? { redacted: noop, notRedacted: handler }
: handler;
let redactionData = dotty.get(event, ["unsigned", "redacted_because"]);
if (redactionData != null) {
return {
... redacted(),
isRedacted: true,
redaction: addCommonFields(redactionData, {
user: redactionData.sender,
isVoluntary: (event.sender != null)
? (redactionData.sender === event.sender)
: undefined,
reason: redactionData.content.reason
})
};
} else {
return {
... notRedacted(),
isRedacted: false,
redaction: {},
};
}
};