This commit is contained in:
unfunny
2026-09-12 23:57:45 -04:00
parent 986c0af682
commit dfe4cc537f
1775 changed files with 246421 additions and 0 deletions

201
node_modules/matrix-events-sdk/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

78
node_modules/matrix-events-sdk/README.md generated vendored Normal file
View File

@@ -0,0 +1,78 @@
# matrix-events-sdk
JS/TS SDK for handling (extensible) events in Matrix
## 🚨🚨 Project is a work in progress
The architecture and approach of this repo is still being considered and is subject to breaking
changes. Use at your own risk.
As a general guide, functionality which is foundational to events (such as text, images, etc)
should be incorporated in this repo before the more complex types. This is to ensure that the
architecture is up to the task of handling proper extensible events.
## Usage: Parsing events
```typescript
const parsed = ExtensibleEvents.parse({
type: "m.room.message",
content: {
"msgtype": "m.text",
"body": "Hello world!"
},
// and other fields
}) as MessageEvent;
// Using instanceof can be unsafe in some cases, but casting the
// response in TypeScript (as above) should be safe given this
// if statement will block non-message types anyhow.
if (parsed?.isEquivalentTo(M_MESSAGE)) {
console.log(parsed.text);
}
```
*Note*: `instanceof` isn't considered safe for projects which might be running multiple copies
of the library, such as in clients which have layers needing access to the events-sdk individually.
If you would like to register your own handling of events, use the following:
```typescript
type MyContent = M_MESSAGE_EVENT_CONTENT & {
field: string;
};
class MyEvent extends MessageEvent {
public readonly field: string;
constructor(wireFormat: IPartialEvent<MyContent>) {
// Parse the text bit of the event
super(wireFormat);
this.field = wireFormat.content?.field;
}
}
function parseMyEvent(wireEvent: IPartialEvent<MyContent>): Optional<MyEvent> {
// If you need to convert a legacy format, this is where you'd do it. Your
// event class should be able to be instatiated outside of this parse function.
return new MyEvent(wireEvent);
}
ExtensibleEvents.registerInterpreter("org.example.my_event_type", parseMyEvent);
ExtensibleEvents.unknownInterpretOrder.push("org.example.my_event_type");
```
## Usage: Making events
Most event objects have a `from` static function which takes common details of an event
and returns an instance of that event for later serialization.
```typescript
const userInput = "**hello**";
const htmlInput = "<b>hello</b>"; // might be after running through a markdown processor
const message = MessageEvent.from(userInput, htmlInput).serialize();
// Finally, assuming your client instance is called `client`:
client.sendEvent(message.type, message.content);
```

View File

@@ -0,0 +1,74 @@
import { IPartialEvent } from "./IPartialEvent";
import { ExtensibleEvent } from "./events/ExtensibleEvent";
import { Optional } from "./types";
import { NamespacedValue } from "./NamespacedValue";
export declare type EventInterpreter<TContentIn = object, TEvent extends ExtensibleEvent = ExtensibleEvent> = (wireEvent: IPartialEvent<TContentIn>) => Optional<TEvent>;
/**
* Utility class for parsing and identifying event types in a renderable form. An
* instance of this class can be created to change rendering preference depending
* on use-case.
*/
export declare class ExtensibleEvents {
private static _defaultInstance;
private interpreters;
private _unknownInterpretOrder;
constructor();
/**
* Gets the default instance for all extensible event parsing.
*/
static get defaultInstance(): ExtensibleEvents;
/**
* Gets the order the internal processor will use for unknown primary
* event types.
*/
get unknownInterpretOrder(): NamespacedValue<string, string>[];
/**
* Sets the order the internal processor will use for unknown primary
* event types.
* @param {NamespacedValue<string, string>[]} val The parsing order.
*/
set unknownInterpretOrder(val: NamespacedValue<string, string>[]);
/**
* Gets the order the internal processor will use for unknown primary
* event types.
*/
static get unknownInterpretOrder(): NamespacedValue<string, string>[];
/**
* Sets the order the internal processor will use for unknown primary
* event types.
* @param {NamespacedValue<string, string>[]} val The parsing order.
*/
static set unknownInterpretOrder(val: NamespacedValue<string, string>[]);
/**
* Registers a primary event type interpreter. Note that the interpreter might be
* called with non-primary events if the event is being parsed as a fallback.
* @param {NamespacedValue<string, string>} wireEventType The event type.
* @param {EventInterpreter} interpreter The interpreter.
*/
registerInterpreter(wireEventType: NamespacedValue<string, string>, interpreter: EventInterpreter): void;
/**
* Registers a primary event type interpreter. Note that the interpreter might be
* called with non-primary events if the event is being parsed as a fallback.
* @param {NamespacedValue<string, string>} wireEventType The event type.
* @param {EventInterpreter} interpreter The interpreter.
*/
static registerInterpreter(wireEventType: NamespacedValue<string, string>, interpreter: EventInterpreter): void;
/**
* Parses an event, trying the primary event type first. If the primary type is not known
* then the content will be inspected to find the most suitable fallback.
*
* If the parsing failed or was a completely unknown type, this will return falsy.
* @param {IPartialEvent<object>} wireFormat The event to parse.
* @returns {Optional<ExtensibleEvent>} The parsed extensible event.
*/
parse(wireFormat: IPartialEvent<object>): Optional<ExtensibleEvent>;
/**
* Parses an event, trying the primary event type first. If the primary type is not known
* then the content will be inspected to find the most suitable fallback.
*
* If the parsing failed or was a completely unknown type, this will return falsy.
* @param {IPartialEvent<object>} wireFormat The event to parse.
* @returns {Optional<ExtensibleEvent>} The parsed extensible event.
*/
static parse(wireFormat: IPartialEvent<object>): Optional<ExtensibleEvent>;
}

189
node_modules/matrix-events-sdk/lib/ExtensibleEvents.js generated vendored Normal file
View File

@@ -0,0 +1,189 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExtensibleEvents = void 0;
var _NamespacedMap = require("./NamespacedMap");
var _InvalidEventError = require("./InvalidEventError");
var _MRoomMessage = require("./interpreters/legacy/MRoomMessage");
var _MMessage = require("./interpreters/modern/MMessage");
var _message_types = require("./events/message_types");
var _poll_types = require("./events/poll_types");
var _MPoll = require("./interpreters/modern/MPoll");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Utility class for parsing and identifying event types in a renderable form. An
* instance of this class can be created to change rendering preference depending
* on use-case.
*/
var ExtensibleEvents = /*#__PURE__*/function () {
function ExtensibleEvents() {
_classCallCheck(this, ExtensibleEvents);
_defineProperty(this, "interpreters", new _NamespacedMap.NamespacedMap([// Remember to add your unit test when adding to this! ("known events" test description)
[_MRoomMessage.LEGACY_M_ROOM_MESSAGE, _MRoomMessage.parseMRoomMessage], [_message_types.M_MESSAGE, _MMessage.parseMMessage], [_message_types.M_EMOTE, _MMessage.parseMMessage], [_message_types.M_NOTICE, _MMessage.parseMMessage], [_poll_types.M_POLL_START, _MPoll.parseMPoll], [_poll_types.M_POLL_RESPONSE, _MPoll.parseMPoll], [_poll_types.M_POLL_END, _MPoll.parseMPoll]]));
_defineProperty(this, "_unknownInterpretOrder", [_message_types.M_MESSAGE]);
}
/**
* Gets the default instance for all extensible event parsing.
*/
_createClass(ExtensibleEvents, [{
key: "unknownInterpretOrder",
get:
/**
* Gets the order the internal processor will use for unknown primary
* event types.
*/
function get() {
var _this$_unknownInterpr;
return (_this$_unknownInterpr = this._unknownInterpretOrder) !== null && _this$_unknownInterpr !== void 0 ? _this$_unknownInterpr : [];
}
/**
* Sets the order the internal processor will use for unknown primary
* event types.
* @param {NamespacedValue<string, string>[]} val The parsing order.
*/
,
set: function set(val) {
this._unknownInterpretOrder = val;
}
/**
* Gets the order the internal processor will use for unknown primary
* event types.
*/
}, {
key: "registerInterpreter",
value:
/**
* Registers a primary event type interpreter. Note that the interpreter might be
* called with non-primary events if the event is being parsed as a fallback.
* @param {NamespacedValue<string, string>} wireEventType The event type.
* @param {EventInterpreter} interpreter The interpreter.
*/
function registerInterpreter(wireEventType, interpreter) {
this.interpreters.set(wireEventType, interpreter);
}
/**
* Registers a primary event type interpreter. Note that the interpreter might be
* called with non-primary events if the event is being parsed as a fallback.
* @param {NamespacedValue<string, string>} wireEventType The event type.
* @param {EventInterpreter} interpreter The interpreter.
*/
}, {
key: "parse",
value:
/**
* Parses an event, trying the primary event type first. If the primary type is not known
* then the content will be inspected to find the most suitable fallback.
*
* If the parsing failed or was a completely unknown type, this will return falsy.
* @param {IPartialEvent<object>} wireFormat The event to parse.
* @returns {Optional<ExtensibleEvent>} The parsed extensible event.
*/
function parse(wireFormat) {
try {
if (this.interpreters.hasNamespaced(wireFormat.type)) {
return this.interpreters.getNamespaced(wireFormat.type)(wireFormat);
}
var _iterator = _createForOfIteratorHelper(this.unknownInterpretOrder),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var tryType = _step.value;
if (this.interpreters.has(tryType)) {
var val = this.interpreters.get(tryType)(wireFormat);
if (val) return val;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return null; // cannot be parsed
} catch (e) {
if (e instanceof _InvalidEventError.InvalidEventError) {
return null; // fail parsing and move on
}
throw e; // re-throw everything else
}
}
/**
* Parses an event, trying the primary event type first. If the primary type is not known
* then the content will be inspected to find the most suitable fallback.
*
* If the parsing failed or was a completely unknown type, this will return falsy.
* @param {IPartialEvent<object>} wireFormat The event to parse.
* @returns {Optional<ExtensibleEvent>} The parsed extensible event.
*/
}], [{
key: "defaultInstance",
get: function get() {
return ExtensibleEvents._defaultInstance;
}
}, {
key: "unknownInterpretOrder",
get: function get() {
return ExtensibleEvents.defaultInstance.unknownInterpretOrder;
}
/**
* Sets the order the internal processor will use for unknown primary
* event types.
* @param {NamespacedValue<string, string>[]} val The parsing order.
*/
,
set: function set(val) {
ExtensibleEvents.defaultInstance.unknownInterpretOrder = val;
}
}, {
key: "registerInterpreter",
value: function registerInterpreter(wireEventType, interpreter) {
ExtensibleEvents.defaultInstance.registerInterpreter(wireEventType, interpreter);
}
}, {
key: "parse",
value: function parse(wireFormat) {
return ExtensibleEvents.defaultInstance.parse(wireFormat);
}
}]);
return ExtensibleEvents;
}();
exports.ExtensibleEvents = ExtensibleEvents;
_defineProperty(ExtensibleEvents, "_defaultInstance", new ExtensibleEvents());

View File

@@ -0,0 +1,7 @@
/**
* Partial types for a Matrix Event.
*/
export interface IPartialEvent<TContent> {
type: string;
content: TContent;
}

5
node_modules/matrix-events-sdk/lib/IPartialEvent.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -0,0 +1,6 @@
/**
* Thrown when an event is unforgivably unparsable.
*/
export declare class InvalidEventError extends Error {
constructor(message: string);
}

View File

@@ -0,0 +1,69 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.InvalidEventError = void 0;
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/*
Copyright 2022 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.
*/
/**
* Thrown when an event is unforgivably unparsable.
*/
var InvalidEventError = /*#__PURE__*/function (_Error) {
_inherits(InvalidEventError, _Error);
var _super = _createSuper(InvalidEventError);
function InvalidEventError(message) {
_classCallCheck(this, InvalidEventError);
return _super.call(this, message);
}
return _createClass(InvalidEventError);
}( /*#__PURE__*/_wrapNativeSuper(Error));
exports.InvalidEventError = InvalidEventError;

55
node_modules/matrix-events-sdk/lib/NamespacedMap.d.ts generated vendored Normal file
View File

@@ -0,0 +1,55 @@
import { NamespacedValue } from "./NamespacedValue";
import { Optional } from "./types";
declare type NS = NamespacedValue<string, string>;
/**
* A `Map` implementation which accepts a NamespacedValue as a key, and arbitrary value. The
* namespaced value must be a string type.
*/
export declare class NamespacedMap<V> {
protected internalMap: Map<string, V>;
/**
* Creates a new map with optional seed data.
* @param {Array<[NS, V]>} initial The seed data.
*/
constructor(initial?: [NS, V][]);
/**
* Gets a value from the map. If the value does not exist under
* either namespace option, falsy is returned.
* @param {NS} key The key.
* @returns {Optional<V>} The value, or falsy.
*/
get(key: NS): Optional<V>;
/**
* Sets a value in the map.
* @param {NS} key The key.
* @param {V} val The value.
*/
set(key: NS, val: V): void;
/**
* Determines if any of the valid namespaced values are present
* in the map.
* @param {NS} key The key.
* @returns {boolean} True if present.
*/
has(key: NS): boolean;
/**
* Removes all the namespaced values from the map.
* @param {NS} key The key.
*/
delete(key: NS): void;
/**
* Determines if the map contains a specific namespaced value
* instead of the parent NS type.
* @param {string} key The key.
* @returns {boolean} True if present.
*/
hasNamespaced(key: string): boolean;
/**
* Gets a specific namespaced value from the map instead of the
* parent NS type. Returns falsy if not found.
* @param {string} key The key.
* @returns {Optional<V>} The value, or falsy.
*/
getNamespaced(key: string): Optional<V>;
}
export {};

149
node_modules/matrix-events-sdk/lib/NamespacedMap.js generated vendored Normal file
View File

@@ -0,0 +1,149 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NamespacedMap = void 0;
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* A `Map` implementation which accepts a NamespacedValue as a key, and arbitrary value. The
* namespaced value must be a string type.
*/
var NamespacedMap = /*#__PURE__*/function () {
// protected to make tests happy for access
/**
* Creates a new map with optional seed data.
* @param {Array<[NS, V]>} initial The seed data.
*/
function NamespacedMap(initial) {
_classCallCheck(this, NamespacedMap);
_defineProperty(this, "internalMap", new Map());
if (initial) {
var _iterator = _createForOfIteratorHelper(initial),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var val = _step.value;
this.set(val[0], val[1]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
}
/**
* Gets a value from the map. If the value does not exist under
* either namespace option, falsy is returned.
* @param {NS} key The key.
* @returns {Optional<V>} The value, or falsy.
*/
_createClass(NamespacedMap, [{
key: "get",
value: function get(key) {
if (key.name && this.internalMap.has(key.name)) {
return this.internalMap.get(key.name);
}
if (key.altName && this.internalMap.has(key.altName)) {
return this.internalMap.get(key.altName);
}
return null;
}
/**
* Sets a value in the map.
* @param {NS} key The key.
* @param {V} val The value.
*/
}, {
key: "set",
value: function set(key, val) {
if (key.name) {
this.internalMap.set(key.name, val);
}
if (key.altName) {
this.internalMap.set(key.altName, val);
}
}
/**
* Determines if any of the valid namespaced values are present
* in the map.
* @param {NS} key The key.
* @returns {boolean} True if present.
*/
}, {
key: "has",
value: function has(key) {
return !!this.get(key);
}
/**
* Removes all the namespaced values from the map.
* @param {NS} key The key.
*/
}, {
key: "delete",
value: function _delete(key) {
if (key.name) {
this.internalMap["delete"](key.name);
}
if (key.altName) {
this.internalMap["delete"](key.altName);
}
}
/**
* Determines if the map contains a specific namespaced value
* instead of the parent NS type.
* @param {string} key The key.
* @returns {boolean} True if present.
*/
}, {
key: "hasNamespaced",
value: function hasNamespaced(key) {
return this.internalMap.has(key);
}
/**
* Gets a specific namespaced value from the map instead of the
* parent NS type. Returns falsy if not found.
* @param {string} key The key.
* @returns {Optional<V>} The value, or falsy.
*/
}, {
key: "getNamespaced",
value: function getNamespaced(key) {
return this.internalMap.get(key);
}
}]);
return NamespacedMap;
}();
exports.NamespacedMap = NamespacedMap;

View File

@@ -0,0 +1,24 @@
import { Optional } from "./types";
/**
* Represents a simple Matrix namespaced value. This will assume that if a stable prefix
* is provided that the stable prefix should be used when representing the identifier.
*/
export declare class NamespacedValue<S extends string, U extends string> {
readonly stable: Optional<S>;
readonly unstable?: U;
constructor(stable: Optional<S>, unstable?: U);
get name(): U | S;
get altName(): U | S | null;
matches(val: string): boolean;
findIn<T>(obj: any): Optional<T>;
includedIn(arr: any[]): boolean;
}
/**
* Represents a namespaced value which prioritizes the unstable value over the stable
* value.
*/
export declare class UnstableValue<S extends string, U extends string> extends NamespacedValue<S, U> {
constructor(stable: S, unstable: U);
get name(): U;
get altName(): S;
}

166
node_modules/matrix-events-sdk/lib/NamespacedValue.js generated vendored Normal file
View File

@@ -0,0 +1,166 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UnstableValue = exports.NamespacedValue = void 0;
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
/*
Copyright 2021 - 2022 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 simple Matrix namespaced value. This will assume that if a stable prefix
* is provided that the stable prefix should be used when representing the identifier.
*/
var NamespacedValue = /*#__PURE__*/function () {
// Stable is optional, but one of the two parameters is required, hence the weird-looking types.
// Goal is to have developers explicitly say there is no stable value (if applicable).
function NamespacedValue(stable, unstable) {
_classCallCheck(this, NamespacedValue);
this.stable = stable;
this.unstable = unstable;
if (!this.unstable && !this.stable) {
throw new Error("One of stable or unstable values must be supplied");
}
}
_createClass(NamespacedValue, [{
key: "name",
get: function get() {
if (this.stable) {
return this.stable;
}
return this.unstable;
}
}, {
key: "altName",
get: function get() {
if (!this.stable) {
return null;
}
return this.unstable;
}
}, {
key: "matches",
value: function matches(val) {
return !!this.name && this.name === val || !!this.altName && this.altName === val;
} // this desperately wants https://github.com/microsoft/TypeScript/pull/26349 at the top level of the class
// so we can instantiate `NamespacedValue<string, _, _>` as a default type for that namespace.
}, {
key: "findIn",
value: function findIn(obj) {
var val;
if (this.name) {
val = obj === null || obj === void 0 ? void 0 : obj[this.name];
}
if (!val && this.altName) {
val = obj === null || obj === void 0 ? void 0 : obj[this.altName];
}
return val;
}
}, {
key: "includedIn",
value: function includedIn(arr) {
var included = false;
if (this.name) {
included = arr.includes(this.name);
}
if (!included && this.altName) {
included = arr.includes(this.altName);
}
return included;
}
}]);
return NamespacedValue;
}();
/**
* Represents a namespaced value which prioritizes the unstable value over the stable
* value.
*/
exports.NamespacedValue = NamespacedValue;
var UnstableValue = /*#__PURE__*/function (_NamespacedValue) {
_inherits(UnstableValue, _NamespacedValue);
var _super = _createSuper(UnstableValue);
// Note: Constructor difference is that `unstable` is *required*.
function UnstableValue(stable, unstable) {
var _this;
_classCallCheck(this, UnstableValue);
_this = _super.call(this, stable, unstable);
if (!_this.unstable) {
throw new Error("Unstable value must be supplied");
}
return _this;
}
_createClass(UnstableValue, [{
key: "name",
get: function get() {
return this.unstable;
}
}, {
key: "altName",
get: function get() {
return this.stable;
}
}]);
return UnstableValue;
}(NamespacedValue);
exports.UnstableValue = UnstableValue;

View File

@@ -0,0 +1,21 @@
import { MessageEvent } from "./MessageEvent";
import { IPartialEvent } from "../IPartialEvent";
import { M_EMOTE_EVENT_CONTENT } from "./message_types";
import { EventType } from "../utility/events";
/**
* Represents an emote. This is essentially a MessageEvent with
* emote characteristics considered.
*/
export declare class EmoteEvent extends MessageEvent {
constructor(wireFormat: IPartialEvent<M_EMOTE_EVENT_CONTENT>);
get isEmote(): boolean;
isEquivalentTo(primaryEventType: EventType): boolean;
serialize(): IPartialEvent<object>;
/**
* Creates a new EmoteEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
static from(text: string, html?: string): EmoteEvent;
}

View File

@@ -0,0 +1,99 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EmoteEvent = void 0;
var _MessageEvent2 = require("./MessageEvent");
var _message_types = require("./message_types");
var _events = require("../utility/events");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
// Emote events are just decorated message events
/**
* Represents an emote. This is essentially a MessageEvent with
* emote characteristics considered.
*/
var EmoteEvent = /*#__PURE__*/function (_MessageEvent) {
_inherits(EmoteEvent, _MessageEvent);
var _super = _createSuper(EmoteEvent);
function EmoteEvent(wireFormat) {
_classCallCheck(this, EmoteEvent);
return _super.call(this, wireFormat);
}
_createClass(EmoteEvent, [{
key: "isEmote",
get: function get() {
return true; // override
}
}, {
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _message_types.M_EMOTE) || _get(_getPrototypeOf(EmoteEvent.prototype), "isEquivalentTo", this).call(this, primaryEventType);
}
}, {
key: "serialize",
value: function serialize() {
var message = _get(_getPrototypeOf(EmoteEvent.prototype), "serialize", this).call(this);
message.content['msgtype'] = "m.emote";
return message;
}
/**
* Creates a new EmoteEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
}], [{
key: "from",
value: function from(text, html) {
var _content;
return new EmoteEvent({
type: _message_types.M_EMOTE.name,
content: (_content = {}, _defineProperty(_content, _message_types.M_TEXT.name, text), _defineProperty(_content, _message_types.M_HTML.name, html), _content)
});
}
}]);
return EmoteEvent;
}(_MessageEvent2.MessageEvent);
exports.EmoteEvent = EmoteEvent;

View File

@@ -0,0 +1,38 @@
import { IPartialEvent } from "../IPartialEvent";
import { EventType } from "../utility/events";
/**
* Represents an Extensible Event in Matrix.
*/
export declare abstract class ExtensibleEvent<TContent extends object = object> {
readonly wireFormat: IPartialEvent<TContent>;
protected constructor(wireFormat: IPartialEvent<TContent>);
/**
* Shortcut to wireFormat.content
*/
get wireContent(): TContent;
/**
* Serializes the event into a format which can be used to send the
* event to the room.
* @returns {IPartialEvent<object>} The serialized event.
*/
abstract serialize(): IPartialEvent<object>;
/**
* Determines if this event is equivalent to the provided event type.
* This is recommended over `instanceof` checks due to issues in the JS
* runtime (and layering of dependencies in some projects).
*
* Implementations should pass this check off to their super classes
* if their own checks fail. Some primary implementations do not extend
* fallback classes given they support the primary type first. Thus,
* those classes may return false if asked about their fallback
* representation.
*
* Note that this only checks primary event types: legacy events, like
* m.room.message, should/will fail this check.
* @param {EventType} primaryEventType The (potentially namespaced) event
* type.
* @returns {boolean} True if this event *could* be represented as the
* given type.
*/
abstract isEquivalentTo(primaryEventType: EventType): boolean;
}

View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ExtensibleEvent = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
/*
Copyright 2021 - 2022 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 an Extensible Event in Matrix.
*/
var ExtensibleEvent = /*#__PURE__*/function () {
function ExtensibleEvent(wireFormat) {
_classCallCheck(this, ExtensibleEvent);
this.wireFormat = wireFormat;
}
/**
* Shortcut to wireFormat.content
*/
_createClass(ExtensibleEvent, [{
key: "wireContent",
get: function get() {
return this.wireFormat.content;
}
/**
* Serializes the event into a format which can be used to send the
* event to the room.
* @returns {IPartialEvent<object>} The serialized event.
*/
}]);
return ExtensibleEvent;
}();
exports.ExtensibleEvent = ExtensibleEvent;

View File

@@ -0,0 +1,58 @@
import { ExtensibleEvent } from "./ExtensibleEvent";
import { IPartialEvent } from "../IPartialEvent";
import { Optional } from "../types";
import { IMessageRendering, M_MESSAGE_EVENT_CONTENT } from "./message_types";
import { EventType } from "../utility/events";
/**
* Represents a message event. Message events are the simplest form of event with
* just text (optionally of different mimetypes, like HTML).
*
* Message events can additionally be an Emote or Notice, though typically those
* are represented as EmoteEvent and NoticeEvent respectively.
*/
export declare class MessageEvent extends ExtensibleEvent<M_MESSAGE_EVENT_CONTENT> {
/**
* The default text for the event.
*/
readonly text: string;
/**
* The default HTML for the event, if provided.
*/
readonly html: Optional<string>;
/**
* 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.
*/
readonly renderings: IMessageRendering[];
/**
* 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
* typed event.
* @param {IPartialEvent<M_MESSAGE_EVENT_CONTENT>} wireFormat The event.
*/
constructor(wireFormat: IPartialEvent<M_MESSAGE_EVENT_CONTENT>);
/**
* Gets whether this message is considered an "emote". Note that a message
* might be an emote and notice at the same time: while technically possible,
* the event should be interpreted as one or the other.
*/
get isEmote(): boolean;
/**
* Gets whether this message is considered a "notice". Note that a message
* might be an emote and notice at the same time: while technically possible,
* the event should be interpreted as one or the other.
*/
get isNotice(): boolean;
isEquivalentTo(primaryEventType: EventType): boolean;
protected serializeMMessageOnly(): M_MESSAGE_EVENT_CONTENT;
serialize(): IPartialEvent<object>;
/**
* Creates a new MessageEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
static from(text: string, html?: string): MessageEvent;
}

View File

@@ -0,0 +1,214 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MessageEvent = void 0;
var _ExtensibleEvent2 = require("./ExtensibleEvent");
var _types = require("../types");
var _InvalidEventError = require("../InvalidEventError");
var _message_types = require("./message_types");
var _events = require("../utility/events");
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) { _defineProperty(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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Represents a message event. Message events are the simplest form of event with
* just text (optionally of different mimetypes, like HTML).
*
* Message events can additionally be an Emote or Notice, though typically those
* are represented as EmoteEvent and NoticeEvent respectively.
*/
var MessageEvent = /*#__PURE__*/function (_ExtensibleEvent) {
_inherits(MessageEvent, _ExtensibleEvent);
var _super = _createSuper(MessageEvent);
/**
* The default text for the event.
*/
/**
* The default HTML for the event, if provided.
*/
/**
* 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.
*/
/**
* 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
* typed event.
* @param {IPartialEvent<M_MESSAGE_EVENT_CONTENT>} wireFormat The event.
*/
function MessageEvent(wireFormat) {
var _this;
_classCallCheck(this, MessageEvent);
_this = _super.call(this, wireFormat);
_defineProperty(_assertThisInitialized(_this), "text", void 0);
_defineProperty(_assertThisInitialized(_this), "html", void 0);
_defineProperty(_assertThisInitialized(_this), "renderings", void 0);
var mmessage = _message_types.M_MESSAGE.findIn(_this.wireContent);
var mtext = _message_types.M_TEXT.findIn(_this.wireContent);
var mhtml = _message_types.M_HTML.findIn(_this.wireContent);
if ((0, _types.isProvided)(mmessage)) {
if (!Array.isArray(mmessage)) {
throw new _InvalidEventError.InvalidEventError("m.message contents must be an array");
}
var text = mmessage.find(function (r) {
return !(0, _types.isProvided)(r.mimetype) || r.mimetype === "text/plain";
});
var html = mmessage.find(function (r) {
return r.mimetype === "text/html";
});
if (!text) throw new _InvalidEventError.InvalidEventError("m.message is missing a plain text representation");
_this.text = text.body;
_this.html = html === null || html === void 0 ? void 0 : html.body;
_this.renderings = mmessage;
} else if ((0, _types.isOptionalAString)(mtext)) {
_this.text = mtext;
_this.html = mhtml;
_this.renderings = [{
body: mtext,
mimetype: "text/plain"
}];
if (_this.html) {
_this.renderings.push({
body: _this.html,
mimetype: "text/html"
});
}
} else {
throw new _InvalidEventError.InvalidEventError("Missing textual representation for event");
}
return _this;
}
/**
* Gets whether this message is considered an "emote". Note that a message
* might be an emote and notice at the same time: while technically possible,
* the event should be interpreted as one or the other.
*/
_createClass(MessageEvent, [{
key: "isEmote",
get: function get() {
return _message_types.M_EMOTE.matches(this.wireFormat.type) || (0, _types.isProvided)(_message_types.M_EMOTE.findIn(this.wireFormat.content));
}
/**
* Gets whether this message is considered a "notice". Note that a message
* might be an emote and notice at the same time: while technically possible,
* the event should be interpreted as one or the other.
*/
}, {
key: "isNotice",
get: function get() {
return _message_types.M_NOTICE.matches(this.wireFormat.type) || (0, _types.isProvided)(_message_types.M_NOTICE.findIn(this.wireFormat.content));
}
}, {
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _message_types.M_MESSAGE);
}
}, {
key: "serializeMMessageOnly",
value: function serializeMMessageOnly() {
var messageRendering = _defineProperty({}, _message_types.M_MESSAGE.name, this.renderings); // Use the shorthand if it's just a simple text event
if (this.renderings.length === 1) {
var mime = this.renderings[0].mimetype;
if (mime === undefined || mime === "text/plain") {
messageRendering = _defineProperty({}, _message_types.M_TEXT.name, this.renderings[0].body);
}
}
return messageRendering;
}
}, {
key: "serialize",
value: function 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 = this.html) !== null && _this$html !== void 0 ? _this$html : undefined
})
};
}
/**
* Creates a new MessageEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
}], [{
key: "from",
value: function from(text, html) {
var _content;
return new MessageEvent({
type: _message_types.M_MESSAGE.name,
content: (_content = {}, _defineProperty(_content, _message_types.M_TEXT.name, text), _defineProperty(_content, _message_types.M_HTML.name, html), _content)
});
}
}]);
return MessageEvent;
}(_ExtensibleEvent2.ExtensibleEvent);
exports.MessageEvent = MessageEvent;

View File

@@ -0,0 +1,21 @@
import { MessageEvent } from "./MessageEvent";
import { IPartialEvent } from "../IPartialEvent";
import { M_NOTICE_EVENT_CONTENT } from "./message_types";
import { EventType } from "../utility/events";
/**
* Represents a notice. This is essentially a MessageEvent with
* notice characteristics considered.
*/
export declare class NoticeEvent extends MessageEvent {
constructor(wireFormat: IPartialEvent<M_NOTICE_EVENT_CONTENT>);
get isNotice(): boolean;
isEquivalentTo(primaryEventType: EventType): boolean;
serialize(): IPartialEvent<object>;
/**
* Creates a new NoticeEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
static from(text: string, html?: string): NoticeEvent;
}

View File

@@ -0,0 +1,99 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NoticeEvent = void 0;
var _MessageEvent2 = require("./MessageEvent");
var _message_types = require("./message_types");
var _events = require("../utility/events");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
// Notice events are just decorated message events
/**
* Represents a notice. This is essentially a MessageEvent with
* notice characteristics considered.
*/
var NoticeEvent = /*#__PURE__*/function (_MessageEvent) {
_inherits(NoticeEvent, _MessageEvent);
var _super = _createSuper(NoticeEvent);
function NoticeEvent(wireFormat) {
_classCallCheck(this, NoticeEvent);
return _super.call(this, wireFormat);
}
_createClass(NoticeEvent, [{
key: "isNotice",
get: function get() {
return true; // override
}
}, {
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _message_types.M_NOTICE) || _get(_getPrototypeOf(NoticeEvent.prototype), "isEquivalentTo", this).call(this, primaryEventType);
}
}, {
key: "serialize",
value: function serialize() {
var message = _get(_getPrototypeOf(NoticeEvent.prototype), "serialize", this).call(this);
message.content['msgtype'] = "m.notice";
return message;
}
/**
* Creates a new NoticeEvent from text and HTML.
* @param {string} text The text.
* @param {string} html Optional HTML.
* @returns {MessageEvent} The representative message event.
*/
}], [{
key: "from",
value: function from(text, html) {
var _content;
return new NoticeEvent({
type: _message_types.M_NOTICE.name,
content: (_content = {}, _defineProperty(_content, _message_types.M_TEXT.name, text), _defineProperty(_content, _message_types.M_HTML.name, html), _content)
});
}
}]);
return NoticeEvent;
}(_MessageEvent2.MessageEvent);
exports.NoticeEvent = NoticeEvent;

View File

@@ -0,0 +1,33 @@
import { M_POLL_END_EVENT_CONTENT } from "./poll_types";
import { IPartialEvent } from "../IPartialEvent";
import { MessageEvent } from "./MessageEvent";
import { EventType } from "../utility/events";
import { ExtensibleEvent } from "./ExtensibleEvent";
/**
* Represents a poll end/closure event.
*/
export declare class PollEndEvent extends ExtensibleEvent<M_POLL_END_EVENT_CONTENT> {
/**
* The poll start event ID referenced by the response.
*/
readonly pollEventId: string;
/**
* The closing message for the event.
*/
readonly closingMessage: MessageEvent;
/**
* Creates a new PollEndEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.response primary typed event.
* @param {IPartialEvent<M_POLL_END_EVENT_CONTENT>} wireFormat The event.
*/
constructor(wireFormat: IPartialEvent<M_POLL_END_EVENT_CONTENT>);
isEquivalentTo(primaryEventType: EventType): boolean;
serialize(): IPartialEvent<object>;
/**
* Creates a new PollEndEvent from a poll event ID.
* @param {string} pollEventId The poll start event ID.
* @param {string} message A closing message, typically revealing the top answer.
* @returns {PollStartEvent} The representative poll closure event.
*/
static from(pollEventId: string, message: string): PollEndEvent;
}

View File

@@ -0,0 +1,138 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PollEndEvent = void 0;
var _poll_types = require("./poll_types");
var _InvalidEventError = require("../InvalidEventError");
var _relationship_types = require("./relationship_types");
var _MessageEvent = require("./MessageEvent");
var _message_types = require("./message_types");
var _events = require("../utility/events");
var _ExtensibleEvent2 = require("./ExtensibleEvent");
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) { _defineProperty(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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Represents a poll end/closure event.
*/
var PollEndEvent = /*#__PURE__*/function (_ExtensibleEvent) {
_inherits(PollEndEvent, _ExtensibleEvent);
var _super = _createSuper(PollEndEvent);
/**
* The poll start event ID referenced by the response.
*/
/**
* The closing message for the event.
*/
/**
* Creates a new PollEndEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.response primary typed event.
* @param {IPartialEvent<M_POLL_END_EVENT_CONTENT>} wireFormat The event.
*/
function PollEndEvent(wireFormat) {
var _this;
_classCallCheck(this, PollEndEvent);
_this = _super.call(this, wireFormat);
_defineProperty(_assertThisInitialized(_this), "pollEventId", void 0);
_defineProperty(_assertThisInitialized(_this), "closingMessage", void 0);
var rel = _this.wireContent["m.relates_to"];
if (!_relationship_types.REFERENCE_RELATION.matches(rel === null || rel === void 0 ? void 0 : rel.rel_type) || typeof (rel === null || rel === void 0 ? void 0 : rel.event_id) !== "string") {
throw new _InvalidEventError.InvalidEventError("Relationship must be a reference to an event");
}
_this.pollEventId = rel.event_id;
_this.closingMessage = new _MessageEvent.MessageEvent(_this.wireFormat);
return _this;
}
_createClass(PollEndEvent, [{
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _poll_types.M_POLL_END);
}
}, {
key: "serialize",
value: function serialize() {
return {
type: _poll_types.M_POLL_END.name,
content: _objectSpread(_defineProperty({
"m.relates_to": {
rel_type: _relationship_types.REFERENCE_RELATION.name,
event_id: this.pollEventId
}
}, _poll_types.M_POLL_END.name, {}), this.closingMessage.serialize().content)
};
}
/**
* Creates a new PollEndEvent from a poll event ID.
* @param {string} pollEventId The poll start event ID.
* @param {string} message A closing message, typically revealing the top answer.
* @returns {PollStartEvent} The representative poll closure event.
*/
}], [{
key: "from",
value: function from(pollEventId, message) {
var _content;
return new PollEndEvent({
type: _poll_types.M_POLL_END.name,
content: (_content = {
"m.relates_to": {
rel_type: _relationship_types.REFERENCE_RELATION.name,
event_id: pollEventId
}
}, _defineProperty(_content, _poll_types.M_POLL_END.name, {}), _defineProperty(_content, _message_types.M_TEXT.name, message), _content)
});
}
}]);
return PollEndEvent;
}(_ExtensibleEvent2.ExtensibleEvent);
exports.PollEndEvent = PollEndEvent;

View File

@@ -0,0 +1,49 @@
import { ExtensibleEvent } from "./ExtensibleEvent";
import { M_POLL_RESPONSE_EVENT_CONTENT } from "./poll_types";
import { IPartialEvent } from "../IPartialEvent";
import { PollStartEvent } from "./PollStartEvent";
import { EventType } from "../utility/events";
/**
* Represents a poll response event.
*/
export declare class PollResponseEvent extends ExtensibleEvent<M_POLL_RESPONSE_EVENT_CONTENT> {
private internalAnswerIds;
private internalSpoiled;
/**
* The provided answers for the poll. Note that this may be falsy/unpredictable if
* the `spoiled` property is true.
*/
get answerIds(): string[];
/**
* The poll start event ID referenced by the response.
*/
readonly pollEventId: string;
/**
* Whether the vote is spoiled.
*/
get spoiled(): boolean;
/**
* Creates a new PollResponseEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.response primary typed event.
*
* To validate the response against a poll, call `validateAgainst` after creation.
* @param {IPartialEvent<M_POLL_RESPONSE_EVENT_CONTENT>} wireFormat The event.
*/
constructor(wireFormat: IPartialEvent<M_POLL_RESPONSE_EVENT_CONTENT>);
/**
* Validates the poll response using the poll start event as a frame of reference. This
* is used to determine if the vote is spoiled, whether the answers are valid, etc.
* @param {PollStartEvent} poll The poll start event.
*/
validateAgainst(poll: PollStartEvent): void;
isEquivalentTo(primaryEventType: EventType): boolean;
serialize(): IPartialEvent<object>;
/**
* Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty
* answers array.
* @param {string} answers The user's answers. Should be valid from a poll's answer IDs.
* @param {string} pollEventId The poll start event ID.
* @returns {PollStartEvent} The representative poll response event.
*/
static from(answers: string[], pollEventId: string): PollResponseEvent;
}

View File

@@ -0,0 +1,198 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PollResponseEvent = void 0;
var _ExtensibleEvent2 = require("./ExtensibleEvent");
var _poll_types = require("./poll_types");
var _InvalidEventError = require("../InvalidEventError");
var _relationship_types = require("./relationship_types");
var _events = require("../utility/events");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Represents a poll response event.
*/
var PollResponseEvent = /*#__PURE__*/function (_ExtensibleEvent) {
_inherits(PollResponseEvent, _ExtensibleEvent);
var _super = _createSuper(PollResponseEvent);
/**
* Creates a new PollResponseEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.response primary typed event.
*
* To validate the response against a poll, call `validateAgainst` after creation.
* @param {IPartialEvent<M_POLL_RESPONSE_EVENT_CONTENT>} wireFormat The event.
*/
function PollResponseEvent(wireFormat) {
var _this;
_classCallCheck(this, PollResponseEvent);
_this = _super.call(this, wireFormat);
_defineProperty(_assertThisInitialized(_this), "internalAnswerIds", void 0);
_defineProperty(_assertThisInitialized(_this), "internalSpoiled", void 0);
_defineProperty(_assertThisInitialized(_this), "pollEventId", void 0);
var rel = _this.wireContent["m.relates_to"];
if (!_relationship_types.REFERENCE_RELATION.matches(rel === null || rel === void 0 ? void 0 : rel.rel_type) || typeof (rel === null || rel === void 0 ? void 0 : rel.event_id) !== "string") {
throw new _InvalidEventError.InvalidEventError("Relationship must be a reference to an event");
}
_this.pollEventId = rel.event_id;
_this.validateAgainst(null);
return _this;
}
/**
* Validates the poll response using the poll start event as a frame of reference. This
* is used to determine if the vote is spoiled, whether the answers are valid, etc.
* @param {PollStartEvent} poll The poll start event.
*/
_createClass(PollResponseEvent, [{
key: "answerIds",
get:
/**
* The provided answers for the poll. Note that this may be falsy/unpredictable if
* the `spoiled` property is true.
*/
function get() {
return this.internalAnswerIds;
}
/**
* The poll start event ID referenced by the response.
*/
}, {
key: "spoiled",
get:
/**
* Whether the vote is spoiled.
*/
function get() {
return this.internalSpoiled;
}
}, {
key: "validateAgainst",
value: function validateAgainst(poll) {
var response = _poll_types.M_POLL_RESPONSE.findIn(this.wireContent);
if (!Array.isArray(response === null || response === void 0 ? void 0 : response.answers)) {
this.internalSpoiled = true;
this.internalAnswerIds = [];
return;
}
var answers = response.answers;
if (answers.some(function (a) {
return typeof a !== "string";
}) || answers.length === 0) {
this.internalSpoiled = true;
this.internalAnswerIds = [];
return;
}
if (poll) {
if (answers.some(function (a) {
return !poll.answers.some(function (pa) {
return pa.id === a;
});
})) {
this.internalSpoiled = true;
this.internalAnswerIds = [];
return;
}
answers = answers.slice(0, poll.maxSelections);
}
this.internalAnswerIds = answers;
this.internalSpoiled = false;
}
}, {
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _poll_types.M_POLL_RESPONSE);
}
}, {
key: "serialize",
value: function serialize() {
return {
type: _poll_types.M_POLL_RESPONSE.name,
content: _defineProperty({
"m.relates_to": {
rel_type: _relationship_types.REFERENCE_RELATION.name,
event_id: this.pollEventId
}
}, _poll_types.M_POLL_RESPONSE.name, {
answers: this.spoiled ? undefined : this.answerIds
})
};
}
/**
* Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty
* answers array.
* @param {string} answers The user's answers. Should be valid from a poll's answer IDs.
* @param {string} pollEventId The poll start event ID.
* @returns {PollStartEvent} The representative poll response event.
*/
}], [{
key: "from",
value: function from(answers, pollEventId) {
return new PollResponseEvent({
type: _poll_types.M_POLL_RESPONSE.name,
content: _defineProperty({
"m.relates_to": {
rel_type: _relationship_types.REFERENCE_RELATION.name,
event_id: pollEventId
}
}, _poll_types.M_POLL_RESPONSE.name, {
answers: answers
})
});
}
}]);
return PollResponseEvent;
}(_ExtensibleEvent2.ExtensibleEvent);
exports.PollResponseEvent = PollResponseEvent;

View File

@@ -0,0 +1,71 @@
import { KNOWN_POLL_KIND, M_POLL_START_EVENT_CONTENT, POLL_ANSWER } from "./poll_types";
import { IPartialEvent } from "../IPartialEvent";
import { MessageEvent } from "./MessageEvent";
import { EventType } from "../utility/events";
import { ExtensibleEvent } from "./ExtensibleEvent";
/**
* Represents a poll answer. Note that this is represented as a subtype and is
* not registered as a parsable event - it is implied for usage exclusively
* within the PollStartEvent parsing.
*/
export declare class PollAnswerSubevent extends MessageEvent {
/**
* The answer ID.
*/
readonly id: string;
constructor(wireFormat: IPartialEvent<POLL_ANSWER>);
serialize(): IPartialEvent<object>;
/**
* Creates a new PollAnswerSubevent from ID and text.
* @param {string} id The answer ID (unique within the poll).
* @param {string} text The text.
* @returns {PollAnswerSubevent} The representative answer.
*/
static from(id: string, text: string): PollAnswerSubevent;
}
/**
* Represents a poll start event.
*/
export declare class PollStartEvent extends ExtensibleEvent<M_POLL_START_EVENT_CONTENT> {
/**
* The question being asked, as a MessageEvent node.
*/
readonly question: MessageEvent;
/**
* The interpreted kind of poll. Note that this will infer a value that is known to the
* SDK rather than verbatim - this means unknown types will be represented as undisclosed
* polls.
*
* To get the raw kind, use rawKind.
*/
readonly kind: KNOWN_POLL_KIND;
/**
* The true kind as provided by the event sender. Might not be valid.
*/
readonly rawKind: string;
/**
* The maximum number of selections a user is allowed to make.
*/
readonly maxSelections: number;
/**
* The possible answers for the poll.
*/
readonly answers: PollAnswerSubevent[];
/**
* Creates a new PollStartEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.start primary typed event.
* @param {IPartialEvent<M_POLL_START_EVENT_CONTENT>} wireFormat The event.
*/
constructor(wireFormat: IPartialEvent<M_POLL_START_EVENT_CONTENT>);
isEquivalentTo(primaryEventType: EventType): boolean;
serialize(): IPartialEvent<object>;
/**
* Creates a new PollStartEvent from question, answers, and metadata.
* @param {string} question The question to ask.
* @param {string} answers The answers. Should be unique within each other.
* @param {KNOWN_POLL_KIND|string} kind The kind of poll.
* @param {number} maxSelections The maximum number of selections. Must be 1 or higher.
* @returns {PollStartEvent} The representative poll start event.
*/
static from(question: string, answers: string[], kind: KNOWN_POLL_KIND | string, maxSelections?: number): PollStartEvent;
}

View File

@@ -0,0 +1,287 @@
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PollStartEvent = exports.PollAnswerSubevent = void 0;
var _poll_types = require("./poll_types");
var _MessageEvent2 = require("./MessageEvent");
var _message_types = require("./message_types");
var _InvalidEventError = require("../InvalidEventError");
var _NamespacedValue = require("../NamespacedValue");
var _events = require("../utility/events");
var _ExtensibleEvent2 = require("./ExtensibleEvent");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
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) { _defineProperty(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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Represents a poll answer. Note that this is represented as a subtype and is
* not registered as a parsable event - it is implied for usage exclusively
* within the PollStartEvent parsing.
*/
var PollAnswerSubevent = /*#__PURE__*/function (_MessageEvent) {
_inherits(PollAnswerSubevent, _MessageEvent);
var _super = _createSuper(PollAnswerSubevent);
/**
* The answer ID.
*/
function PollAnswerSubevent(wireFormat) {
var _this;
_classCallCheck(this, PollAnswerSubevent);
_this = _super.call(this, wireFormat);
_defineProperty(_assertThisInitialized(_this), "id", void 0);
var id = wireFormat.content.id;
if (!id || typeof id !== "string") {
throw new _InvalidEventError.InvalidEventError("Answer ID must be a non-empty string");
}
_this.id = id;
return _this;
}
_createClass(PollAnswerSubevent, [{
key: "serialize",
value: function serialize() {
return {
type: "org.matrix.sdk.poll.answer",
content: _objectSpread({
id: this.id
}, this.serializeMMessageOnly())
};
}
/**
* Creates a new PollAnswerSubevent from ID and text.
* @param {string} id The answer ID (unique within the poll).
* @param {string} text The text.
* @returns {PollAnswerSubevent} The representative answer.
*/
}], [{
key: "from",
value: function from(id, text) {
return new PollAnswerSubevent({
type: "org.matrix.sdk.poll.answer",
content: _defineProperty({
id: id
}, _message_types.M_TEXT.name, text)
});
}
}]);
return PollAnswerSubevent;
}(_MessageEvent2.MessageEvent);
/**
* Represents a poll start event.
*/
exports.PollAnswerSubevent = PollAnswerSubevent;
var PollStartEvent = /*#__PURE__*/function (_ExtensibleEvent) {
_inherits(PollStartEvent, _ExtensibleEvent);
var _super2 = _createSuper(PollStartEvent);
/**
* The question being asked, as a MessageEvent node.
*/
/**
* The interpreted kind of poll. Note that this will infer a value that is known to the
* SDK rather than verbatim - this means unknown types will be represented as undisclosed
* polls.
*
* To get the raw kind, use rawKind.
*/
/**
* The true kind as provided by the event sender. Might not be valid.
*/
/**
* The maximum number of selections a user is allowed to make.
*/
/**
* The possible answers for the poll.
*/
/**
* Creates a new PollStartEvent from a pure format. Note that the event is *not*
* parsed here: it will be treated as a literal m.poll.start primary typed event.
* @param {IPartialEvent<M_POLL_START_EVENT_CONTENT>} wireFormat The event.
*/
function PollStartEvent(wireFormat) {
var _this2;
_classCallCheck(this, PollStartEvent);
_this2 = _super2.call(this, wireFormat);
_defineProperty(_assertThisInitialized(_this2), "question", void 0);
_defineProperty(_assertThisInitialized(_this2), "kind", void 0);
_defineProperty(_assertThisInitialized(_this2), "rawKind", void 0);
_defineProperty(_assertThisInitialized(_this2), "maxSelections", void 0);
_defineProperty(_assertThisInitialized(_this2), "answers", void 0);
var poll = _poll_types.M_POLL_START.findIn(_this2.wireContent);
if (!poll.question) {
throw new _InvalidEventError.InvalidEventError("A question is required");
}
_this2.question = new _MessageEvent2.MessageEvent({
type: "org.matrix.sdk.poll.question",
content: poll.question
});
_this2.rawKind = poll.kind;
if (_poll_types.M_POLL_KIND_DISCLOSED.matches(_this2.rawKind)) {
_this2.kind = _poll_types.M_POLL_KIND_DISCLOSED;
} else {
_this2.kind = _poll_types.M_POLL_KIND_UNDISCLOSED; // default & assumed value
}
_this2.maxSelections = Number.isFinite(poll.max_selections) && poll.max_selections > 0 ? poll.max_selections : 1;
if (!Array.isArray(poll.answers)) {
throw new _InvalidEventError.InvalidEventError("Poll answers must be an array");
}
var answers = poll.answers.slice(0, 20).map(function (a) {
return new PollAnswerSubevent({
type: "org.matrix.sdk.poll.answer",
content: a
});
});
if (answers.length <= 0) {
throw new _InvalidEventError.InvalidEventError("No answers available");
}
_this2.answers = answers;
return _this2;
}
_createClass(PollStartEvent, [{
key: "isEquivalentTo",
value: function isEquivalentTo(primaryEventType) {
return (0, _events.isEventTypeSame)(primaryEventType, _poll_types.M_POLL_START);
}
}, {
key: "serialize",
value: function serialize() {
var _content2;
return {
type: _poll_types.M_POLL_START.name,
content: (_content2 = {}, _defineProperty(_content2, _poll_types.M_POLL_START.name, {
question: this.question.serialize().content,
kind: this.rawKind,
max_selections: this.maxSelections,
answers: this.answers.map(function (a) {
return a.serialize().content;
})
}), _defineProperty(_content2, _message_types.M_TEXT.name, "".concat(this.question.text, "\n").concat(this.answers.map(function (a, i) {
return "".concat(i + 1, ". ").concat(a.text);
}).join("\n"))), _content2)
};
}
/**
* Creates a new PollStartEvent from question, answers, and metadata.
* @param {string} question The question to ask.
* @param {string} answers The answers. Should be unique within each other.
* @param {KNOWN_POLL_KIND|string} kind The kind of poll.
* @param {number} maxSelections The maximum number of selections. Must be 1 or higher.
* @returns {PollStartEvent} The representative poll start event.
*/
}], [{
key: "from",
value: function from(question, answers, kind) {
var _content3;
var maxSelections = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
return new PollStartEvent({
type: _poll_types.M_POLL_START.name,
content: (_content3 = {}, _defineProperty(_content3, _message_types.M_TEXT.name, question), _defineProperty(_content3, _poll_types.M_POLL_START.name, {
question: _defineProperty({}, _message_types.M_TEXT.name, question),
kind: kind instanceof _NamespacedValue.NamespacedValue ? kind.name : kind,
max_selections: maxSelections,
answers: answers.map(function (a) {
return _defineProperty({
id: makeId()
}, _message_types.M_TEXT.name, a);
})
}), _content3)
});
}
}]);
return PollStartEvent;
}(_ExtensibleEvent2.ExtensibleEvent);
exports.PollStartEvent = PollStartEvent;
var LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
function makeId() {
return _toConsumableArray(Array(16)).map(function () {
return LETTERS.charAt(Math.floor(Math.random() * LETTERS.length));
}).join('');
}

View File

@@ -0,0 +1,81 @@
import { UnstableValue } from "../NamespacedValue";
import { EitherAnd } from "../types";
/**
* The namespaced value for m.message
*/
export declare const M_MESSAGE: UnstableValue<"m.message", "org.matrix.msc1767.message">;
/**
* An m.message event rendering
*/
export interface IMessageRendering {
body: string;
mimetype?: string;
}
/**
* The content for an m.message event
*/
export declare type M_MESSAGE_EVENT = EitherAnd<{
[M_MESSAGE.name]: IMessageRendering[];
}, {
[M_MESSAGE.altName]: IMessageRendering[];
}>;
/**
* The namespaced value for m.text
*/
export declare const M_TEXT: UnstableValue<"m.text", "org.matrix.msc1767.text">;
/**
* The content for an m.text event
*/
export declare type M_TEXT_EVENT = EitherAnd<{
[M_TEXT.name]: string;
}, {
[M_TEXT.altName]: string;
}>;
/**
* The namespaced value for m.html
*/
export declare const M_HTML: UnstableValue<"m.html", "org.matrix.msc1767.html">;
/**
* The content for an m.html event
*/
export declare type M_HTML_EVENT = EitherAnd<{
[M_HTML.name]: string;
}, {
[M_HTML.altName]: string;
}>;
/**
* The content for an m.message, m.text, or m.html event
*/
export declare type M_MESSAGE_EVENT_CONTENT = M_MESSAGE_EVENT | M_TEXT_EVENT | M_HTML_EVENT;
/**
* The namespaced value for m.emote
*/
export declare const M_EMOTE: UnstableValue<"m.emote", "org.matrix.msc1767.emote">;
/**
* The event definition for an m.emote event (in content)
*/
export declare type M_EMOTE_EVENT = EitherAnd<{
[M_EMOTE.name]?: {};
}, {
[M_EMOTE.altName]?: {};
}>;
/**
* The content for an m.emote event
*/
export declare type M_EMOTE_EVENT_CONTENT = M_MESSAGE_EVENT_CONTENT & M_EMOTE_EVENT;
/**
* The namespaced value for m.notice
*/
export declare const M_NOTICE: UnstableValue<"m.notice", "org.matrix.msc1767.notice">;
/**
* The event definition for an m.notice event (in content)
*/
export declare type M_NOTICE_EVENT = EitherAnd<{
[M_NOTICE.name]?: {};
}, {
[M_NOTICE.altName]?: {};
}>;
/**
* The content for an m.notice event
*/
export declare type M_NOTICE_EVENT_CONTENT = M_MESSAGE_EVENT_CONTENT & M_NOTICE_EVENT;

View File

@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.M_TEXT = exports.M_NOTICE = exports.M_MESSAGE = exports.M_HTML = exports.M_EMOTE = void 0;
var _NamespacedValue = require("../NamespacedValue");
/*
Copyright 2022 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.
*/
/**
* The namespaced value for m.message
*/
var M_MESSAGE = new _NamespacedValue.UnstableValue("m.message", "org.matrix.msc1767.message");
/**
* An m.message event rendering
*/
exports.M_MESSAGE = M_MESSAGE;
/**
* The namespaced value for m.text
*/
var M_TEXT = new _NamespacedValue.UnstableValue("m.text", "org.matrix.msc1767.text");
/**
* The content for an m.text event
*/
exports.M_TEXT = M_TEXT;
/**
* The namespaced value for m.html
*/
var M_HTML = new _NamespacedValue.UnstableValue("m.html", "org.matrix.msc1767.html");
/**
* The content for an m.html event
*/
exports.M_HTML = M_HTML;
/**
* The namespaced value for m.emote
*/
var M_EMOTE = new _NamespacedValue.UnstableValue("m.emote", "org.matrix.msc1767.emote");
/**
* The event definition for an m.emote event (in content)
*/
exports.M_EMOTE = M_EMOTE;
/**
* The namespaced value for m.notice
*/
var M_NOTICE = new _NamespacedValue.UnstableValue("m.notice", "org.matrix.msc1767.notice");
/**
* The event definition for an m.notice event (in content)
*/
exports.M_NOTICE = M_NOTICE;

View File

@@ -0,0 +1,89 @@
import { UnstableValue } from "../NamespacedValue";
import { EitherAnd, TSNamespace } from "../types";
import { M_MESSAGE_EVENT_CONTENT } from "./message_types";
import { REFERENCE_RELATION, RELATES_TO_RELATIONSHIP } from "./relationship_types";
/**
* Identifier for a disclosed poll.
*/
export declare const M_POLL_KIND_DISCLOSED: UnstableValue<"m.poll.disclosed", "org.matrix.msc3381.poll.disclosed">;
/**
* Identifier for an undisclosed poll.
*/
export declare const M_POLL_KIND_UNDISCLOSED: UnstableValue<"m.poll.undisclosed", "org.matrix.msc3381.poll.undisclosed">;
/**
* Any poll kind.
*/
export declare type POLL_KIND = TSNamespace<typeof M_POLL_KIND_DISCLOSED> | TSNamespace<typeof M_POLL_KIND_UNDISCLOSED> | string;
/**
* Known poll kind namespaces.
*/
export declare type KNOWN_POLL_KIND = (typeof M_POLL_KIND_DISCLOSED) | (typeof M_POLL_KIND_UNDISCLOSED);
/**
* The namespaced value for m.poll.start
*/
export declare const M_POLL_START: UnstableValue<"m.poll.start", "org.matrix.msc3381.poll.start">;
/**
* The m.poll.start type within event content
*/
export declare type M_POLL_START_SUBTYPE = {
question: M_MESSAGE_EVENT_CONTENT;
kind: POLL_KIND;
max_selections?: number;
answers: POLL_ANSWER[];
};
/**
* A poll answer.
*/
export declare type POLL_ANSWER = M_MESSAGE_EVENT_CONTENT & {
id: string;
};
/**
* The event definition for an m.poll.start event (in content)
*/
export declare type M_POLL_START_EVENT = EitherAnd<{
[M_POLL_START.name]: M_POLL_START_SUBTYPE;
}, {
[M_POLL_START.altName]: M_POLL_START_SUBTYPE;
}>;
/**
* The content for an m.poll.start event
*/
export declare type M_POLL_START_EVENT_CONTENT = M_POLL_START_EVENT & M_MESSAGE_EVENT_CONTENT;
/**
* The namespaced value for m.poll.response
*/
export declare const M_POLL_RESPONSE: UnstableValue<"m.poll.response", "org.matrix.msc3381.poll.response">;
/**
* The m.poll.response type within event content
*/
export declare type M_POLL_RESPONSE_SUBTYPE = {
answers: string[];
};
/**
* The event definition for an m.poll.response event (in content)
*/
export declare type M_POLL_RESPONSE_EVENT = EitherAnd<{
[M_POLL_RESPONSE.name]: M_POLL_RESPONSE_SUBTYPE;
}, {
[M_POLL_RESPONSE.altName]: M_POLL_RESPONSE_SUBTYPE;
}>;
/**
* The content for an m.poll.response event
*/
export declare type M_POLL_RESPONSE_EVENT_CONTENT = M_POLL_RESPONSE_EVENT & RELATES_TO_RELATIONSHIP<typeof REFERENCE_RELATION>;
/**
* The namespaced value for m.poll.end
*/
export declare const M_POLL_END: UnstableValue<"m.poll.end", "org.matrix.msc3381.poll.end">;
/**
* The event definition for an m.poll.end event (in content)
*/
export declare type M_POLL_END_EVENT = EitherAnd<{
[M_POLL_END.name]: {};
}, {
[M_POLL_END.altName]: {};
}>;
/**
* The content for an m.poll.end event
*/
export declare type M_POLL_END_EVENT_CONTENT = M_POLL_END_EVENT & RELATES_TO_RELATIONSHIP<typeof REFERENCE_RELATION> & M_MESSAGE_EVENT_CONTENT;

View File

@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.M_POLL_START = exports.M_POLL_RESPONSE = exports.M_POLL_KIND_UNDISCLOSED = exports.M_POLL_KIND_DISCLOSED = exports.M_POLL_END = void 0;
var _NamespacedValue = require("../NamespacedValue");
/*
Copyright 2022 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.
*/
/**
* Identifier for a disclosed poll.
*/
var M_POLL_KIND_DISCLOSED = new _NamespacedValue.UnstableValue("m.poll.disclosed", "org.matrix.msc3381.poll.disclosed");
/**
* Identifier for an undisclosed poll.
*/
exports.M_POLL_KIND_DISCLOSED = M_POLL_KIND_DISCLOSED;
var M_POLL_KIND_UNDISCLOSED = new _NamespacedValue.UnstableValue("m.poll.undisclosed", "org.matrix.msc3381.poll.undisclosed");
/**
* Any poll kind.
*/
exports.M_POLL_KIND_UNDISCLOSED = M_POLL_KIND_UNDISCLOSED;
/**
* The namespaced value for m.poll.start
*/
var M_POLL_START = new _NamespacedValue.UnstableValue("m.poll.start", "org.matrix.msc3381.poll.start");
/**
* The m.poll.start type within event content
*/
exports.M_POLL_START = M_POLL_START;
/**
* The namespaced value for m.poll.response
*/
var M_POLL_RESPONSE = new _NamespacedValue.UnstableValue("m.poll.response", "org.matrix.msc3381.poll.response");
/**
* The m.poll.response type within event content
*/
exports.M_POLL_RESPONSE = M_POLL_RESPONSE;
/**
* The namespaced value for m.poll.end
*/
var M_POLL_END = new _NamespacedValue.UnstableValue("m.poll.end", "org.matrix.msc3381.poll.end");
/**
* The event definition for an m.poll.end event (in content)
*/
exports.M_POLL_END = M_POLL_END;

View File

@@ -0,0 +1,19 @@
import { NamespacedValue } from "../NamespacedValue";
import { DefaultNever, TSNamespace } from "../types";
/**
* The namespaced value for an m.reference relation
*/
export declare const REFERENCE_RELATION: NamespacedValue<"m.reference", string>;
/**
* Represents any relation type
*/
export declare type ANY_RELATION = TSNamespace<typeof REFERENCE_RELATION> | string;
/**
* An m.relates_to relationship
*/
export declare type RELATES_TO_RELATIONSHIP<R = never, C = never> = {
"m.relates_to": {
rel_type: [R] extends [never] ? ANY_RELATION : TSNamespace<R>;
event_id: string;
} & DefaultNever<C, {}>;
};

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.REFERENCE_RELATION = void 0;
var _NamespacedValue = require("../NamespacedValue");
/*
Copyright 2022 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.
*/
/**
* The namespaced value for an m.reference relation
*/
var REFERENCE_RELATION = new _NamespacedValue.NamespacedValue("m.reference");
/**
* Represents any relation type
*/
exports.REFERENCE_RELATION = REFERENCE_RELATION;

21
node_modules/matrix-events-sdk/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
export * from "./ExtensibleEvents";
export * from "./IPartialEvent";
export * from "./InvalidEventError";
export * from "./NamespacedValue";
export * from "./NamespacedMap";
export * from "./types";
export * from "./utility/MessageMatchers";
export * from "./utility/events";
export * from "./interpreters/legacy/MRoomMessage";
export * from "./interpreters/modern/MMessage";
export * from "./interpreters/modern/MPoll";
export * from "./events/relationship_types";
export * from "./events/ExtensibleEvent";
export * from "./events/message_types";
export * from "./events/MessageEvent";
export * from "./events/EmoteEvent";
export * from "./events/NoticeEvent";
export * from "./events/poll_types";
export * from "./events/PollStartEvent";
export * from "./events/PollResponseEvent";
export * from "./events/PollEndEvent";

278
node_modules/matrix-events-sdk/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,278 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _ExtensibleEvents = require("./ExtensibleEvents");
Object.keys(_ExtensibleEvents).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ExtensibleEvents[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ExtensibleEvents[key];
}
});
});
var _IPartialEvent = require("./IPartialEvent");
Object.keys(_IPartialEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _IPartialEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _IPartialEvent[key];
}
});
});
var _InvalidEventError = require("./InvalidEventError");
Object.keys(_InvalidEventError).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _InvalidEventError[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _InvalidEventError[key];
}
});
});
var _NamespacedValue = require("./NamespacedValue");
Object.keys(_NamespacedValue).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _NamespacedValue[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _NamespacedValue[key];
}
});
});
var _NamespacedMap = require("./NamespacedMap");
Object.keys(_NamespacedMap).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _NamespacedMap[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _NamespacedMap[key];
}
});
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _types[key];
}
});
});
var _MessageMatchers = require("./utility/MessageMatchers");
Object.keys(_MessageMatchers).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _MessageMatchers[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _MessageMatchers[key];
}
});
});
var _events = require("./utility/events");
Object.keys(_events).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _events[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _events[key];
}
});
});
var _MRoomMessage = require("./interpreters/legacy/MRoomMessage");
Object.keys(_MRoomMessage).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _MRoomMessage[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _MRoomMessage[key];
}
});
});
var _MMessage = require("./interpreters/modern/MMessage");
Object.keys(_MMessage).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _MMessage[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _MMessage[key];
}
});
});
var _MPoll = require("./interpreters/modern/MPoll");
Object.keys(_MPoll).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _MPoll[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _MPoll[key];
}
});
});
var _relationship_types = require("./events/relationship_types");
Object.keys(_relationship_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _relationship_types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _relationship_types[key];
}
});
});
var _ExtensibleEvent = require("./events/ExtensibleEvent");
Object.keys(_ExtensibleEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _ExtensibleEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _ExtensibleEvent[key];
}
});
});
var _message_types = require("./events/message_types");
Object.keys(_message_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _message_types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _message_types[key];
}
});
});
var _MessageEvent = require("./events/MessageEvent");
Object.keys(_MessageEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _MessageEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _MessageEvent[key];
}
});
});
var _EmoteEvent = require("./events/EmoteEvent");
Object.keys(_EmoteEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _EmoteEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _EmoteEvent[key];
}
});
});
var _NoticeEvent = require("./events/NoticeEvent");
Object.keys(_NoticeEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _NoticeEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _NoticeEvent[key];
}
});
});
var _poll_types = require("./events/poll_types");
Object.keys(_poll_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _poll_types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _poll_types[key];
}
});
});
var _PollStartEvent = require("./events/PollStartEvent");
Object.keys(_PollStartEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _PollStartEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _PollStartEvent[key];
}
});
});
var _PollResponseEvent = require("./events/PollResponseEvent");
Object.keys(_PollResponseEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _PollResponseEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _PollResponseEvent[key];
}
});
});
var _PollEndEvent = require("./events/PollEndEvent");
Object.keys(_PollEndEvent).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _PollEndEvent[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _PollEndEvent[key];
}
});
});

View File

@@ -0,0 +1,12 @@
import { IPartialEvent } from "../../IPartialEvent";
import { Optional } from "../../types";
import { ExtensibleEvent } from "../../events/ExtensibleEvent";
import { NamespacedValue } from "../../NamespacedValue";
export declare const LEGACY_M_ROOM_MESSAGE: NamespacedValue<"m.room.message", string>;
export interface IPartialLegacyContent {
body: string;
msgtype: string;
format?: string;
formatted_body?: string;
}
export declare function parseMRoomMessage(wireEvent: IPartialEvent<IPartialLegacyContent>): Optional<ExtensibleEvent>;

View File

@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LEGACY_M_ROOM_MESSAGE = void 0;
exports.parseMRoomMessage = parseMRoomMessage;
var _MessageEvent = require("../../events/MessageEvent");
var _NoticeEvent = require("../../events/NoticeEvent");
var _EmoteEvent = require("../../events/EmoteEvent");
var _NamespacedValue = require("../../NamespacedValue");
var _message_types = require("../../events/message_types");
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) { _defineProperty(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; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var LEGACY_M_ROOM_MESSAGE = new _NamespacedValue.NamespacedValue("m.room.message");
exports.LEGACY_M_ROOM_MESSAGE = LEGACY_M_ROOM_MESSAGE;
function parseMRoomMessage(wireEvent) {
var _wireEvent$content, _wireEvent$content2, _wireEvent$content3;
if (_message_types.M_MESSAGE.findIn(wireEvent.content) || _message_types.M_TEXT.findIn(wireEvent.content)) {
// We know enough about the event to coerce it into the right type
return new _MessageEvent.MessageEvent(wireEvent);
}
var msgtype = (_wireEvent$content = wireEvent.content) === null || _wireEvent$content === void 0 ? void 0 : _wireEvent$content.msgtype;
var text = (_wireEvent$content2 = wireEvent.content) === null || _wireEvent$content2 === void 0 ? void 0 : _wireEvent$content2.body;
var html = ((_wireEvent$content3 = wireEvent.content) === null || _wireEvent$content3 === void 0 ? void 0 : _wireEvent$content3.format) === "org.matrix.custom.html" ? wireEvent.content.formatted_body : null;
if (msgtype === "m.text") {
var _objectSpread2;
return new _MessageEvent.MessageEvent(_objectSpread(_objectSpread({}, wireEvent), {}, {
content: _objectSpread(_objectSpread({}, wireEvent.content), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, _message_types.M_TEXT.name, text), _defineProperty(_objectSpread2, _message_types.M_HTML.name, html), _objectSpread2))
}));
} else if (msgtype === "m.notice") {
var _objectSpread3;
return new _NoticeEvent.NoticeEvent(_objectSpread(_objectSpread({}, wireEvent), {}, {
content: _objectSpread(_objectSpread({}, wireEvent.content), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, _message_types.M_TEXT.name, text), _defineProperty(_objectSpread3, _message_types.M_HTML.name, html), _objectSpread3))
}));
} else if (msgtype === "m.emote") {
var _objectSpread4;
return new _EmoteEvent.EmoteEvent(_objectSpread(_objectSpread({}, wireEvent), {}, {
content: _objectSpread(_objectSpread({}, wireEvent.content), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, _message_types.M_TEXT.name, text), _defineProperty(_objectSpread4, _message_types.M_HTML.name, html), _objectSpread4))
}));
} else {
// TODO: Handle other types
return null;
}
}

View File

@@ -0,0 +1,5 @@
import { IPartialEvent } from "../../IPartialEvent";
import { Optional } from "../../types";
import { MessageEvent } from "../../events/MessageEvent";
import { M_MESSAGE_EVENT_CONTENT } from "../../events/message_types";
export declare function parseMMessage(wireEvent: IPartialEvent<M_MESSAGE_EVENT_CONTENT>): Optional<MessageEvent>;

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseMMessage = parseMMessage;
var _MessageEvent = require("../../events/MessageEvent");
var _message_types = require("../../events/message_types");
var _EmoteEvent = require("../../events/EmoteEvent");
var _NoticeEvent = require("../../events/NoticeEvent");
/*
Copyright 2022 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.
*/
function parseMMessage(wireEvent) {
if (_message_types.M_EMOTE.matches(wireEvent.type)) {
return new _EmoteEvent.EmoteEvent(wireEvent);
} else if (_message_types.M_NOTICE.matches(wireEvent.type)) {
return new _NoticeEvent.NoticeEvent(wireEvent);
} // default: return a generic message
return new _MessageEvent.MessageEvent(wireEvent);
}

View File

@@ -0,0 +1,10 @@
import { IPartialEvent } from "../../IPartialEvent";
import { Optional } from "../../types";
import { M_POLL_END_EVENT_CONTENT, M_POLL_RESPONSE_EVENT_CONTENT, M_POLL_START_EVENT_CONTENT } from "../../events/poll_types";
import { PollStartEvent } from "../../events/PollStartEvent";
import { PollResponseEvent } from "../../events/PollResponseEvent";
import { PollEndEvent } from "../../events/PollEndEvent";
declare type PollContent = M_POLL_START_EVENT_CONTENT | M_POLL_RESPONSE_EVENT_CONTENT | M_POLL_END_EVENT_CONTENT;
declare type PollEvent = PollStartEvent | PollResponseEvent | PollEndEvent;
export declare function parseMPoll(wireEvent: IPartialEvent<PollContent>): Optional<PollEvent>;
export {};

View File

@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseMPoll = parseMPoll;
var _poll_types = require("../../events/poll_types");
var _PollStartEvent = require("../../events/PollStartEvent");
var _PollResponseEvent = require("../../events/PollResponseEvent");
var _PollEndEvent = require("../../events/PollEndEvent");
/*
Copyright 2022 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.
*/
function parseMPoll(wireEvent) {
if (_poll_types.M_POLL_START.matches(wireEvent.type)) {
return new _PollStartEvent.PollStartEvent(wireEvent);
} else if (_poll_types.M_POLL_RESPONSE.matches(wireEvent.type)) {
return new _PollResponseEvent.PollResponseEvent(wireEvent);
} else if (_poll_types.M_POLL_END.matches(wireEvent.type)) {
return new _PollEndEvent.PollEndEvent(wireEvent);
}
return null; // not a poll event
}

34
node_modules/matrix-events-sdk/lib/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,34 @@
import { NamespacedValue } from "./NamespacedValue";
/**
* Represents an optional type: can either be T or a falsy value.
*/
export declare type Optional<T> = T | null | undefined;
/**
* Determines if the given optional string is a defined string.
* @param {Optional<string>} s The input string.
* @returns {boolean} True if the input is a defined string.
*/
export declare function isOptionalAString(s: Optional<string>): boolean;
/**
* Determines if the given optional was provided a value.
* @param {Optional<T>} s The optional to test.
* @returns {boolean} True if the value is defined.
*/
export declare function isProvided<T>(s: Optional<T>): boolean;
/**
* Represents either just T1, just T2, or T1 and T2 mixed.
*/
export declare type EitherAnd<T1, T2> = (T1 & T2) | T1 | T2;
/**
* Represents the stable and unstable values of a given namespace.
*/
export declare type TSNamespace<N> = N extends NamespacedValue<infer S, infer U> ? (TSNamespaceValue<S> | TSNamespaceValue<U>) : never;
/**
* Represents a namespaced value, if the value is a string. Used to extract provided types
* from a TSNamespace<N> (in cases where only stable *or* unstable is provided).
*/
export declare type TSNamespaceValue<V> = V extends string ? V : never;
/**
* Creates a type which is V when T is `never`, otherwise T.
*/
export declare type DefaultNever<T, V> = [T] extends [never] ? V : T;

49
node_modules/matrix-events-sdk/lib/types.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isOptionalAString = isOptionalAString;
exports.isProvided = isProvided;
/*
Copyright 2021 - 2022 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 an optional type: can either be T or a falsy value.
*/
/**
* Determines if the given optional string is a defined string.
* @param {Optional<string>} s The input string.
* @returns {boolean} True if the input is a defined string.
*/
function isOptionalAString(s) {
return isProvided(s) && typeof s === 'string';
}
/**
* Determines if the given optional was provided a value.
* @param {Optional<T>} s The optional to test.
* @returns {boolean} True if the value is defined.
*/
function isProvided(s) {
return s !== null && s !== undefined;
}
/**
* Represents either just T1, just T2, or T1 and T2 mixed.
*/

View File

@@ -0,0 +1,20 @@
import { IPartialEvent } from "../IPartialEvent";
import { IPartialLegacyContent } from "../interpreters/legacy/MRoomMessage";
import { EitherAnd } from "../types";
import { M_MESSAGE_EVENT_CONTENT } from "../events/message_types";
/**
* Represents a legacy m.room.message msgtype
*/
export declare enum LegacyMsgType {
Text = "m.text",
Notice = "m.notice",
Emote = "m.emote"
}
/**
* Determines if the given partial event looks similar enough to the given legacy msgtype
* to count as that message type.
* @param {IPartialEvent<EitherAnd<IPartialLegacyContent, M_MESSAGE_EVENT_CONTENT>>} event The event.
* @param {LegacyMsgType} msgtype The message type to compare for.
* @returns {boolean} True if the event appears to look similar enough to the msgtype.
*/
export declare function isEventLike(event: IPartialEvent<EitherAnd<IPartialLegacyContent, M_MESSAGE_EVENT_CONTENT>>, msgtype: LegacyMsgType): boolean;

View File

@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LegacyMsgType = void 0;
exports.isEventLike = isEventLike;
var _message_types = require("../events/message_types");
/*
Copyright 2022 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 legacy m.room.message msgtype
*/
var LegacyMsgType;
/**
* Determines if the given partial event looks similar enough to the given legacy msgtype
* to count as that message type.
* @param {IPartialEvent<EitherAnd<IPartialLegacyContent, M_MESSAGE_EVENT_CONTENT>>} event The event.
* @param {LegacyMsgType} msgtype The message type to compare for.
* @returns {boolean} True if the event appears to look similar enough to the msgtype.
*/
exports.LegacyMsgType = LegacyMsgType;
(function (LegacyMsgType) {
LegacyMsgType["Text"] = "m.text";
LegacyMsgType["Notice"] = "m.notice";
LegacyMsgType["Emote"] = "m.emote";
})(LegacyMsgType || (exports.LegacyMsgType = LegacyMsgType = {}));
function isEventLike(event, msgtype) {
var content = event.content;
if (msgtype === LegacyMsgType.Text) {
return _message_types.M_MESSAGE.matches(event.type) || event.type === "m.room.message" && (content === null || content === void 0 ? void 0 : content['msgtype']) === "m.text";
} else if (msgtype === LegacyMsgType.Emote) {
return _message_types.M_EMOTE.matches(event.type) || event.type === "m.room.message" && (content === null || content === void 0 ? void 0 : content['msgtype']) === "m.emote";
} else if (msgtype === LegacyMsgType.Notice) {
return _message_types.M_NOTICE.matches(event.type) || event.type === "m.room.message" && (content === null || content === void 0 ? void 0 : content['msgtype']) === "m.notice";
}
return false;
}

13
node_modules/matrix-events-sdk/lib/utility/events.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { NamespacedValue } from "../NamespacedValue";
/**
* Represents a potentially namespaced event type.
*/
export declare type EventType = NamespacedValue<string, string> | string;
/**
* Determines if two event types are the same, including namespaces.
* @param {EventType} given The given event type. This will be compared
* against the expected type.
* @param {EventType} expected The expected event type.
* @returns {boolean} True if the given type matches the expected type.
*/
export declare function isEventTypeSame(given: EventType, expected: EventType): boolean;

51
node_modules/matrix-events-sdk/lib/utility/events.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isEventTypeSame = isEventTypeSame;
/*
Copyright 2022 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 potentially namespaced event type.
*/
/**
* Determines if two event types are the same, including namespaces.
* @param {EventType} given The given event type. This will be compared
* against the expected type.
* @param {EventType} expected The expected event type.
* @returns {boolean} True if the given type matches the expected type.
*/
function isEventTypeSame(given, expected) {
if (typeof given === "string") {
if (typeof expected === "string") {
return expected === given;
} else {
return expected.matches(given);
}
} else {
if (typeof expected === "string") {
return given.matches(expected);
} else {
var expectedNs = expected;
var givenNs = given;
return expectedNs.matches(givenNs.name) || expectedNs.matches(givenNs.altName);
}
}
}

48
node_modules/matrix-events-sdk/package.json generated vendored Normal file
View File

@@ -0,0 +1,48 @@
{
"name": "matrix-events-sdk",
"version": "0.0.1",
"description": "JS/TS SDK for interacting with Matrix events",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"repository": "git@github.com:matrix-org/matrix-events-sdk.git",
"author": "The Matrix.org Foundation C.I.C.",
"license": "Apache-2.0",
"files": [
"lib",
"README.md",
"package.json",
"yarn.lock",
"LICENSE"
],
"scripts": {
"prepublishOnly": "yarn build",
"clean": "rimraf lib",
"build": "yarn clean && yarn build:compile && yarn build:types",
"build:types": "tsc -p ./tsconfig.build.json --emitDeclarationOnly",
"build:compile": "babel -d lib --verbose --extensions \".ts\" src",
"start": "tsc -p ./tsconfig.build.json -w",
"test": "jest",
"lint": "eslint src test && tsc --noEmit",
"lint:fix": "eslint --fix src test"
},
"devDependencies": {
"@babel/cli": "^7.16.7",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/eslint-plugin": "^7.16.5",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"eslint": "^7.32.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-matrix-org": "^0.4.0",
"jest": "^27.2.4",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"typescript": "^4.5.4"
}
}

4655
node_modules/matrix-events-sdk/yarn.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff