feat: complete Ancestor quote bot with production-ready Docker support
This commit is contained in:
95
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js
generated
vendored
95
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js
generated
vendored
@@ -1,26 +1,31 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
||||
import { isEventTypeSame, M_HTML, M_MESSAGE, M_TEXT } from "../@types/extensible_events.js";
|
||||
import { isOptionalAString, isProvided } from "./utilities.js";
|
||||
import { InvalidEventError } from "./InvalidEventError.js";
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.MessageEvent = void 0;
|
||||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
||||
var _ExtensibleEvent = require("./ExtensibleEvent");
|
||||
var _extensible_events = require("../@types/extensible_events");
|
||||
var _utilities = require("./utilities");
|
||||
var _InvalidEventError = require("./InvalidEventError");
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Represents a message event. Message events are the simplest form of event with
|
||||
* just text (optionally of different mimetypes, like HTML).
|
||||
@@ -28,7 +33,7 @@ import { InvalidEventError } from "./InvalidEventError.js";
|
||||
* Message events can additionally be an Emote or Notice, though typically those
|
||||
* are represented as EmoteEvent and NoticeEvent respectively.
|
||||
*/
|
||||
export class MessageEvent extends ExtensibleEvent {
|
||||
class MessageEvent extends _ExtensibleEvent.ExtensibleEvent {
|
||||
/**
|
||||
* Creates a new MessageEvent from a pure format. Note that the event is
|
||||
* *not* parsed here: it will be treated as a literal m.message primary
|
||||
@@ -40,34 +45,34 @@ export class MessageEvent extends ExtensibleEvent {
|
||||
/**
|
||||
* The default text for the event.
|
||||
*/
|
||||
_defineProperty(this, "text", void 0);
|
||||
(0, _defineProperty2.default)(this, "text", void 0);
|
||||
/**
|
||||
* The default HTML for the event, if provided.
|
||||
*/
|
||||
_defineProperty(this, "html", void 0);
|
||||
(0, _defineProperty2.default)(this, "html", void 0);
|
||||
/**
|
||||
* All the different renderings of the message. Note that this is the same
|
||||
* format as an m.message body but may contain elements not found directly
|
||||
* in the event content: this is because this is interpreted based off the
|
||||
* other information available in the event.
|
||||
*/
|
||||
_defineProperty(this, "renderings", void 0);
|
||||
const mmessage = M_MESSAGE.findIn(this.wireContent);
|
||||
const mtext = M_TEXT.findIn(this.wireContent);
|
||||
const mhtml = M_HTML.findIn(this.wireContent);
|
||||
if (isProvided(mmessage)) {
|
||||
(0, _defineProperty2.default)(this, "renderings", void 0);
|
||||
const mmessage = _extensible_events.M_MESSAGE.findIn(this.wireContent);
|
||||
const mtext = _extensible_events.M_TEXT.findIn(this.wireContent);
|
||||
const mhtml = _extensible_events.M_HTML.findIn(this.wireContent);
|
||||
if ((0, _utilities.isProvided)(mmessage)) {
|
||||
if (!Array.isArray(mmessage)) {
|
||||
throw new InvalidEventError("m.message contents must be an array");
|
||||
throw new _InvalidEventError.InvalidEventError("m.message contents must be an array");
|
||||
}
|
||||
const text = mmessage.find(r => !isProvided(r.mimetype) || r.mimetype === "text/plain");
|
||||
const text = mmessage.find(r => !(0, _utilities.isProvided)(r.mimetype) || r.mimetype === "text/plain");
|
||||
const html = mmessage.find(r => r.mimetype === "text/html");
|
||||
if (!text) throw new InvalidEventError("m.message is missing a plain text representation");
|
||||
if (!text) throw new _InvalidEventError.InvalidEventError("m.message is missing a plain text representation");
|
||||
this.text = text.body;
|
||||
this.html = html?.body;
|
||||
this.html = html === null || html === void 0 ? void 0 : html.body;
|
||||
this.renderings = mmessage;
|
||||
} else if (isOptionalAString(mtext)) {
|
||||
} else if ((0, _utilities.isOptionalAString)(mtext)) {
|
||||
this.text = mtext;
|
||||
this.html = mhtml ?? undefined;
|
||||
this.html = mhtml;
|
||||
this.renderings = [{
|
||||
body: mtext,
|
||||
mimetype: "text/plain"
|
||||
@@ -79,15 +84,15 @@ export class MessageEvent extends ExtensibleEvent {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new InvalidEventError("Missing textual representation for event");
|
||||
throw new _InvalidEventError.InvalidEventError("Missing textual representation for event");
|
||||
}
|
||||
}
|
||||
isEquivalentTo(primaryEventType) {
|
||||
return isEventTypeSame(primaryEventType, M_MESSAGE);
|
||||
return (0, _extensible_events.isEventTypeSame)(primaryEventType, _extensible_events.M_MESSAGE);
|
||||
}
|
||||
serializeMMessageOnly() {
|
||||
let messageRendering = {
|
||||
[M_MESSAGE.name]: this.renderings
|
||||
[_extensible_events.M_MESSAGE.name]: this.renderings
|
||||
};
|
||||
|
||||
// Use the shorthand if it's just a simple text event
|
||||
@@ -95,20 +100,21 @@ export class MessageEvent extends ExtensibleEvent {
|
||||
const mime = this.renderings[0].mimetype;
|
||||
if (mime === undefined || mime === "text/plain") {
|
||||
messageRendering = {
|
||||
[M_TEXT.name]: this.renderings[0].body
|
||||
[_extensible_events.M_TEXT.name]: this.renderings[0].body
|
||||
};
|
||||
}
|
||||
}
|
||||
return messageRendering;
|
||||
}
|
||||
serialize() {
|
||||
var _this$html;
|
||||
return {
|
||||
type: "m.room.message",
|
||||
content: _objectSpread(_objectSpread({}, this.serializeMMessageOnly()), {}, {
|
||||
body: this.text,
|
||||
msgtype: "m.text",
|
||||
format: this.html ? "org.matrix.custom.html" : undefined,
|
||||
formatted_body: this.html ?? undefined
|
||||
formatted_body: (_this$html = this.html) !== null && _this$html !== void 0 ? _this$html : undefined
|
||||
})
|
||||
};
|
||||
}
|
||||
@@ -121,12 +127,13 @@ export class MessageEvent extends ExtensibleEvent {
|
||||
*/
|
||||
static from(text, html) {
|
||||
return new MessageEvent({
|
||||
type: M_MESSAGE.name,
|
||||
type: _extensible_events.M_MESSAGE.name,
|
||||
content: {
|
||||
[M_TEXT.name]: text,
|
||||
[M_HTML.name]: html
|
||||
[_extensible_events.M_TEXT.name]: text,
|
||||
[_extensible_events.M_HTML.name]: html
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.MessageEvent = MessageEvent;
|
||||
//# sourceMappingURL=MessageEvent.js.map
|
||||
Reference in New Issue
Block a user