@textrp/briij-js-sdk 41.0.1 → 43.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/LICENSE +177 -177
- package/README.md +85 -3
- package/lib/@types/AESEncryptedSecretStoragePayload.js.map +1 -1
- package/lib/@types/IIdentityServerProvider.js.map +1 -1
- package/lib/@types/PushRules.js +14 -14
- package/lib/@types/PushRules.js.map +1 -1
- package/lib/@types/another-json.d.js.map +1 -1
- package/lib/@types/auth.d.ts +72 -1
- package/lib/@types/auth.d.ts.map +1 -1
- package/lib/@types/auth.js +57 -54
- package/lib/@types/auth.js.map +1 -1
- package/lib/@types/beacon.js +100 -100
- package/lib/@types/beacon.js.map +1 -1
- package/lib/@types/common.js.map +1 -1
- package/lib/@types/crypto.js.map +1 -1
- package/lib/@types/event.d.ts +59 -0
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js +105 -102
- package/lib/@types/event.js.map +1 -1
- package/lib/@types/events.js.map +1 -1
- package/lib/@types/extensible_events.js +53 -53
- package/lib/@types/extensible_events.js.map +1 -1
- package/lib/@types/local_notifications.js.map +1 -1
- package/lib/@types/location.js +41 -41
- package/lib/@types/location.js.map +1 -1
- package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -1
- package/lib/@types/media.js.map +1 -1
- package/lib/@types/membership.js +39 -39
- package/lib/@types/membership.js.map +1 -1
- package/lib/@types/partials.js +25 -25
- package/lib/@types/partials.js.map +1 -1
- package/lib/@types/polls.js +46 -46
- package/lib/@types/polls.js.map +1 -1
- package/lib/@types/read_receipts.js +14 -14
- package/lib/@types/read_receipts.js.map +1 -1
- package/lib/@types/registration.js.map +1 -1
- package/lib/@types/search.js +14 -14
- package/lib/@types/search.js.map +1 -1
- package/lib/@types/signed.js.map +1 -1
- package/lib/@types/spaces.js.map +1 -1
- package/lib/@types/state_events.js.map +1 -1
- package/lib/@types/synapse.js.map +1 -1
- package/lib/@types/sync.js +18 -18
- package/lib/@types/sync.js.map +1 -1
- package/lib/@types/threepids.js +14 -14
- package/lib/@types/threepids.js.map +1 -1
- package/lib/@types/topic.js +47 -47
- package/lib/@types/topic.js.map +1 -1
- package/lib/@types/uia.js.map +1 -1
- package/lib/NamespacedValue.js +20 -20
- package/lib/NamespacedValue.js.map +1 -1
- package/lib/ReEmitter.js +16 -16
- package/lib/ReEmitter.js.map +1 -1
- package/lib/base64.js +32 -32
- package/lib/base64.js.map +1 -1
- package/lib/briij.d.ts +4 -0
- package/lib/briij.d.ts.map +1 -1
- package/lib/briij.js +4 -0
- package/lib/briij.js.map +1 -1
- package/lib/client.d.ts +48 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +262 -108
- package/lib/client.js.map +1 -1
- package/lib/common-crypto/key-passphrase.js +19 -19
- package/lib/common-crypto/key-passphrase.js.map +1 -1
- package/lib/content-helpers.js +57 -57
- package/lib/content-helpers.js.map +1 -1
- package/lib/content-repo.js +36 -36
- package/lib/content-repo.js.map +1 -1
- package/lib/crypto/store/base.js +69 -69
- package/lib/crypto/store/base.js.map +1 -1
- package/lib/crypto/store/indexeddb-crypto-store-backend.js +58 -58
- package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
- package/lib/crypto/store/indexeddb-crypto-store.js +193 -193
- package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
- package/lib/crypto/store/localStorage-crypto-store.js +72 -72
- package/lib/crypto/store/localStorage-crypto-store.js.map +1 -1
- package/lib/crypto/store/memory-crypto-store.js +74 -74
- package/lib/crypto/store/memory-crypto-store.js.map +1 -1
- package/lib/crypto-api/CryptoEventHandlerMap.js.map +1 -1
- package/lib/crypto-api/key-passphrase.js +22 -22
- package/lib/crypto-api/key-passphrase.js.map +1 -1
- package/lib/crypto-api/keybackup.js.map +1 -1
- package/lib/crypto-api/recovery-key.js +20 -20
- package/lib/crypto-api/recovery-key.js.map +1 -1
- package/lib/digest.js +21 -21
- package/lib/digest.js.map +1 -1
- package/lib/extensible_events_v1/ExtensibleEvent.js +39 -39
- package/lib/extensible_events_v1/ExtensibleEvent.js.map +1 -1
- package/lib/extensible_events_v1/InvalidEventError.js +16 -16
- package/lib/extensible_events_v1/InvalidEventError.js.map +1 -1
- package/lib/extensible_events_v1/MessageEvent.js +39 -39
- package/lib/extensible_events_v1/MessageEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollEndEvent.js +29 -29
- package/lib/extensible_events_v1/PollEndEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollResponseEvent.js +39 -39
- package/lib/extensible_events_v1/PollResponseEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollStartEvent.js +52 -52
- package/lib/extensible_events_v1/PollStartEvent.js.map +1 -1
- package/lib/extensible_events_v1/utilities.js +22 -22
- package/lib/extensible_events_v1/utilities.js.map +1 -1
- package/lib/feature.js +16 -16
- package/lib/feature.js.map +1 -1
- package/lib/http-api/method.js +14 -14
- package/lib/http-api/method.js.map +1 -1
- package/lib/http-api/prefix.js +26 -26
- package/lib/http-api/prefix.js.map +1 -1
- package/lib/indexeddb-helpers.js +21 -21
- package/lib/indexeddb-helpers.js.map +1 -1
- package/lib/indexeddb-worker.js +18 -18
- package/lib/indexeddb-worker.js.map +1 -1
- package/lib/matrixrtc/IKeyTransport.js +17 -17
- package/lib/matrixrtc/IKeyTransport.js.map +1 -1
- package/lib/matrixrtc/IMembershipManager.js +27 -27
- package/lib/matrixrtc/IMembershipManager.js.map +1 -1
- package/lib/matrixrtc/LivekitTransport.js +19 -19
- package/lib/matrixrtc/LivekitTransport.js.map +1 -1
- package/lib/matrixrtc/index.js +14 -14
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/utils.js +27 -27
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/models/ToDeviceMessage.js.map +1 -1
- package/lib/models/device.js +24 -24
- package/lib/models/device.js.map +1 -1
- package/lib/models/event-status.js +17 -17
- package/lib/models/event-status.js.map +1 -1
- package/lib/models/invites-ignorer-types.js +25 -25
- package/lib/models/invites-ignorer-types.js.map +1 -1
- package/lib/models/profile-keys.js +26 -26
- package/lib/models/profile-keys.js.map +1 -1
- package/lib/models/room-summary.js +26 -26
- package/lib/models/room-summary.js.map +1 -1
- package/lib/models/search-result.js +22 -22
- package/lib/models/search-result.js.map +1 -1
- package/lib/models/typed-event-emitter.js +122 -122
- package/lib/models/typed-event-emitter.js.map +1 -1
- package/lib/oidc/authorize.js +76 -76
- package/lib/oidc/authorize.js.map +1 -1
- package/lib/oidc/error.js +17 -17
- package/lib/oidc/error.js.map +1 -1
- package/lib/oidc/index.js +17 -17
- package/lib/oidc/index.js.map +1 -1
- package/lib/oidc/register.js +41 -41
- package/lib/oidc/register.js.map +1 -1
- package/lib/oidc/tokenRefresher.js +51 -51
- package/lib/oidc/tokenRefresher.js.map +1 -1
- package/lib/oidc/validate.js +59 -59
- package/lib/oidc/validate.js.map +1 -1
- package/lib/randomstring.js +35 -35
- package/lib/randomstring.js.map +1 -1
- package/lib/realtime-callbacks.js +39 -39
- package/lib/realtime-callbacks.js.map +1 -1
- package/lib/receipt-accumulator.js +44 -44
- package/lib/receipt-accumulator.js.map +1 -1
- package/lib/rendezvous/RendezvousChannel.js.map +1 -1
- package/lib/rendezvous/RendezvousCode.js.map +1 -1
- package/lib/rendezvous/RendezvousError.js +14 -14
- package/lib/rendezvous/RendezvousError.js.map +1 -1
- package/lib/rendezvous/RendezvousFailureReason.js +14 -14
- package/lib/rendezvous/RendezvousFailureReason.js.map +1 -1
- package/lib/rendezvous/RendezvousIntent.js +14 -14
- package/lib/rendezvous/RendezvousIntent.js.map +1 -1
- package/lib/rendezvous/RendezvousTransport.js.map +1 -1
- package/lib/rendezvous/channels/MSC4108SecureChannel.js +63 -63
- package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +1 -1
- package/lib/rendezvous/channels/index.js +14 -14
- package/lib/rendezvous/channels/index.js.map +1 -1
- package/lib/rendezvous/index.js +14 -14
- package/lib/rendezvous/index.js.map +1 -1
- package/lib/rendezvous/transports/index.js +14 -14
- package/lib/rendezvous/transports/index.js.map +1 -1
- package/lib/rust-crypto/CrossSigningIdentity.js +29 -29
- package/lib/rust-crypto/CrossSigningIdentity.js.map +1 -1
- package/lib/rust-crypto/OutgoingRequestsManager.js +37 -37
- package/lib/rust-crypto/OutgoingRequestsManager.js.map +1 -1
- package/lib/rust-crypto/device-converter.js +30 -30
- package/lib/rust-crypto/device-converter.js.map +1 -1
- package/lib/rust-crypto/secret-storage.js +30 -30
- package/lib/rust-crypto/secret-storage.js.map +1 -1
- package/lib/service-types.js +14 -14
- package/lib/service-types.js.map +1 -1
- package/lib/store/local-storage-events-emitter.js +21 -21
- package/lib/store/local-storage-events-emitter.js.map +1 -1
- package/lib/sync-accumulator.js +50 -50
- package/lib/sync-accumulator.js.map +1 -1
- package/lib/thread-utils.js +20 -20
- package/lib/thread-utils.js.map +1 -1
- package/lib/types.js +34 -34
- package/lib/types.js.map +1 -1
- package/lib/utils/decryptAESSecretStorageItem.js +22 -22
- package/lib/utils/decryptAESSecretStorageItem.js.map +1 -1
- package/lib/utils/encryptAESSecretStorageItem.js +26 -26
- package/lib/utils/encryptAESSecretStorageItem.js.map +1 -1
- package/lib/utils/internal/deriveKeys.js +21 -21
- package/lib/utils/internal/deriveKeys.js.map +1 -1
- package/lib/utils/roomVersion.js +26 -26
- package/lib/utils/roomVersion.js.map +1 -1
- package/lib/version-support.js +26 -26
- package/lib/version-support.js.map +1 -1
- package/lib/wallet-recovery.d.ts +24 -0
- package/lib/wallet-recovery.d.ts.map +1 -0
- package/lib/wallet-recovery.js +232 -0
- package/lib/wallet-recovery.js.map +1 -0
- package/lib/webrtc/audioContext.js +24 -24
- package/lib/webrtc/audioContext.js.map +1 -1
- package/lib/webrtc/callEventTypes.js.map +1 -1
- package/lib/webrtc/stats/callFeedStatsReporter.js +14 -14
- package/lib/webrtc/stats/callFeedStatsReporter.js.map +1 -1
- package/lib/webrtc/stats/callStatsReportGatherer.js +14 -14
- package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
- package/lib/webrtc/stats/callStatsReportSummary.js.map +1 -1
- package/lib/webrtc/stats/connectionStats.js +14 -14
- package/lib/webrtc/stats/connectionStats.js.map +1 -1
- package/lib/webrtc/stats/connectionStatsBuilder.js +14 -14
- package/lib/webrtc/stats/connectionStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.js +14 -14
- package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +1 -1
- package/lib/webrtc/stats/groupCallStats.js +14 -14
- package/lib/webrtc/stats/groupCallStats.js.map +1 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.js +14 -14
- package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.js +14 -14
- package/lib/webrtc/stats/media/mediaTrackHandler.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackStats.js +27 -27
- package/lib/webrtc/stats/media/mediaTrackStats.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +20 -20
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +1 -1
- package/lib/webrtc/stats/statsReport.js +14 -14
- package/lib/webrtc/stats/statsReport.js.map +1 -1
- package/lib/webrtc/stats/statsReportEmitter.js +14 -14
- package/lib/webrtc/stats/statsReportEmitter.js.map +1 -1
- package/lib/webrtc/stats/trackStatsBuilder.js +4 -4
- package/lib/webrtc/stats/trackStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/transportStats.js.map +1 -1
- package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/valueFormatter.js +11 -11
- package/lib/webrtc/stats/valueFormatter.js.map +1 -1
- package/lib/xrpl/identity.d.ts +28 -0
- package/lib/xrpl/identity.d.ts.map +1 -0
- package/lib/xrpl/identity.js +213 -0
- package/lib/xrpl/identity.js.map +1 -0
- package/lib/xrpl/trust.d.ts +8 -0
- package/lib/xrpl/trust.d.ts.map +1 -0
- package/lib/xrpl/trust.js +61 -0
- package/lib/xrpl/trust.js.map +1 -0
- package/lib/xrpl/verification.d.ts +26 -0
- package/lib/xrpl/verification.d.ts.map +1 -0
- package/lib/xrpl/verification.js +295 -0
- package/lib/xrpl/verification.js.map +1 -0
- package/package.json +130 -129
- package/src/@types/AESEncryptedSecretStoragePayload.ts +29 -29
- package/src/@types/IIdentityServerProvider.ts +24 -24
- package/src/@types/PushRules.ts +208 -208
- package/src/@types/another-json.d.ts +19 -19
- package/src/@types/auth.ts +340 -258
- package/src/@types/beacon.ts +140 -140
- package/src/@types/common.ts +24 -24
- package/src/@types/crypto.ts +71 -71
- package/src/@types/event.ts +508 -449
- package/src/@types/events.ts +119 -119
- package/src/@types/extensible_events.ts +147 -147
- package/src/@types/local_notifications.ts +19 -19
- package/src/@types/location.ts +92 -92
- package/src/@types/matrix-sdk-crypto-wasm.d.ts +39 -39
- package/src/@types/media.ts +245 -245
- package/src/@types/membership.ts +57 -57
- package/src/@types/partials.ts +103 -103
- package/src/@types/polls.ts +120 -120
- package/src/@types/read_receipts.ts +61 -61
- package/src/@types/registration.ts +102 -102
- package/src/@types/search.ts +119 -119
- package/src/@types/signed.ts +25 -25
- package/src/@types/spaces.ts +37 -37
- package/src/@types/state_events.ts +153 -153
- package/src/@types/synapse.ts +40 -40
- package/src/@types/sync.ts +27 -27
- package/src/@types/threepids.ts +29 -29
- package/src/@types/topic.ts +69 -69
- package/src/@types/uia.ts +24 -24
- package/src/NamespacedValue.ts +121 -121
- package/src/ReEmitter.ts +93 -93
- package/src/base64.ts +86 -86
- package/src/briij.ts +4 -0
- package/src/client.ts +183 -10
- package/src/common-crypto/README.md +4 -4
- package/src/common-crypto/key-passphrase.ts +43 -43
- package/src/content-helpers.ts +298 -298
- package/src/content-repo.ts +122 -122
- package/src/crypto/store/base.ts +388 -388
- package/src/crypto/store/indexeddb-crypto-store-backend.ts +655 -655
- package/src/crypto/store/indexeddb-crypto-store.ts +555 -555
- package/src/crypto/store/localStorage-crypto-store.ts +409 -409
- package/src/crypto/store/memory-crypto-store.ts +326 -326
- package/src/crypto-api/CryptoEventHandlerMap.ts +42 -42
- package/src/crypto-api/key-passphrase.ts +58 -58
- package/src/crypto-api/keybackup.ts +114 -114
- package/src/crypto-api/recovery-key.ts +69 -69
- package/src/digest.ts +34 -34
- package/src/extensible_events_v1/ExtensibleEvent.ts +58 -58
- package/src/extensible_events_v1/InvalidEventError.ts +24 -24
- package/src/extensible_events_v1/MessageEvent.ts +143 -143
- package/src/extensible_events_v1/PollEndEvent.ts +97 -97
- package/src/extensible_events_v1/PollResponseEvent.ts +148 -148
- package/src/extensible_events_v1/PollStartEvent.ts +207 -207
- package/src/extensible_events_v1/utilities.ts +35 -35
- package/src/feature.ts +88 -88
- package/src/http-api/method.ts +25 -25
- package/src/http-api/prefix.ts +48 -48
- package/src/indexeddb-helpers.ts +50 -50
- package/src/indexeddb-worker.ts +24 -24
- package/src/matrixrtc/IKeyTransport.ts +63 -63
- package/src/matrixrtc/IMembershipManager.ts +120 -120
- package/src/matrixrtc/LivekitTransport.ts +46 -46
- package/src/matrixrtc/index.ts +24 -24
- package/src/matrixrtc/utils.ts +71 -71
- package/src/models/ToDeviceMessage.ts +38 -38
- package/src/models/device.ts +85 -85
- package/src/models/event-status.ts +39 -39
- package/src/models/invites-ignorer-types.ts +58 -58
- package/src/models/profile-keys.ts +33 -33
- package/src/models/room-summary.ts +78 -78
- package/src/models/search-result.ts +57 -57
- package/src/models/typed-event-emitter.ts +246 -246
- package/src/oidc/authorize.ts +279 -279
- package/src/oidc/error.ts +33 -33
- package/src/oidc/index.ts +33 -33
- package/src/oidc/register.ts +163 -163
- package/src/oidc/tokenRefresher.ts +184 -184
- package/src/oidc/validate.ts +265 -265
- package/src/randomstring.ts +103 -103
- package/src/realtime-callbacks.ts +191 -191
- package/src/receipt-accumulator.ts +189 -189
- package/src/rendezvous/RendezvousChannel.ts +48 -48
- package/src/rendezvous/RendezvousCode.ts +25 -25
- package/src/rendezvous/RendezvousError.ts +26 -26
- package/src/rendezvous/RendezvousFailureReason.ts +49 -49
- package/src/rendezvous/RendezvousIntent.ts +20 -20
- package/src/rendezvous/RendezvousTransport.ts +58 -58
- package/src/rendezvous/channels/MSC4108SecureChannel.ts +270 -270
- package/src/rendezvous/channels/index.ts +17 -17
- package/src/rendezvous/index.ts +25 -25
- package/src/rendezvous/transports/index.ts +17 -17
- package/src/rust-crypto/CrossSigningIdentity.ts +195 -195
- package/src/rust-crypto/OutgoingRequestsManager.ts +170 -170
- package/src/rust-crypto/device-converter.ts +128 -128
- package/src/rust-crypto/secret-storage.ts +60 -60
- package/src/service-types.ts +20 -20
- package/src/store/local-storage-events-emitter.ts +46 -46
- package/src/sync-accumulator.ts +779 -779
- package/src/thread-utils.ts +31 -31
- package/src/types.ts +59 -59
- package/src/utils/decryptAESSecretStorageItem.ts +54 -54
- package/src/utils/encryptAESSecretStorageItem.ts +73 -73
- package/src/utils/internal/deriveKeys.ts +63 -63
- package/src/utils/roomVersion.ts +35 -35
- package/src/version-support.ts +50 -50
- package/src/wallet-recovery.ts +252 -0
- package/src/webrtc/audioContext.ts +44 -44
- package/src/webrtc/callEventTypes.ts +101 -101
- package/src/webrtc/stats/callFeedStatsReporter.ts +91 -91
- package/src/webrtc/stats/callStatsReportGatherer.ts +219 -219
- package/src/webrtc/stats/callStatsReportSummary.ts +30 -30
- package/src/webrtc/stats/connectionStats.ts +47 -47
- package/src/webrtc/stats/connectionStatsBuilder.ts +28 -28
- package/src/webrtc/stats/connectionStatsReportBuilder.ts +140 -140
- package/src/webrtc/stats/groupCallStats.ts +93 -93
- package/src/webrtc/stats/media/mediaSsrcHandler.ts +57 -57
- package/src/webrtc/stats/media/mediaTrackHandler.ts +70 -70
- package/src/webrtc/stats/media/mediaTrackStats.ts +176 -176
- package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +90 -90
- package/src/webrtc/stats/statsReport.ts +133 -133
- package/src/webrtc/stats/statsReportEmitter.ts +49 -49
- package/src/webrtc/stats/trackStatsBuilder.ts +207 -207
- package/src/webrtc/stats/transportStats.ts +26 -26
- package/src/webrtc/stats/transportStatsBuilder.ts +48 -48
- package/src/webrtc/stats/valueFormatter.ts +27 -27
- package/src/xrpl/identity.ts +245 -0
- package/src/xrpl/trust.ts +64 -0
- package/src/xrpl/verification.ts +284 -0
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Represents an Extensible Event in Matrix.
|
|
17
|
+
/**
|
|
18
|
+
* Represents an Extensible Event in Matrix.
|
|
19
19
|
*/
|
|
20
20
|
export class ExtensibleEvent {
|
|
21
21
|
constructor(wireFormat) {
|
|
22
22
|
this.wireFormat = wireFormat;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Shortcut to wireFormat.content
|
|
25
|
+
/**
|
|
26
|
+
* Shortcut to wireFormat.content
|
|
27
27
|
*/
|
|
28
28
|
get wireContent() {
|
|
29
29
|
return this.wireFormat.content;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* Serializes the event into a format which can be used to send the
|
|
34
|
-
* event to the room.
|
|
35
|
-
* @returns The serialized event.
|
|
32
|
+
/**
|
|
33
|
+
* Serializes the event into a format which can be used to send the
|
|
34
|
+
* event to the room.
|
|
35
|
+
* @returns The serialized event.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Determines if this event is equivalent to the provided event type.
|
|
40
|
-
* This is recommended over `instanceof` checks due to issues in the JS
|
|
41
|
-
* runtime (and layering of dependencies in some projects).
|
|
42
|
-
*
|
|
43
|
-
* Implementations should pass this check off to their super classes
|
|
44
|
-
* if their own checks fail. Some primary implementations do not extend
|
|
45
|
-
* fallback classes given they support the primary type first. Thus,
|
|
46
|
-
* those classes may return false if asked about their fallback
|
|
47
|
-
* representation.
|
|
48
|
-
*
|
|
49
|
-
* Note that this only checks primary event types: legacy events, like
|
|
50
|
-
* m.room.message, should/will fail this check.
|
|
51
|
-
* @param primaryEventType - The (potentially namespaced) event
|
|
52
|
-
* type.
|
|
53
|
-
* @returns True if this event *could* be represented as the
|
|
54
|
-
* given type.
|
|
38
|
+
/**
|
|
39
|
+
* Determines if this event is equivalent to the provided event type.
|
|
40
|
+
* This is recommended over `instanceof` checks due to issues in the JS
|
|
41
|
+
* runtime (and layering of dependencies in some projects).
|
|
42
|
+
*
|
|
43
|
+
* Implementations should pass this check off to their super classes
|
|
44
|
+
* if their own checks fail. Some primary implementations do not extend
|
|
45
|
+
* fallback classes given they support the primary type first. Thus,
|
|
46
|
+
* those classes may return false if asked about their fallback
|
|
47
|
+
* representation.
|
|
48
|
+
*
|
|
49
|
+
* Note that this only checks primary event types: legacy events, like
|
|
50
|
+
* m.room.message, should/will fail this check.
|
|
51
|
+
* @param primaryEventType - The (potentially namespaced) event
|
|
52
|
+
* type.
|
|
53
|
+
* @returns True if this event *could* be represented as the
|
|
54
|
+
* given type.
|
|
55
55
|
*/
|
|
56
56
|
}
|
|
57
57
|
//# sourceMappingURL=ExtensibleEvent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensibleEvent.js","names":["ExtensibleEvent","constructor","wireFormat","wireContent","content"],"sources":["../../src/extensible_events_v1/ExtensibleEvent.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"ExtensibleEvent.js","names":["ExtensibleEvent","constructor","wireFormat","wireContent","content"],"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,MAAeA,eAAe,CAAmC;EAC1DC,WAAWA,CAAiBC,UAAmC,EAAE;IAAA,KAArCA,UAAmC,GAAnCA,UAAmC;EAAG;;EAE5E;AACJ;AACA;EACI,IAAWC,WAAWA,CAAA,EAAa;IAC/B,OAAO,IAAI,CAACD,UAAU,CAACE,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":[]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Thrown when an event is unforgivably unparsable.
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when an event is unforgivably unparsable.
|
|
19
19
|
*/
|
|
20
20
|
export class InvalidEventError extends Error {
|
|
21
21
|
constructor(message) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvalidEventError.js","names":["InvalidEventError","Error","constructor","message"],"sources":["../../src/extensible_events_v1/InvalidEventError.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"InvalidEventError.js","names":["InvalidEventError","Error","constructor","message"],"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,MAAMA,iBAAiB,SAASC,KAAK,CAAC;EAClCC,WAAWA,CAACC,OAAe,EAAE;IAChC,KAAK,CAACA,OAAO,CAAC;EAClB;AACJ","ignoreList":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
/*
|
|
5
|
-
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
6
|
-
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License.
|
|
9
|
-
You may obtain a copy of the License at
|
|
10
|
-
|
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
See the License for the specific language governing permissions and
|
|
17
|
-
limitations under the License.
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
|
@@ -22,35 +22,35 @@ import { isEventTypeSame, M_HTML, M_MESSAGE, M_TEXT } from "../@types/extensible
|
|
|
22
22
|
import { isOptionalAString, isProvided } from "./utilities.js";
|
|
23
23
|
import { InvalidEventError } from "./InvalidEventError.js";
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Represents a message event. Message events are the simplest form of event with
|
|
27
|
-
* just text (optionally of different mimetypes, like HTML).
|
|
28
|
-
*
|
|
29
|
-
* Message events can additionally be an Emote or Notice, though typically those
|
|
30
|
-
* are represented as EmoteEvent and NoticeEvent respectively.
|
|
25
|
+
/**
|
|
26
|
+
* Represents a message event. Message events are the simplest form of event with
|
|
27
|
+
* just text (optionally of different mimetypes, like HTML).
|
|
28
|
+
*
|
|
29
|
+
* Message events can additionally be an Emote or Notice, though typically those
|
|
30
|
+
* are represented as EmoteEvent and NoticeEvent respectively.
|
|
31
31
|
*/
|
|
32
32
|
export class MessageEvent extends ExtensibleEvent {
|
|
33
|
-
/**
|
|
34
|
-
* Creates a new MessageEvent from a pure format. Note that the event is
|
|
35
|
-
* *not* parsed here: it will be treated as a literal m.message primary
|
|
36
|
-
* typed event.
|
|
37
|
-
* @param wireFormat - The event.
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new MessageEvent from a pure format. Note that the event is
|
|
35
|
+
* *not* parsed here: it will be treated as a literal m.message primary
|
|
36
|
+
* typed event.
|
|
37
|
+
* @param wireFormat - The event.
|
|
38
38
|
*/
|
|
39
39
|
constructor(wireFormat) {
|
|
40
40
|
super(wireFormat);
|
|
41
|
-
/**
|
|
42
|
-
* The default text for the event.
|
|
41
|
+
/**
|
|
42
|
+
* The default text for the event.
|
|
43
43
|
*/
|
|
44
44
|
_defineProperty(this, "text", void 0);
|
|
45
|
-
/**
|
|
46
|
-
* The default HTML for the event, if provided.
|
|
45
|
+
/**
|
|
46
|
+
* The default HTML for the event, if provided.
|
|
47
47
|
*/
|
|
48
48
|
_defineProperty(this, "html", void 0);
|
|
49
|
-
/**
|
|
50
|
-
* All the different renderings of the message. Note that this is the same
|
|
51
|
-
* format as an m.message body but may contain elements not found directly
|
|
52
|
-
* in the event content: this is because this is interpreted based off the
|
|
53
|
-
* other information available in the event.
|
|
49
|
+
/**
|
|
50
|
+
* All the different renderings of the message. Note that this is the same
|
|
51
|
+
* format as an m.message body but may contain elements not found directly
|
|
52
|
+
* in the event content: this is because this is interpreted based off the
|
|
53
|
+
* other information available in the event.
|
|
54
54
|
*/
|
|
55
55
|
_defineProperty(this, "renderings", void 0);
|
|
56
56
|
var mmessage = M_MESSAGE.findIn(this.wireContent);
|
|
@@ -115,11 +115,11 @@ export class MessageEvent extends ExtensibleEvent {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
/**
|
|
119
|
-
* Creates a new MessageEvent from text and HTML.
|
|
120
|
-
* @param text - The text.
|
|
121
|
-
* @param html - Optional HTML.
|
|
122
|
-
* @returns The representative message event.
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new MessageEvent from text and HTML.
|
|
120
|
+
* @param text - The text.
|
|
121
|
+
* @param html - Optional HTML.
|
|
122
|
+
* @returns The representative message event.
|
|
123
123
|
*/
|
|
124
124
|
static from(text, html) {
|
|
125
125
|
return new MessageEvent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageEvent.js","names":["ExtensibleEvent","isEventTypeSame","M_HTML","M_MESSAGE","M_TEXT","isOptionalAString","isProvided","InvalidEventError","MessageEvent","constructor","wireFormat","_defineProperty","mmessage","findIn","wireContent","mtext","mhtml","Array","isArray","text","find","r","mimetype","html","body","renderings","undefined","push","isEquivalentTo","primaryEventType","serializeMMessageOnly","messageRendering","name","length","mime","serialize","_this$html","type","content","_objectSpread","msgtype","format","formatted_body","from"],"sources":["../../src/extensible_events_v1/MessageEvent.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"MessageEvent.js","names":["ExtensibleEvent","isEventTypeSame","M_HTML","M_MESSAGE","M_TEXT","isOptionalAString","isProvided","InvalidEventError","MessageEvent","constructor","wireFormat","_defineProperty","mmessage","findIn","wireContent","mtext","mhtml","Array","isArray","text","find","r","mimetype","html","body","renderings","undefined","push","isEquivalentTo","primaryEventType","serializeMMessageOnly","messageRendering","name","length","mime","serialize","_this$html","type","content","_objectSpread","msgtype","format","formatted_body","from"],"sources":["../../src/extensible_events_v1/MessageEvent.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 { ExtensibleEvent } from \"./ExtensibleEvent.ts\";\nimport {\n type ExtensibleEventType,\n type IMessageRendering,\n type IPartialEvent,\n isEventTypeSame,\n M_HTML,\n M_MESSAGE,\n type ExtensibleAnyMessageEventContent,\n M_TEXT,\n} from \"../@types/extensible_events.ts\";\nimport { isOptionalAString, isProvided } from \"./utilities.ts\";\nimport { InvalidEventError } from \"./InvalidEventError.ts\";\n\n/**\n * Represents a message event. Message events are the simplest form of event with\n * just text (optionally of different mimetypes, like HTML).\n *\n * Message events can additionally be an Emote or Notice, though typically those\n * are represented as EmoteEvent and NoticeEvent respectively.\n */\nexport class MessageEvent extends ExtensibleEvent<ExtensibleAnyMessageEventContent> {\n /**\n * The default text for the event.\n */\n public readonly text: string;\n\n /**\n * The default HTML for the event, if provided.\n */\n public readonly html?: string;\n\n /**\n * All the different renderings of the message. Note that this is the same\n * format as an m.message body but may contain elements not found directly\n * in the event content: this is because this is interpreted based off the\n * other information available in the event.\n */\n public readonly renderings: IMessageRendering[];\n\n /**\n * Creates a new MessageEvent from a pure format. Note that the event is\n * *not* parsed here: it will be treated as a literal m.message primary\n * typed event.\n * @param wireFormat - The event.\n */\n public constructor(wireFormat: IPartialEvent<ExtensibleAnyMessageEventContent>) {\n super(wireFormat);\n\n const mmessage = M_MESSAGE.findIn(this.wireContent);\n const mtext = M_TEXT.findIn<string>(this.wireContent);\n const mhtml = M_HTML.findIn<string>(this.wireContent);\n if (isProvided(mmessage)) {\n if (!Array.isArray(mmessage)) {\n throw new InvalidEventError(\"m.message contents must be an array\");\n }\n const text = mmessage.find((r) => !isProvided(r.mimetype) || r.mimetype === \"text/plain\");\n const html = mmessage.find((r) => r.mimetype === \"text/html\");\n\n if (!text) throw new InvalidEventError(\"m.message is missing a plain text representation\");\n\n this.text = text.body;\n this.html = html?.body;\n this.renderings = mmessage;\n } else if (isOptionalAString(mtext)) {\n this.text = mtext;\n this.html = mhtml ?? undefined;\n this.renderings = [{ body: mtext, mimetype: \"text/plain\" }];\n if (this.html) {\n this.renderings.push({ body: this.html, mimetype: \"text/html\" });\n }\n } else {\n throw new InvalidEventError(\"Missing textual representation for event\");\n }\n }\n\n public isEquivalentTo(primaryEventType: ExtensibleEventType): boolean {\n return isEventTypeSame(primaryEventType, M_MESSAGE);\n }\n\n protected serializeMMessageOnly(): ExtensibleAnyMessageEventContent {\n let messageRendering: ExtensibleAnyMessageEventContent = {\n [M_MESSAGE.name]: this.renderings,\n };\n\n // Use the shorthand if it's just a simple text event\n if (this.renderings.length === 1) {\n const mime = this.renderings[0].mimetype;\n if (mime === undefined || mime === \"text/plain\") {\n messageRendering = {\n [M_TEXT.name]: this.renderings[0].body,\n };\n }\n }\n\n return messageRendering;\n }\n\n public serialize(): IPartialEvent<object> {\n return {\n type: \"m.room.message\",\n content: {\n ...this.serializeMMessageOnly(),\n body: this.text,\n msgtype: \"m.text\",\n format: this.html ? \"org.matrix.custom.html\" : undefined,\n formatted_body: this.html ?? undefined,\n },\n };\n }\n\n /**\n * Creates a new MessageEvent from text and HTML.\n * @param text - The text.\n * @param html - Optional HTML.\n * @returns The representative message event.\n */\n public static from(text: string, html?: string): MessageEvent {\n return new MessageEvent({\n type: M_MESSAGE.name,\n content: {\n [M_TEXT.name]: text,\n [M_HTML.name]: html,\n },\n });\n }\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,sBAAsB;AACtD,SAIIC,eAAe,EACfC,MAAM,EACNC,SAAS,EAETC,MAAM,QACH,gCAAgC;AACvC,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,gBAAgB;AAC9D,SAASC,iBAAiB,QAAQ,wBAAwB;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,SAASR,eAAe,CAAmC;EAmBhF;AACJ;AACA;AACA;AACA;AACA;EACWS,WAAWA,CAACC,UAA2D,EAAE;IAC5E,KAAK,CAACA,UAAU,CAAC;IAzBrB;AACJ;AACA;IAFIC,eAAA;IAKA;AACJ;AACA;IAFIA,eAAA;IAKA;AACJ;AACA;AACA;AACA;AACA;IALIA,eAAA;IAiBI,IAAMC,QAAQ,GAAGT,SAAS,CAACU,MAAM,CAAC,IAAI,CAACC,WAAW,CAAC;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AI;MACpBM,OAAO,EAAE;QACL,CAAClC,MAAM,CAAC4B,IAAI,GAAGb,IAAI;QACnB,CAACjB,MAAM,CAAC8B,IAAI,GAAGT;MACnB;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
/*
|
|
5
|
-
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
6
|
-
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License.
|
|
9
|
-
You may obtain a copy of the License at
|
|
10
|
-
|
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
See the License for the specific language governing permissions and
|
|
17
|
-
limitations under the License.
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { isEventTypeSame, M_TEXT, REFERENCE_RELATION } from "../@types/extensible_events.js";
|
|
@@ -23,23 +23,23 @@ import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
|
|
23
23
|
import { InvalidEventError } from "./InvalidEventError.js";
|
|
24
24
|
import { MessageEvent } from "./MessageEvent.js";
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* Represents a poll end/closure event.
|
|
26
|
+
/**
|
|
27
|
+
* Represents a poll end/closure event.
|
|
28
28
|
*/
|
|
29
29
|
export class PollEndEvent extends ExtensibleEvent {
|
|
30
|
-
/**
|
|
31
|
-
* Creates a new PollEndEvent from a pure format. Note that the event is *not*
|
|
32
|
-
* parsed here: it will be treated as a literal m.poll.response primary typed event.
|
|
33
|
-
* @param wireFormat - The event.
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new PollEndEvent from a pure format. Note that the event is *not*
|
|
32
|
+
* parsed here: it will be treated as a literal m.poll.response primary typed event.
|
|
33
|
+
* @param wireFormat - The event.
|
|
34
34
|
*/
|
|
35
35
|
constructor(wireFormat) {
|
|
36
36
|
super(wireFormat);
|
|
37
|
-
/**
|
|
38
|
-
* The poll start event ID referenced by the response.
|
|
37
|
+
/**
|
|
38
|
+
* The poll start event ID referenced by the response.
|
|
39
39
|
*/
|
|
40
40
|
_defineProperty(this, "pollEventId", void 0);
|
|
41
|
-
/**
|
|
42
|
-
* The closing message for the event.
|
|
41
|
+
/**
|
|
42
|
+
* The closing message for the event.
|
|
43
43
|
*/
|
|
44
44
|
_defineProperty(this, "closingMessage", void 0);
|
|
45
45
|
var rel = this.wireContent["m.relates_to"];
|
|
@@ -65,11 +65,11 @@ export class PollEndEvent extends ExtensibleEvent {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
/**
|
|
69
|
-
* Creates a new PollEndEvent from a poll event ID.
|
|
70
|
-
* @param pollEventId - The poll start event ID.
|
|
71
|
-
* @param message - A closing message, typically revealing the top answer.
|
|
72
|
-
* @returns The representative poll closure event.
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new PollEndEvent from a poll event ID.
|
|
70
|
+
* @param pollEventId - The poll start event ID.
|
|
71
|
+
* @param message - A closing message, typically revealing the top answer.
|
|
72
|
+
* @returns The representative poll closure event.
|
|
73
73
|
*/
|
|
74
74
|
static from(pollEventId, message) {
|
|
75
75
|
return new PollEndEvent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PollEndEvent.js","names":["isEventTypeSame","M_TEXT","REFERENCE_RELATION","M_POLL_END","ExtensibleEvent","InvalidEventError","MessageEvent","PollEndEvent","constructor","wireFormat","_defineProperty","rel","wireContent","matches","rel_type","event_id","pollEventId","closingMessage","isEquivalentTo","primaryEventType","serialize","type","name","content","_objectSpread","from","message"],"sources":["../../src/extensible_events_v1/PollEndEvent.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"PollEndEvent.js","names":["isEventTypeSame","M_TEXT","REFERENCE_RELATION","M_POLL_END","ExtensibleEvent","InvalidEventError","MessageEvent","PollEndEvent","constructor","wireFormat","_defineProperty","rel","wireContent","matches","rel_type","event_id","pollEventId","closingMessage","isEquivalentTo","primaryEventType","serialize","type","name","content","_objectSpread","from","message"],"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,SAGIA,eAAe,EACfC,MAAM,EACNC,kBAAkB,QACf,gCAAgC;AACvC,SAASC,UAAU,QAAkC,oBAAoB;AACzE,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,YAAY,QAAQ,mBAAmB;;AAEhD;AACA;AACA;AACA,OAAO,MAAMC,YAAY,SAASH,eAAe,CAAsB;EAWnE;AACJ;AACA;AACA;AACA;EACWI,WAAWA,CAACC,UAA8C,EAAE;IAC/D,KAAK,CAACA,UAAU,CAAC;IAhBrB;AACJ;AACA;IAFIC,eAAA;IAKA;AACJ;AACA;IAFIA,eAAA;IAaI,IAAMC,GAAG,GAAG,IAAI,CAACC,WAAW,CAAC,cAAc,CAAC;IAC5C,IAAI,CAACV,kBAAkB,CAACW,OAAO,CAACF,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG,QAAQ,CAAC,IAAI,QAAOH,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEI,QAAQ,MAAK,QAAQ,EAAE;MACjF,MAAM,IAAIV,iBAAiB,CAAC,8CAA8C,CAAC;IAC/E;IAEA,IAAI,CAACW,WAAW,GAAGL,GAAG,CAACI,QAAQ;IAC/B,IAAI,CAACE,cAAc,GAAG,IAAIX,YAAY,CAAC,IAAI,CAACG,UAAU,CAAC;EAC3D;EAEOS,cAAcA,CAACC,gBAAqC,EAAW;IAClE,OAAOnB,eAAe,CAACmB,gBAAgB,EAAEhB,UAAU,CAAC;EACxD;EAEOiB,SAASA,CAAA,EAA0B;IACtC,OAAO;MACHC,IAAI,EAAElB,UAAU,CAACmB,IAAI;MACrBC,OAAO,EAAAC,aAAA;QACH,cAAc,EAAE;UACZV,QAAQ,EAAEZ,kBAAkB,CAACoB,IAAI;UACjCP,QAAQ,EAAE,IAAI,CAACC;QACnB,CAAC;QACD,CAACb,UAAU,CAACmB,IAAI,GAAG,CAAC;MAAC,GAClB,IAAI,CAACL,cAAc,CAACG,SAAS,CAAC,CAAC,CAACG,OAAO;IAElD,CAAC;EACL;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAcE,IAAIA,CAACT,WAAmB,EAAEU,OAAe,EAAgB;IACnE,OAAO,IAAInB,YAAY,CAAC;MACpBc,IAAI,EAAElB,UAAU,CAACmB,IAAI;MACrBC,OAAO,EAAE;QACL,cAAc,EAAE;UACZT,QAAQ,EAAEZ,kBAAkB,CAACoB,IAAI;UACjCP,QAAQ,EAAEC;QACd,CAAC;QACD,CAACb,UAAU,CAACmB,IAAI,GAAG,CAAC,CAAC;QACrB,CAACrB,MAAM,CAACqB,IAAI,GAAGI;MACnB;IACJ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
4
|
-
|
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
you may not use this file except in compliance with the License.
|
|
7
|
-
You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
See the License for the specific language governing permissions and
|
|
15
|
-
limitations under the License.
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { ExtensibleEvent } from "./ExtensibleEvent.js";
|
|
19
19
|
import { M_POLL_RESPONSE } from "../@types/polls.js";
|
|
20
20
|
import { isEventTypeSame, REFERENCE_RELATION } from "../@types/extensible_events.js";
|
|
21
21
|
import { InvalidEventError } from "./InvalidEventError.js";
|
|
22
|
-
/**
|
|
23
|
-
* Represents a poll response event.
|
|
22
|
+
/**
|
|
23
|
+
* Represents a poll response event.
|
|
24
24
|
*/
|
|
25
25
|
export class PollResponseEvent extends ExtensibleEvent {
|
|
26
|
-
/**
|
|
27
|
-
* The provided answers for the poll. Note that this may be falsy/unpredictable if
|
|
28
|
-
* the `spoiled` property is true.
|
|
26
|
+
/**
|
|
27
|
+
* The provided answers for the poll. Note that this may be falsy/unpredictable if
|
|
28
|
+
* the `spoiled` property is true.
|
|
29
29
|
*/
|
|
30
30
|
get answerIds() {
|
|
31
31
|
return this.internalAnswerIds;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
/**
|
|
35
|
-
* The poll start event ID referenced by the response.
|
|
34
|
+
/**
|
|
35
|
+
* The poll start event ID referenced by the response.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Whether the vote is spoiled.
|
|
38
|
+
/**
|
|
39
|
+
* Whether the vote is spoiled.
|
|
40
40
|
*/
|
|
41
41
|
get spoiled() {
|
|
42
42
|
return this.internalSpoiled;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
* Creates a new PollResponseEvent from a pure format. Note that the event is *not*
|
|
47
|
-
* parsed here: it will be treated as a literal m.poll.response primary typed event.
|
|
48
|
-
*
|
|
49
|
-
* To validate the response against a poll, call `validateAgainst` after creation.
|
|
50
|
-
* @param wireFormat - The event.
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new PollResponseEvent from a pure format. Note that the event is *not*
|
|
47
|
+
* parsed here: it will be treated as a literal m.poll.response primary typed event.
|
|
48
|
+
*
|
|
49
|
+
* To validate the response against a poll, call `validateAgainst` after creation.
|
|
50
|
+
* @param wireFormat - The event.
|
|
51
51
|
*/
|
|
52
52
|
constructor(wireFormat) {
|
|
53
53
|
super(wireFormat);
|
|
@@ -62,10 +62,10 @@ export class PollResponseEvent extends ExtensibleEvent {
|
|
|
62
62
|
this.validateAgainst(null);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
* Validates the poll response using the poll start event as a frame of reference. This
|
|
67
|
-
* is used to determine if the vote is spoiled, whether the answers are valid, etc.
|
|
68
|
-
* @param poll - The poll start event.
|
|
65
|
+
/**
|
|
66
|
+
* Validates the poll response using the poll start event as a frame of reference. This
|
|
67
|
+
* is used to determine if the vote is spoiled, whether the answers are valid, etc.
|
|
68
|
+
* @param poll - The poll start event.
|
|
69
69
|
*/
|
|
70
70
|
validateAgainst(poll) {
|
|
71
71
|
var _response$answers;
|
|
@@ -110,12 +110,12 @@ export class PollResponseEvent extends ExtensibleEvent {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/**
|
|
114
|
-
* Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty
|
|
115
|
-
* answers array.
|
|
116
|
-
* @param answers - The user's answers. Should be valid from a poll's answer IDs.
|
|
117
|
-
* @param pollEventId - The poll start event ID.
|
|
118
|
-
* @returns The representative poll response event.
|
|
113
|
+
/**
|
|
114
|
+
* Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty
|
|
115
|
+
* answers array.
|
|
116
|
+
* @param answers - The user's answers. Should be valid from a poll's answer IDs.
|
|
117
|
+
* @param pollEventId - The poll start event ID.
|
|
118
|
+
* @returns The representative poll response event.
|
|
119
119
|
*/
|
|
120
120
|
static from(answers, pollEventId) {
|
|
121
121
|
return new PollResponseEvent({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PollResponseEvent.js","names":["ExtensibleEvent","M_POLL_RESPONSE","isEventTypeSame","REFERENCE_RELATION","InvalidEventError","PollResponseEvent","answerIds","internalAnswerIds","spoiled","internalSpoiled","constructor","wireFormat","_defineProperty","rel","wireContent","matches","rel_type","event_id","pollEventId","validateAgainst","poll","_response$answers","response","findIn","Array","isArray","answers","some","a","length","pa","id","slice","maxSelections","isEquivalentTo","primaryEventType","serialize","type","name","content","undefined","from"],"sources":["../../src/extensible_events_v1/PollResponseEvent.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"PollResponseEvent.js","names":["ExtensibleEvent","M_POLL_RESPONSE","isEventTypeSame","REFERENCE_RELATION","InvalidEventError","PollResponseEvent","answerIds","internalAnswerIds","spoiled","internalSpoiled","constructor","wireFormat","_defineProperty","rel","wireContent","matches","rel_type","event_id","pollEventId","validateAgainst","poll","_response$answers","response","findIn","Array","isArray","answers","some","a","length","pa","id","slice","maxSelections","isEquivalentTo","primaryEventType","serialize","type","name","content","undefined","from"],"sources":["../../src/extensible_events_v1/PollResponseEvent.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 { ExtensibleEvent } from \"./ExtensibleEvent.ts\";\nimport { M_POLL_RESPONSE, type PollResponseEventContent, type PollResponseSubtype } from \"../@types/polls.ts\";\nimport {\n type ExtensibleEventType,\n type IPartialEvent,\n isEventTypeSame,\n REFERENCE_RELATION,\n} from \"../@types/extensible_events.ts\";\nimport { InvalidEventError } from \"./InvalidEventError.ts\";\nimport { type PollStartEvent } from \"./PollStartEvent.ts\";\n\n/**\n * Represents a poll response event.\n */\nexport class PollResponseEvent extends ExtensibleEvent<PollResponseEventContent> {\n private internalAnswerIds: string[] = [];\n private internalSpoiled = false;\n\n /**\n * The provided answers for the poll. Note that this may be falsy/unpredictable if\n * the `spoiled` property is true.\n */\n public get answerIds(): string[] {\n return this.internalAnswerIds;\n }\n\n /**\n * The poll start event ID referenced by the response.\n */\n public readonly pollEventId: string;\n\n /**\n * Whether the vote is spoiled.\n */\n public get spoiled(): boolean {\n return this.internalSpoiled;\n }\n\n /**\n * Creates a new PollResponseEvent 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 *\n * To validate the response against a poll, call `validateAgainst` after creation.\n * @param wireFormat - The event.\n */\n public constructor(wireFormat: IPartialEvent<PollResponseEventContent>) {\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.validateAgainst(null);\n }\n\n /**\n * Validates the poll response using the poll start event as a frame of reference. This\n * is used to determine if the vote is spoiled, whether the answers are valid, etc.\n * @param poll - The poll start event.\n */\n public validateAgainst(poll: PollStartEvent | null): void {\n const response = M_POLL_RESPONSE.findIn<PollResponseSubtype>(this.wireContent);\n if (!Array.isArray(response?.answers)) {\n this.internalSpoiled = true;\n this.internalAnswerIds = [];\n return;\n }\n\n let answers = response?.answers ?? [];\n if (answers.some((a) => typeof a !== \"string\") || answers.length === 0) {\n this.internalSpoiled = true;\n this.internalAnswerIds = [];\n return;\n }\n\n if (poll) {\n if (answers.some((a) => !poll.answers.some((pa) => pa.id === a))) {\n this.internalSpoiled = true;\n this.internalAnswerIds = [];\n return;\n }\n\n answers = answers.slice(0, poll.maxSelections);\n }\n\n this.internalAnswerIds = answers;\n this.internalSpoiled = false;\n }\n\n public isEquivalentTo(primaryEventType: ExtensibleEventType): boolean {\n return isEventTypeSame(primaryEventType, M_POLL_RESPONSE);\n }\n\n public serialize(): IPartialEvent<object> {\n return {\n type: M_POLL_RESPONSE.name,\n content: {\n \"m.relates_to\": {\n rel_type: REFERENCE_RELATION.name,\n event_id: this.pollEventId,\n },\n [M_POLL_RESPONSE.name]: {\n answers: this.spoiled ? undefined : this.answerIds,\n },\n },\n };\n }\n\n /**\n * Creates a new PollResponseEvent from a set of answers. To spoil the vote, pass an empty\n * answers array.\n * @param answers - The user's answers. Should be valid from a poll's answer IDs.\n * @param pollEventId - The poll start event ID.\n * @returns The representative poll response event.\n */\n public static from(answers: string[], pollEventId: string): PollResponseEvent {\n return new PollResponseEvent({\n type: M_POLL_RESPONSE.name,\n content: {\n \"m.relates_to\": {\n rel_type: REFERENCE_RELATION.name,\n event_id: pollEventId,\n },\n [M_POLL_RESPONSE.name]: {\n answers: answers,\n },\n },\n });\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,sBAAsB;AACtD,SAASC,eAAe,QAAiE,oBAAoB;AAC7G,SAGIC,eAAe,EACfC,kBAAkB,QACf,gCAAgC;AACvC,SAASC,iBAAiB,QAAQ,wBAAwB;AAG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