init
This commit is contained in:
38
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.d.ts
generated
vendored
Normal file
38
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { type ExtensibleEventType, type IPartialEvent } from "../@types/extensible_events.ts";
|
||||
/**
|
||||
* 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 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 primaryEventType - The (potentially namespaced) event
|
||||
* type.
|
||||
* @returns True if this event *could* be represented as the
|
||||
* given type.
|
||||
*/
|
||||
abstract isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;
|
||||
}
|
||||
//# sourceMappingURL=ExtensibleEvent.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ExtensibleEvent.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/ExtensibleEvent.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE9F;;GAEG;AACH,8BAAsB,eAAe,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;aAC5B,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC;IAAzE,SAAS,aAA6B,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAI;IAE7E;;OAEG;IACH,IAAW,WAAW,IAAI,QAAQ,CAEjC;IAED;;;;OAIG;IACH,SAAgB,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAEnD;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAgB,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAAC;CAClF"}
|
||||
57
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.js
generated
vendored
Normal file
57
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents an Extensible Event in Matrix.
|
||||
*/
|
||||
export class ExtensibleEvent {
|
||||
constructor(wireFormat) {
|
||||
this.wireFormat = wireFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to wireFormat.content
|
||||
*/
|
||||
get wireContent() {
|
||||
return this.wireFormat.content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the event into a format which can be used to send the
|
||||
* event to the room.
|
||||
* @returns The serialized event.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 primaryEventType - The (potentially namespaced) event
|
||||
* type.
|
||||
* @returns True if this event *could* be represented as the
|
||||
* given type.
|
||||
*/
|
||||
}
|
||||
//# sourceMappingURL=ExtensibleEvent.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/ExtensibleEvent.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ExtensibleEvent.js","names":[],"sources":["../../src/extensible_events_v1/ExtensibleEvent.ts"],"sourcesContent":["/*\nCopyright 2021 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type ExtensibleEventType, type IPartialEvent } from \"../@types/extensible_events.ts\";\n\n/**\n * Represents an Extensible Event in Matrix.\n */\nexport abstract class ExtensibleEvent<TContent extends object = object> {\n protected constructor(public readonly wireFormat: IPartialEvent<TContent>) {}\n\n /**\n * Shortcut to wireFormat.content\n */\n public get wireContent(): TContent {\n return this.wireFormat.content;\n }\n\n /**\n * Serializes the event into a format which can be used to send the\n * event to the room.\n * @returns The serialized event.\n */\n public abstract serialize(): IPartialEvent<object>;\n\n /**\n * Determines if this event is equivalent to the provided event type.\n * This is recommended over `instanceof` checks due to issues in the JS\n * runtime (and layering of dependencies in some projects).\n *\n * Implementations should pass this check off to their super classes\n * if their own checks fail. Some primary implementations do not extend\n * fallback classes given they support the primary type first. Thus,\n * those classes may return false if asked about their fallback\n * representation.\n *\n * Note that this only checks primary event types: legacy events, like\n * m.room.message, should/will fail this check.\n * @param primaryEventType - The (potentially namespaced) event\n * type.\n * @returns True if this event *could* be represented as the\n * given type.\n */\n public abstract isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA,OAAO,MAAe,eAAe,CAAmC;EAC1D,WAAW,CAAiB,UAAmC,EAAE;IAAA,KAArC,UAAmC,GAAnC,UAAmC;EAAG;;EAE5E;AACJ;AACA;EACI,IAAW,WAAW,GAAa;IAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO;EAClC;;EAEA;AACJ;AACA;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA","ignoreList":[]}
|
||||
7
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.d.ts
generated
vendored
Normal file
7
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Thrown when an event is unforgivably unparsable.
|
||||
*/
|
||||
export declare class InvalidEventError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
//# sourceMappingURL=InvalidEventError.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"InvalidEventError.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/InvalidEventError.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IACxC,YAAmB,OAAO,EAAE,MAAM,EAEjC;CACJ"}
|
||||
25
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.js
generated
vendored
Normal file
25
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Thrown when an event is unforgivably unparsable.
|
||||
*/
|
||||
export class InvalidEventError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=InvalidEventError.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/InvalidEventError.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"InvalidEventError.js","names":[],"sources":["../../src/extensible_events_v1/InvalidEventError.ts"],"sourcesContent":["/*\nCopyright 2022 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/**\n * Thrown when an event is unforgivably unparsable.\n */\nexport class InvalidEventError extends Error {\n public constructor(message: string) {\n super(message);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAM,iBAAiB,SAAS,KAAK,CAAC;EAClC,WAAW,CAAC,OAAe,EAAE;IAChC,KAAK,CAAC,OAAO,CAAC;EAClB;AACJ","ignoreList":[]}
|
||||
44
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.d.ts
generated
vendored
Normal file
44
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.ts";
|
||||
import { type ExtensibleEventType, type IMessageRendering, type IPartialEvent, type ExtensibleAnyMessageEventContent } from "../@types/extensible_events.ts";
|
||||
/**
|
||||
* 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<ExtensibleAnyMessageEventContent> {
|
||||
/**
|
||||
* The default text for the event.
|
||||
*/
|
||||
readonly text: string;
|
||||
/**
|
||||
* The default HTML for the event, if provided.
|
||||
*/
|
||||
readonly html?: 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat: IPartialEvent<ExtensibleAnyMessageEventContent>);
|
||||
isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;
|
||||
protected serializeMMessageOnly(): ExtensibleAnyMessageEventContent;
|
||||
serialize(): IPartialEvent<object>;
|
||||
/**
|
||||
* Creates a new MessageEvent from text and HTML.
|
||||
* @param text - The text.
|
||||
* @param html - Optional HTML.
|
||||
* @returns The representative message event.
|
||||
*/
|
||||
static from(text: string, html?: string): MessageEvent;
|
||||
}
|
||||
//# sourceMappingURL=MessageEvent.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"MessageEvent.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/MessageEvent.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAIlB,KAAK,gCAAgC,EAExC,MAAM,gCAAgC,CAAC;AAIxC;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,eAAe,CAAC,gCAAgC,CAAC;IAC/E;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;OAKG;IACH,SAAgB,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAEhD;;;;;OAKG;IACH,YAAmB,UAAU,EAAE,aAAa,CAAC,gCAAgC,CAAC,EA4B7E;IAEM,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAEpE;IAED,SAAS,CAAC,qBAAqB,IAAI,gCAAgC,CAgBlE;IAEM,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAWxC;IAED;;;;;OAKG;IACH,OAAc,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAQ5D;CACJ"}
|
||||
132
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js
generated
vendored
Normal file
132
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
||||
import { isEventTypeSame, M_HTML, M_MESSAGE, M_TEXT } from "../@types/extensible_events.js";
|
||||
import { isOptionalAString, isProvided } from "./utilities.js";
|
||||
import { InvalidEventError } from "./InvalidEventError.js";
|
||||
|
||||
/**
|
||||
* 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 class MessageEvent extends ExtensibleEvent {
|
||||
/**
|
||||
* Creates a new MessageEvent from a pure format. Note that the event is
|
||||
* *not* parsed here: it will be treated as a literal m.message primary
|
||||
* typed event.
|
||||
* @param wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat) {
|
||||
super(wireFormat);
|
||||
/**
|
||||
* The default text for the event.
|
||||
*/
|
||||
_defineProperty(this, "text", void 0);
|
||||
/**
|
||||
* The default HTML for the event, if provided.
|
||||
*/
|
||||
_defineProperty(this, "html", void 0);
|
||||
/**
|
||||
* All the different renderings of the message. Note that this is the same
|
||||
* format as an m.message body but may contain elements not found directly
|
||||
* in the event content: this is because this is interpreted based off the
|
||||
* other information available in the event.
|
||||
*/
|
||||
_defineProperty(this, "renderings", void 0);
|
||||
const mmessage = M_MESSAGE.findIn(this.wireContent);
|
||||
const mtext = M_TEXT.findIn(this.wireContent);
|
||||
const mhtml = M_HTML.findIn(this.wireContent);
|
||||
if (isProvided(mmessage)) {
|
||||
if (!Array.isArray(mmessage)) {
|
||||
throw new InvalidEventError("m.message contents must be an array");
|
||||
}
|
||||
const text = mmessage.find(r => !isProvided(r.mimetype) || r.mimetype === "text/plain");
|
||||
const html = mmessage.find(r => r.mimetype === "text/html");
|
||||
if (!text) throw new InvalidEventError("m.message is missing a plain text representation");
|
||||
this.text = text.body;
|
||||
this.html = html?.body;
|
||||
this.renderings = mmessage;
|
||||
} else if (isOptionalAString(mtext)) {
|
||||
this.text = mtext;
|
||||
this.html = mhtml ?? undefined;
|
||||
this.renderings = [{
|
||||
body: mtext,
|
||||
mimetype: "text/plain"
|
||||
}];
|
||||
if (this.html) {
|
||||
this.renderings.push({
|
||||
body: this.html,
|
||||
mimetype: "text/html"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new InvalidEventError("Missing textual representation for event");
|
||||
}
|
||||
}
|
||||
isEquivalentTo(primaryEventType) {
|
||||
return isEventTypeSame(primaryEventType, M_MESSAGE);
|
||||
}
|
||||
serializeMMessageOnly() {
|
||||
let messageRendering = {
|
||||
[M_MESSAGE.name]: this.renderings
|
||||
};
|
||||
|
||||
// Use the shorthand if it's just a simple text event
|
||||
if (this.renderings.length === 1) {
|
||||
const mime = this.renderings[0].mimetype;
|
||||
if (mime === undefined || mime === "text/plain") {
|
||||
messageRendering = {
|
||||
[M_TEXT.name]: this.renderings[0].body
|
||||
};
|
||||
}
|
||||
}
|
||||
return messageRendering;
|
||||
}
|
||||
serialize() {
|
||||
return {
|
||||
type: "m.room.message",
|
||||
content: _objectSpread(_objectSpread({}, this.serializeMMessageOnly()), {}, {
|
||||
body: this.text,
|
||||
msgtype: "m.text",
|
||||
format: this.html ? "org.matrix.custom.html" : undefined,
|
||||
formatted_body: this.html ?? undefined
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MessageEvent from text and HTML.
|
||||
* @param text - The text.
|
||||
* @param html - Optional HTML.
|
||||
* @returns The representative message event.
|
||||
*/
|
||||
static from(text, html) {
|
||||
return new MessageEvent({
|
||||
type: M_MESSAGE.name,
|
||||
content: {
|
||||
[M_TEXT.name]: text,
|
||||
[M_HTML.name]: html
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=MessageEvent.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/MessageEvent.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
33
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.d.ts
generated
vendored
Normal file
33
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { type ExtensibleEventType, type IPartialEvent } from "../@types/extensible_events.ts";
|
||||
import { type PollEndEventContent } from "../@types/polls.ts";
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.ts";
|
||||
import { MessageEvent } from "./MessageEvent.ts";
|
||||
/**
|
||||
* Represents a poll end/closure event.
|
||||
*/
|
||||
export declare class PollEndEvent extends ExtensibleEvent<PollEndEventContent> {
|
||||
/**
|
||||
* 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat: IPartialEvent<PollEndEventContent>);
|
||||
isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;
|
||||
serialize(): IPartialEvent<object>;
|
||||
/**
|
||||
* Creates a new PollEndEvent from a poll event ID.
|
||||
* @param pollEventId - The poll start event ID.
|
||||
* @param message - A closing message, typically revealing the top answer.
|
||||
* @returns The representative poll closure event.
|
||||
*/
|
||||
static from(pollEventId: string, message: string): PollEndEvent;
|
||||
}
|
||||
//# sourceMappingURL=PollEndEvent.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PollEndEvent.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/PollEndEvent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAIrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAc,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,qBAAa,YAAa,SAAQ,eAAe,CAAC,mBAAmB,CAAC;IAClE;;OAEG;IACH,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,SAAgB,cAAc,EAAE,YAAY,CAAC;IAE7C;;;;OAIG;IACH,YAAmB,UAAU,EAAE,aAAa,CAAC,mBAAmB,CAAC,EAUhE;IAEM,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAEpE;IAEM,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAYxC;IAED;;;;;OAKG;IACH,OAAc,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAYrE;CACJ"}
|
||||
87
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.js
generated
vendored
Normal file
87
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { isEventTypeSame, M_TEXT, REFERENCE_RELATION } from "../@types/extensible_events.js";
|
||||
import { M_POLL_END } from "../@types/polls.js";
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
||||
import { InvalidEventError } from "./InvalidEventError.js";
|
||||
import { MessageEvent } from "./MessageEvent.js";
|
||||
|
||||
/**
|
||||
* Represents a poll end/closure event.
|
||||
*/
|
||||
export class PollEndEvent extends ExtensibleEvent {
|
||||
/**
|
||||
* 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat) {
|
||||
super(wireFormat);
|
||||
/**
|
||||
* The poll start event ID referenced by the response.
|
||||
*/
|
||||
_defineProperty(this, "pollEventId", void 0);
|
||||
/**
|
||||
* The closing message for the event.
|
||||
*/
|
||||
_defineProperty(this, "closingMessage", void 0);
|
||||
const rel = this.wireContent["m.relates_to"];
|
||||
if (!REFERENCE_RELATION.matches(rel?.rel_type) || typeof rel?.event_id !== "string") {
|
||||
throw new InvalidEventError("Relationship must be a reference to an event");
|
||||
}
|
||||
this.pollEventId = rel.event_id;
|
||||
this.closingMessage = new MessageEvent(this.wireFormat);
|
||||
}
|
||||
isEquivalentTo(primaryEventType) {
|
||||
return isEventTypeSame(primaryEventType, M_POLL_END);
|
||||
}
|
||||
serialize() {
|
||||
return {
|
||||
type: M_POLL_END.name,
|
||||
content: _objectSpread({
|
||||
"m.relates_to": {
|
||||
rel_type: REFERENCE_RELATION.name,
|
||||
event_id: this.pollEventId
|
||||
},
|
||||
[M_POLL_END.name]: {}
|
||||
}, this.closingMessage.serialize().content)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PollEndEvent from a poll event ID.
|
||||
* @param pollEventId - The poll start event ID.
|
||||
* @param message - A closing message, typically revealing the top answer.
|
||||
* @returns The representative poll closure event.
|
||||
*/
|
||||
static from(pollEventId, message) {
|
||||
return new PollEndEvent({
|
||||
type: M_POLL_END.name,
|
||||
content: {
|
||||
"m.relates_to": {
|
||||
rel_type: REFERENCE_RELATION.name,
|
||||
event_id: pollEventId
|
||||
},
|
||||
[M_POLL_END.name]: {},
|
||||
[M_TEXT.name]: message
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=PollEndEvent.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollEndEvent.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PollEndEvent.js","names":[],"sources":["../../src/extensible_events_v1/PollEndEvent.ts"],"sourcesContent":["/*\nCopyright 2022 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport {\n type ExtensibleEventType,\n type IPartialEvent,\n isEventTypeSame,\n M_TEXT,\n REFERENCE_RELATION,\n} from \"../@types/extensible_events.ts\";\nimport { M_POLL_END, type PollEndEventContent } from \"../@types/polls.ts\";\nimport { ExtensibleEvent } from \"./ExtensibleEvent.ts\";\nimport { InvalidEventError } from \"./InvalidEventError.ts\";\nimport { MessageEvent } from \"./MessageEvent.ts\";\n\n/**\n * Represents a poll end/closure event.\n */\nexport class PollEndEvent extends ExtensibleEvent<PollEndEventContent> {\n /**\n * The poll start event ID referenced by the response.\n */\n public readonly pollEventId: string;\n\n /**\n * The closing message for the event.\n */\n public readonly closingMessage: MessageEvent;\n\n /**\n * Creates a new PollEndEvent from a pure format. Note that the event is *not*\n * parsed here: it will be treated as a literal m.poll.response primary typed event.\n * @param wireFormat - The event.\n */\n public constructor(wireFormat: IPartialEvent<PollEndEventContent>) {\n super(wireFormat);\n\n const rel = this.wireContent[\"m.relates_to\"];\n if (!REFERENCE_RELATION.matches(rel?.rel_type) || typeof rel?.event_id !== \"string\") {\n throw new InvalidEventError(\"Relationship must be a reference to an event\");\n }\n\n this.pollEventId = rel.event_id;\n this.closingMessage = new MessageEvent(this.wireFormat);\n }\n\n public isEquivalentTo(primaryEventType: ExtensibleEventType): boolean {\n return isEventTypeSame(primaryEventType, M_POLL_END);\n }\n\n public serialize(): IPartialEvent<object> {\n return {\n type: M_POLL_END.name,\n content: {\n \"m.relates_to\": {\n rel_type: REFERENCE_RELATION.name,\n event_id: this.pollEventId,\n },\n [M_POLL_END.name]: {},\n ...this.closingMessage.serialize().content,\n },\n };\n }\n\n /**\n * Creates a new PollEndEvent from a poll event ID.\n * @param pollEventId - The poll start event ID.\n * @param message - A closing message, typically revealing the top answer.\n * @returns The representative poll closure event.\n */\n public static from(pollEventId: string, message: string): PollEndEvent {\n return new PollEndEvent({\n type: M_POLL_END.name,\n content: {\n \"m.relates_to\": {\n rel_type: REFERENCE_RELATION.name,\n event_id: pollEventId,\n },\n [M_POLL_END.name]: {},\n [M_TEXT.name]: message,\n },\n });\n }\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAGI,eAAe,EACf,MAAM,EACN,kBAAkB,QACf,gCAAgC;AACvC,SAAS,UAAU,QAAkC,oBAAoB;AACzE,SAAS,eAAe,QAAQ,sBAAsB;AACtD,SAAS,iBAAiB,QAAQ,wBAAwB;AAC1D,SAAS,YAAY,QAAQ,mBAAmB;;AAEhD;AACA;AACA;AACA,OAAO,MAAM,YAAY,SAAS,eAAe,CAAsB;EAWnE;AACJ;AACA;AACA;AACA;EACW,WAAW,CAAC,UAA8C,EAAE;IAC/D,KAAK,CAAC,UAAU,CAAC;IAhBrB;AACJ;AACA;IAFI;IAKA;AACJ;AACA;IAFI;IAaI,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC;IAC5C,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,OAAO,GAAG,EAAE,QAAQ,KAAK,QAAQ,EAAE;MACjF,MAAM,IAAI,iBAAiB,CAAC,8CAA8C,CAAC;IAC/E;IAEA,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,QAAQ;IAC/B,IAAI,CAAC,cAAc,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;EAC3D;EAEO,cAAc,CAAC,gBAAqC,EAAW;IAClE,OAAO,eAAe,CAAC,gBAAgB,EAAE,UAAU,CAAC;EACxD;EAEO,SAAS,GAA0B;IACtC,OAAO;MACH,IAAI,EAAE,UAAU,CAAC,IAAI;MACrB,OAAO;QACH,cAAc,EAAE;UACZ,QAAQ,EAAE,kBAAkB,CAAC,IAAI;UACjC,QAAQ,EAAE,IAAI,CAAC;QACnB,CAAC;QACD,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;MAAC,GAClB,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;IAElD,CAAC;EACL;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAc,IAAI,CAAC,WAAmB,EAAE,OAAe,EAAgB;IACnE,OAAO,IAAI,YAAY,CAAC;MACpB,IAAI,EAAE,UAAU,CAAC,IAAI;MACrB,OAAO,EAAE;QACL,cAAc,EAAE;UACZ,QAAQ,EAAE,kBAAkB,CAAC,IAAI;UACjC,QAAQ,EAAE;QACd,CAAC;QACD,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;QACrB,CAAC,MAAM,CAAC,IAAI,GAAG;MACnB;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
||||
49
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.d.ts
generated
vendored
Normal file
49
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.ts";
|
||||
import { type PollResponseEventContent } from "../@types/polls.ts";
|
||||
import { type ExtensibleEventType, type IPartialEvent } from "../@types/extensible_events.ts";
|
||||
import { type PollStartEvent } from "./PollStartEvent.ts";
|
||||
/**
|
||||
* Represents a poll response event.
|
||||
*/
|
||||
export declare class PollResponseEvent extends ExtensibleEvent<PollResponseEventContent> {
|
||||
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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat: IPartialEvent<PollResponseEventContent>);
|
||||
/**
|
||||
* 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 poll - The poll start event.
|
||||
*/
|
||||
validateAgainst(poll: PollStartEvent | null): void;
|
||||
isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;
|
||||
serialize(): IPartialEvent<object>;
|
||||
/**
|
||||
* Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty
|
||||
* answers array.
|
||||
* @param answers - The user's answers. Should be valid from a poll's answer IDs.
|
||||
* @param pollEventId - The poll start event ID.
|
||||
* @returns The representative poll response event.
|
||||
*/
|
||||
static from(answers: string[], pollEventId: string): PollResponseEvent;
|
||||
}
|
||||
//# sourceMappingURL=PollResponseEvent.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PollResponseEvent.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/PollResponseEvent.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAmB,KAAK,wBAAwB,EAA4B,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAGrB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe,CAAC,wBAAwB,CAAC;IAC5E,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,eAAe,CAAS;IAEhC;;;OAGG;IACH,IAAW,SAAS,IAAI,MAAM,EAAE,CAE/B;IAED;;OAEG;IACH,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC;;OAEG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAED;;;;;;OAMG;IACH,YAAmB,UAAU,EAAE,aAAa,CAAC,wBAAwB,CAAC,EAUrE;IAED;;;;OAIG;IACI,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CA2BxD;IAEM,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAEpE;IAEM,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAaxC;IAED;;;;;;OAMG;IACH,OAAc,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAa5E;CACJ"}
|
||||
134
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.js
generated
vendored
Normal file
134
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.js
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
||||
import { M_POLL_RESPONSE } from "../@types/polls.js";
|
||||
import { isEventTypeSame, REFERENCE_RELATION } from "../@types/extensible_events.js";
|
||||
import { InvalidEventError } from "./InvalidEventError.js";
|
||||
/**
|
||||
* Represents a poll response event.
|
||||
*/
|
||||
export class PollResponseEvent extends ExtensibleEvent {
|
||||
/**
|
||||
* The provided answers for the poll. Note that this may be falsy/unpredictable if
|
||||
* the `spoiled` property is true.
|
||||
*/
|
||||
get answerIds() {
|
||||
return this.internalAnswerIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* The poll start event ID referenced by the response.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Whether the vote is spoiled.
|
||||
*/
|
||||
get spoiled() {
|
||||
return this.internalSpoiled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat) {
|
||||
super(wireFormat);
|
||||
_defineProperty(this, "internalAnswerIds", []);
|
||||
_defineProperty(this, "internalSpoiled", false);
|
||||
_defineProperty(this, "pollEventId", void 0);
|
||||
const rel = this.wireContent["m.relates_to"];
|
||||
if (!REFERENCE_RELATION.matches(rel?.rel_type) || typeof rel?.event_id !== "string") {
|
||||
throw new InvalidEventError("Relationship must be a reference to an event");
|
||||
}
|
||||
this.pollEventId = rel.event_id;
|
||||
this.validateAgainst(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 poll - The poll start event.
|
||||
*/
|
||||
validateAgainst(poll) {
|
||||
const response = M_POLL_RESPONSE.findIn(this.wireContent);
|
||||
if (!Array.isArray(response?.answers)) {
|
||||
this.internalSpoiled = true;
|
||||
this.internalAnswerIds = [];
|
||||
return;
|
||||
}
|
||||
let answers = response?.answers ?? [];
|
||||
if (answers.some(a => typeof a !== "string") || answers.length === 0) {
|
||||
this.internalSpoiled = true;
|
||||
this.internalAnswerIds = [];
|
||||
return;
|
||||
}
|
||||
if (poll) {
|
||||
if (answers.some(a => !poll.answers.some(pa => pa.id === a))) {
|
||||
this.internalSpoiled = true;
|
||||
this.internalAnswerIds = [];
|
||||
return;
|
||||
}
|
||||
answers = answers.slice(0, poll.maxSelections);
|
||||
}
|
||||
this.internalAnswerIds = answers;
|
||||
this.internalSpoiled = false;
|
||||
}
|
||||
isEquivalentTo(primaryEventType) {
|
||||
return isEventTypeSame(primaryEventType, M_POLL_RESPONSE);
|
||||
}
|
||||
serialize() {
|
||||
return {
|
||||
type: M_POLL_RESPONSE.name,
|
||||
content: {
|
||||
"m.relates_to": {
|
||||
rel_type: REFERENCE_RELATION.name,
|
||||
event_id: this.pollEventId
|
||||
},
|
||||
[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 answers - The user's answers. Should be valid from a poll's answer IDs.
|
||||
* @param pollEventId - The poll start event ID.
|
||||
* @returns The representative poll response event.
|
||||
*/
|
||||
static from(answers, pollEventId) {
|
||||
return new PollResponseEvent({
|
||||
type: M_POLL_RESPONSE.name,
|
||||
content: {
|
||||
"m.relates_to": {
|
||||
rel_type: REFERENCE_RELATION.name,
|
||||
event_id: pollEventId
|
||||
},
|
||||
[M_POLL_RESPONSE.name]: {
|
||||
answers: answers
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=PollResponseEvent.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollResponseEvent.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
71
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.d.ts
generated
vendored
Normal file
71
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.d.ts
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import { MessageEvent } from "./MessageEvent.ts";
|
||||
import { type ExtensibleEventType, type IPartialEvent } from "../@types/extensible_events.ts";
|
||||
import { type KnownPollKind, type PollStartEventContent, type PollAnswer } from "../@types/polls.ts";
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.ts";
|
||||
/**
|
||||
* 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<PollAnswer>);
|
||||
serialize(): IPartialEvent<object>;
|
||||
/**
|
||||
* Creates a new PollAnswerSubevent from ID and text.
|
||||
* @param id - The answer ID (unique within the poll).
|
||||
* @param text - The text.
|
||||
* @returns The representative answer.
|
||||
*/
|
||||
static from(id: string, text: string): PollAnswerSubevent;
|
||||
}
|
||||
/**
|
||||
* Represents a poll start event.
|
||||
*/
|
||||
export declare class PollStartEvent extends ExtensibleEvent<PollStartEventContent> {
|
||||
/**
|
||||
* 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: KnownPollKind;
|
||||
/**
|
||||
* 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat: IPartialEvent<PollStartEventContent>);
|
||||
isEquivalentTo(primaryEventType: ExtensibleEventType): boolean;
|
||||
serialize(): IPartialEvent<object>;
|
||||
/**
|
||||
* Creates a new PollStartEvent from question, answers, and metadata.
|
||||
* @param question - The question to ask.
|
||||
* @param answers - The answers. Should be unique within each other.
|
||||
* @param kind - The kind of poll.
|
||||
* @param maxSelections - The maximum number of selections. Must be 1 or higher.
|
||||
* @returns The representative poll start event.
|
||||
*/
|
||||
static from(question: string, answers: string[], kind: KnownPollKind | string, maxSelections?: number): PollStartEvent;
|
||||
}
|
||||
//# sourceMappingURL=PollStartEvent.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"PollStartEvent.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/PollStartEvent.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,aAAa,EAA2B,MAAM,gCAAgC,CAAC;AACvH,OAAO,EACH,KAAK,aAAa,EAIlB,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAChD;;OAEG;IACH,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,YAAmB,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,EAQvD;IAEM,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAQxC;IAED;;;;;OAKG;IACH,OAAc,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAQ/D;CACJ;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,eAAe,CAAC,qBAAqB,CAAC;IACtE;;OAEG;IACH,SAAgB,QAAQ,EAAE,YAAY,CAAC;IAEvC;;;;;;OAMG;IACH,SAAgB,IAAI,EAAE,aAAa,CAAC;IAEpC;;OAEG;IACH,SAAgB,OAAO,EAAE,MAAM,CAAC;IAEhC;;OAEG;IACH,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC;;OAEG;IACH,SAAgB,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAE9C;;;;OAIG;IACH,YAAmB,UAAU,EAAE,aAAa,CAAC,qBAAqB,CAAC,EAmClE;IAEM,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,GAAG,OAAO,CAEpE;IAEM,SAAS,IAAI,aAAa,CAAC,MAAM,CAAC,CAaxC;IAED;;;;;;;OAOG;IACH,OAAc,IAAI,CACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,aAAa,GAAG,MAAM,EAC5B,aAAa,SAAI,GAClB,cAAc,CAahB;CACJ"}
|
||||
183
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.js
generated
vendored
Normal file
183
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
||||
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
||||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { NamespacedValue } from "matrix-events-sdk";
|
||||
import { MessageEvent } from "./MessageEvent.js";
|
||||
import { isEventTypeSame, M_TEXT } from "../@types/extensible_events.js";
|
||||
import { M_POLL_KIND_DISCLOSED, M_POLL_KIND_UNDISCLOSED, M_POLL_START } from "../@types/polls.js";
|
||||
import { InvalidEventError } from "./InvalidEventError.js";
|
||||
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
||||
|
||||
/**
|
||||
* 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 class PollAnswerSubevent extends MessageEvent {
|
||||
constructor(wireFormat) {
|
||||
super(wireFormat);
|
||||
/**
|
||||
* The answer ID.
|
||||
*/
|
||||
_defineProperty(this, "id", void 0);
|
||||
const id = wireFormat.content.id;
|
||||
if (!id || typeof id !== "string") {
|
||||
throw new InvalidEventError("Answer ID must be a non-empty string");
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
serialize() {
|
||||
return {
|
||||
type: "org.matrix.sdk.poll.answer",
|
||||
content: _objectSpread({
|
||||
id: this.id
|
||||
}, this.serializeMMessageOnly())
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PollAnswerSubevent from ID and text.
|
||||
* @param id - The answer ID (unique within the poll).
|
||||
* @param text - The text.
|
||||
* @returns The representative answer.
|
||||
*/
|
||||
static from(id, text) {
|
||||
return new PollAnswerSubevent({
|
||||
type: "org.matrix.sdk.poll.answer",
|
||||
content: {
|
||||
id: id,
|
||||
[M_TEXT.name]: text
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a poll start event.
|
||||
*/
|
||||
export class PollStartEvent extends ExtensibleEvent {
|
||||
/**
|
||||
* 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 wireFormat - The event.
|
||||
*/
|
||||
constructor(wireFormat) {
|
||||
super(wireFormat);
|
||||
/**
|
||||
* The question being asked, as a MessageEvent node.
|
||||
*/
|
||||
_defineProperty(this, "question", void 0);
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
_defineProperty(this, "kind", void 0);
|
||||
/**
|
||||
* The true kind as provided by the event sender. Might not be valid.
|
||||
*/
|
||||
_defineProperty(this, "rawKind", void 0);
|
||||
/**
|
||||
* The maximum number of selections a user is allowed to make.
|
||||
*/
|
||||
_defineProperty(this, "maxSelections", void 0);
|
||||
/**
|
||||
* The possible answers for the poll.
|
||||
*/
|
||||
_defineProperty(this, "answers", void 0);
|
||||
const poll = M_POLL_START.findIn(this.wireContent);
|
||||
if (!poll?.question) {
|
||||
throw new InvalidEventError("A question is required");
|
||||
}
|
||||
this.question = new MessageEvent({
|
||||
type: "org.matrix.sdk.poll.question",
|
||||
content: poll.question
|
||||
});
|
||||
this.rawKind = poll.kind;
|
||||
if (M_POLL_KIND_DISCLOSED.matches(this.rawKind)) {
|
||||
this.kind = M_POLL_KIND_DISCLOSED;
|
||||
} else {
|
||||
this.kind = M_POLL_KIND_UNDISCLOSED; // default & assumed value
|
||||
}
|
||||
this.maxSelections = Number.isFinite(poll.max_selections) && poll.max_selections > 0 ? poll.max_selections : 1;
|
||||
if (!Array.isArray(poll.answers)) {
|
||||
throw new InvalidEventError("Poll answers must be an array");
|
||||
}
|
||||
const answers = poll.answers.slice(0, 20).map(a => new PollAnswerSubevent({
|
||||
type: "org.matrix.sdk.poll.answer",
|
||||
content: a
|
||||
}));
|
||||
if (answers.length <= 0) {
|
||||
throw new InvalidEventError("No answers available");
|
||||
}
|
||||
this.answers = answers;
|
||||
}
|
||||
isEquivalentTo(primaryEventType) {
|
||||
return isEventTypeSame(primaryEventType, M_POLL_START);
|
||||
}
|
||||
serialize() {
|
||||
return {
|
||||
type: M_POLL_START.name,
|
||||
content: {
|
||||
[M_POLL_START.name]: {
|
||||
question: this.question.serialize().content,
|
||||
kind: this.rawKind,
|
||||
max_selections: this.maxSelections,
|
||||
answers: this.answers.map(a => a.serialize().content)
|
||||
},
|
||||
[M_TEXT.name]: `${this.question.text}\n${this.answers.map((a, i) => `${i + 1}. ${a.text}`).join("\n")}`
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PollStartEvent from question, answers, and metadata.
|
||||
* @param question - The question to ask.
|
||||
* @param answers - The answers. Should be unique within each other.
|
||||
* @param kind - The kind of poll.
|
||||
* @param maxSelections - The maximum number of selections. Must be 1 or higher.
|
||||
* @returns The representative poll start event.
|
||||
*/
|
||||
static from(question, answers, kind, maxSelections = 1) {
|
||||
return new PollStartEvent({
|
||||
type: M_POLL_START.name,
|
||||
content: {
|
||||
[M_TEXT.name]: question,
|
||||
// unused by parsing
|
||||
[M_POLL_START.name]: {
|
||||
question: {
|
||||
[M_TEXT.name]: question
|
||||
},
|
||||
kind: kind instanceof NamespacedValue ? kind.name : kind,
|
||||
max_selections: maxSelections,
|
||||
answers: answers.map(a => ({
|
||||
id: makeId(),
|
||||
[M_TEXT.name]: a
|
||||
}))
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
const LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
function makeId() {
|
||||
return [...Array(16)].map(() => LETTERS.charAt(Math.floor(Math.random() * LETTERS.length))).join("");
|
||||
}
|
||||
//# sourceMappingURL=PollStartEvent.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/PollStartEvent.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
14
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.d.ts
generated
vendored
Normal file
14
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { type Optional } from "matrix-events-sdk";
|
||||
/**
|
||||
* Determines if the given optional was provided a value.
|
||||
* @param s - The optional to test.
|
||||
* @returns True if the value is defined.
|
||||
*/
|
||||
export declare function isProvided<T>(s: Optional<T>): s is T;
|
||||
/**
|
||||
* Determines if the given optional string is a defined string.
|
||||
* @param s - The input string.
|
||||
* @returns True if the input is a defined string.
|
||||
*/
|
||||
export declare function isOptionalAString(s: Optional<string>): s is string;
|
||||
//# sourceMappingURL=utilities.d.ts.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.d.ts.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/extensible_events_v1/utilities.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,MAAM,CAElE"}
|
||||
34
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.js
generated
vendored
Normal file
34
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determines if the given optional was provided a value.
|
||||
* @param s - The optional to test.
|
||||
* @returns True if the value is defined.
|
||||
*/
|
||||
export function isProvided(s) {
|
||||
return s !== null && s !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given optional string is a defined string.
|
||||
* @param s - The input string.
|
||||
* @returns True if the input is a defined string.
|
||||
*/
|
||||
export function isOptionalAString(s) {
|
||||
return isProvided(s) && typeof s === "string";
|
||||
}
|
||||
//# sourceMappingURL=utilities.js.map
|
||||
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.js.map
generated
vendored
Normal file
1
node_modules/matrix-js-sdk/lib/extensible_events_v1/utilities.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utilities.js","names":[],"sources":["../../src/extensible_events_v1/utilities.ts"],"sourcesContent":["/*\nCopyright 2021 - 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Optional } from \"matrix-events-sdk\";\n\n/**\n * Determines if the given optional was provided a value.\n * @param s - The optional to test.\n * @returns True if the value is defined.\n */\nexport function isProvided<T>(s: Optional<T>): s is T {\n return s !== null && s !== undefined;\n}\n\n/**\n * Determines if the given optional string is a defined string.\n * @param s - The input string.\n * @returns True if the input is a defined string.\n */\nexport function isOptionalAString(s: Optional<string>): s is string {\n return isProvided(s) && typeof s === \"string\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,UAAU,CAAI,CAAc,EAAU;EAClD,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;AACxC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS,iBAAiB,CAAC,CAAmB,EAAe;EAChE,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;AACjD","ignoreList":[]}
|
||||
Reference in New Issue
Block a user