@jeongsu816/matrix-bot-sdk 0.0.0-stage → 0.8.1
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/LICENSE +21 -0
- package/README.md +50 -2
- package/lib/AdminApis.d.ts +52 -0
- package/lib/AdminApis.js +29 -0
- package/lib/AdminApis.js.map +1 -0
- package/lib/DMs.d.ts +48 -0
- package/lib/DMs.js +160 -0
- package/lib/DMs.js.map +1 -0
- package/lib/IFilter.d.ts +7 -0
- package/lib/IFilter.js +3 -0
- package/lib/IFilter.js.map +1 -0
- package/lib/MatrixAuth.d.ts +45 -0
- package/lib/MatrixAuth.js +125 -0
- package/lib/MatrixAuth.js.map +1 -0
- package/lib/MatrixClient.d.ts +834 -0
- package/lib/MatrixClient.js +2268 -0
- package/lib/MatrixClient.js.map +1 -0
- package/lib/PantalaimonClient.d.ts +42 -0
- package/lib/PantalaimonClient.js +44 -0
- package/lib/PantalaimonClient.js.map +1 -0
- package/lib/SynapseAdminApis.d.ts +350 -0
- package/lib/SynapseAdminApis.js +244 -0
- package/lib/SynapseAdminApis.js.map +1 -0
- package/lib/SynchronousMatrixClient.d.ts +82 -0
- package/lib/SynchronousMatrixClient.js +130 -0
- package/lib/SynchronousMatrixClient.js.map +1 -0
- package/lib/UnstableApis.d.ts +43 -0
- package/lib/UnstableApis.js +74 -0
- package/lib/UnstableApis.js.map +1 -0
- package/lib/appservice/Appservice.d.ts +328 -0
- package/lib/appservice/Appservice.js +803 -0
- package/lib/appservice/Appservice.js.map +1 -0
- package/lib/appservice/Intent.d.ts +113 -0
- package/lib/appservice/Intent.js +363 -0
- package/lib/appservice/Intent.js.map +1 -0
- package/lib/appservice/MatrixBridge.d.ts +85 -0
- package/lib/appservice/MatrixBridge.js +111 -0
- package/lib/appservice/MatrixBridge.js.map +1 -0
- package/lib/appservice/UnstableAppserviceApis.d.ts +41 -0
- package/lib/appservice/UnstableAppserviceApis.js +62 -0
- package/lib/appservice/UnstableAppserviceApis.js.map +1 -0
- package/lib/appservice/http_responses.d.ts +77 -0
- package/lib/appservice/http_responses.js +3 -0
- package/lib/appservice/http_responses.js.map +1 -0
- package/lib/b64.d.ts +42 -0
- package/lib/b64.js +68 -0
- package/lib/b64.js.map +1 -0
- package/lib/e2ee/CrossSigningBootstrap.d.ts +73 -0
- package/lib/e2ee/CrossSigningBootstrap.js +86 -0
- package/lib/e2ee/CrossSigningBootstrap.js.map +1 -0
- package/lib/e2ee/CryptoClient.d.ts +163 -0
- package/lib/e2ee/CryptoClient.js +382 -0
- package/lib/e2ee/CryptoClient.js.map +1 -0
- package/lib/e2ee/ICryptoRoomInformation.d.ts +8 -0
- package/lib/e2ee/ICryptoRoomInformation.js +3 -0
- package/lib/e2ee/ICryptoRoomInformation.js.map +1 -0
- package/lib/e2ee/RoomTracker.d.ts +41 -0
- package/lib/e2ee/RoomTracker.js +96 -0
- package/lib/e2ee/RoomTracker.js.map +1 -0
- package/lib/e2ee/RustEngine.d.ts +149 -0
- package/lib/e2ee/RustEngine.js +467 -0
- package/lib/e2ee/RustEngine.js.map +1 -0
- package/lib/e2ee/decorators.d.ts +10 -0
- package/lib/e2ee/decorators.js +37 -0
- package/lib/e2ee/decorators.js.map +1 -0
- package/lib/helpers/MatrixEntity.d.ts +37 -0
- package/lib/helpers/MatrixEntity.js +67 -0
- package/lib/helpers/MatrixEntity.js.map +1 -0
- package/lib/helpers/MatrixGlob.d.ts +22 -0
- package/lib/helpers/MatrixGlob.js +35 -0
- package/lib/helpers/MatrixGlob.js.map +1 -0
- package/lib/helpers/MentionPill.d.ts +40 -0
- package/lib/helpers/MentionPill.js +91 -0
- package/lib/helpers/MentionPill.js.map +1 -0
- package/lib/helpers/Permalinks.d.ts +58 -0
- package/lib/helpers/Permalinks.js +73 -0
- package/lib/helpers/Permalinks.js.map +1 -0
- package/lib/helpers/ProfileCache.d.ts +48 -0
- package/lib/helpers/ProfileCache.js +114 -0
- package/lib/helpers/ProfileCache.js.map +1 -0
- package/lib/helpers/RichReply.d.ts +17 -0
- package/lib/helpers/RichReply.js +47 -0
- package/lib/helpers/RichReply.js.map +1 -0
- package/lib/helpers/UnpaddedBase64.d.ts +31 -0
- package/lib/helpers/UnpaddedBase64.js +45 -0
- package/lib/helpers/UnpaddedBase64.js.map +1 -0
- package/lib/http.d.ts +17 -0
- package/lib/http.js +147 -0
- package/lib/http.js.map +1 -0
- package/lib/identity/IdentityClient.d.ts +93 -0
- package/lib/identity/IdentityClient.js +248 -0
- package/lib/identity/IdentityClient.js.map +1 -0
- package/lib/index.d.ts +91 -0
- package/lib/index.js +125 -0
- package/lib/index.js.map +1 -0
- package/lib/logging/ConsoleLogger.d.ts +12 -0
- package/lib/logging/ConsoleLogger.js +28 -0
- package/lib/logging/ConsoleLogger.js.map +1 -0
- package/lib/logging/ILogger.d.ts +36 -0
- package/lib/logging/ILogger.js +3 -0
- package/lib/logging/ILogger.js.map +1 -0
- package/lib/logging/LogService.d.ts +100 -0
- package/lib/logging/LogService.js +169 -0
- package/lib/logging/LogService.js.map +1 -0
- package/lib/logging/RichConsoleLogger.d.ts +20 -0
- package/lib/logging/RichConsoleLogger.js +41 -0
- package/lib/logging/RichConsoleLogger.js.map +1 -0
- package/lib/metrics/IMetricListener.d.ts +52 -0
- package/lib/metrics/IMetricListener.js +3 -0
- package/lib/metrics/IMetricListener.js.map +1 -0
- package/lib/metrics/Metrics.d.ts +66 -0
- package/lib/metrics/Metrics.js +128 -0
- package/lib/metrics/Metrics.js.map +1 -0
- package/lib/metrics/contexts.d.ts +51 -0
- package/lib/metrics/contexts.js +3 -0
- package/lib/metrics/contexts.js.map +1 -0
- package/lib/metrics/decorators.d.ts +15 -0
- package/lib/metrics/decorators.js +92 -0
- package/lib/metrics/decorators.js.map +1 -0
- package/lib/metrics/names.d.ts +45 -0
- package/lib/metrics/names.js +49 -0
- package/lib/metrics/names.js.map +1 -0
- package/lib/mixins/AutojoinRoomsMixin.d.ts +10 -0
- package/lib/mixins/AutojoinRoomsMixin.js +25 -0
- package/lib/mixins/AutojoinRoomsMixin.js.map +1 -0
- package/lib/mixins/AutojoinUpgradedRoomsMixin.d.ts +10 -0
- package/lib/mixins/AutojoinUpgradedRoomsMixin.js +40 -0
- package/lib/mixins/AutojoinUpgradedRoomsMixin.js.map +1 -0
- package/lib/models/Account.d.ts +8 -0
- package/lib/models/Account.js +3 -0
- package/lib/models/Account.js.map +1 -0
- package/lib/models/CreateRoom.d.ts +125 -0
- package/lib/models/CreateRoom.js +3 -0
- package/lib/models/CreateRoom.js.map +1 -0
- package/lib/models/Crypto.d.ts +167 -0
- package/lib/models/Crypto.js +31 -0
- package/lib/models/Crypto.js.map +1 -0
- package/lib/models/EventContext.d.ts +19 -0
- package/lib/models/EventContext.js +3 -0
- package/lib/models/EventContext.js.map +1 -0
- package/lib/models/IdentityServerModels.d.ts +20 -0
- package/lib/models/IdentityServerModels.js +3 -0
- package/lib/models/IdentityServerModels.js.map +1 -0
- package/lib/models/MSC2176.d.ts +42 -0
- package/lib/models/MSC2176.js +3 -0
- package/lib/models/MSC2176.js.map +1 -0
- package/lib/models/MatrixError.d.ts +38 -0
- package/lib/models/MatrixError.js +30 -0
- package/lib/models/MatrixError.js.map +1 -0
- package/lib/models/MatrixProfile.d.ts +43 -0
- package/lib/models/MatrixProfile.js +43 -0
- package/lib/models/MatrixProfile.js.map +1 -0
- package/lib/models/OpenIDConnect.d.ts +10 -0
- package/lib/models/OpenIDConnect.js +3 -0
- package/lib/models/OpenIDConnect.js.map +1 -0
- package/lib/models/Policies.d.ts +25 -0
- package/lib/models/Policies.js +3 -0
- package/lib/models/Policies.js.map +1 -0
- package/lib/models/PowerLevelAction.d.ts +27 -0
- package/lib/models/PowerLevelAction.js +32 -0
- package/lib/models/PowerLevelAction.js.map +1 -0
- package/lib/models/PowerLevelBounds.d.ts +15 -0
- package/lib/models/PowerLevelBounds.js +3 -0
- package/lib/models/PowerLevelBounds.js.map +1 -0
- package/lib/models/Presence.d.ts +25 -0
- package/lib/models/Presence.js +38 -0
- package/lib/models/Presence.js.map +1 -0
- package/lib/models/ServerVersions.d.ts +8 -0
- package/lib/models/ServerVersions.js +3 -0
- package/lib/models/ServerVersions.js.map +1 -0
- package/lib/models/Spaces.d.ts +116 -0
- package/lib/models/Spaces.js +91 -0
- package/lib/models/Spaces.js.map +1 -0
- package/lib/models/Threepid.d.ts +8 -0
- package/lib/models/Threepid.js +3 -0
- package/lib/models/Threepid.js.map +1 -0
- package/lib/models/events/AliasesEvent.d.ts +27 -0
- package/lib/models/events/AliasesEvent.js +27 -0
- package/lib/models/events/AliasesEvent.js.map +1 -0
- package/lib/models/events/CanonicalAliasEvent.d.ts +23 -0
- package/lib/models/events/CanonicalAliasEvent.js +21 -0
- package/lib/models/events/CanonicalAliasEvent.js.map +1 -0
- package/lib/models/events/CreateEvent.d.ts +63 -0
- package/lib/models/events/CreateEvent.js +33 -0
- package/lib/models/events/CreateEvent.js.map +1 -0
- package/lib/models/events/EncryptedRoomEvent.d.ts +42 -0
- package/lib/models/events/EncryptedRoomEvent.js +28 -0
- package/lib/models/events/EncryptedRoomEvent.js.map +1 -0
- package/lib/models/events/EncryptionEvent.d.ts +47 -0
- package/lib/models/events/EncryptionEvent.js +42 -0
- package/lib/models/events/EncryptionEvent.js.map +1 -0
- package/lib/models/events/Event.d.ts +26 -0
- package/lib/models/events/Event.js +40 -0
- package/lib/models/events/Event.js.map +1 -0
- package/lib/models/events/EventKind.d.ts +15 -0
- package/lib/models/events/EventKind.js +20 -0
- package/lib/models/events/EventKind.js.map +1 -0
- package/lib/models/events/InvalidEventError.d.ts +14 -0
- package/lib/models/events/InvalidEventError.js +24 -0
- package/lib/models/events/InvalidEventError.js.map +1 -0
- package/lib/models/events/JoinRulesEvent.d.ts +29 -0
- package/lib/models/events/JoinRulesEvent.js +21 -0
- package/lib/models/events/JoinRulesEvent.js.map +1 -0
- package/lib/models/events/MembershipEvent.d.ts +54 -0
- package/lib/models/events/MembershipEvent.js +49 -0
- package/lib/models/events/MembershipEvent.js.map +1 -0
- package/lib/models/events/MessageEvent.d.ts +233 -0
- package/lib/models/events/MessageEvent.js +49 -0
- package/lib/models/events/MessageEvent.js.map +1 -0
- package/lib/models/events/PinnedEventsEvent.d.ts +23 -0
- package/lib/models/events/PinnedEventsEvent.js +21 -0
- package/lib/models/events/PinnedEventsEvent.js.map +1 -0
- package/lib/models/events/PowerLevelsEvent.d.ts +96 -0
- package/lib/models/events/PowerLevelsEvent.js +70 -0
- package/lib/models/events/PowerLevelsEvent.js.map +1 -0
- package/lib/models/events/PresenceEvent.d.ts +56 -0
- package/lib/models/events/PresenceEvent.js +21 -0
- package/lib/models/events/PresenceEvent.js.map +1 -0
- package/lib/models/events/RedactionEvent.d.ts +28 -0
- package/lib/models/events/RedactionEvent.js +36 -0
- package/lib/models/events/RedactionEvent.js.map +1 -0
- package/lib/models/events/RoomAvatarEvent.d.ts +28 -0
- package/lib/models/events/RoomAvatarEvent.js +21 -0
- package/lib/models/events/RoomAvatarEvent.js.map +1 -0
- package/lib/models/events/RoomEvent.d.ts +58 -0
- package/lib/models/events/RoomEvent.js +57 -0
- package/lib/models/events/RoomEvent.js.map +1 -0
- package/lib/models/events/RoomNameEvent.d.ts +20 -0
- package/lib/models/events/RoomNameEvent.js +21 -0
- package/lib/models/events/RoomNameEvent.js.map +1 -0
- package/lib/models/events/RoomTopicEvent.d.ts +20 -0
- package/lib/models/events/RoomTopicEvent.js +21 -0
- package/lib/models/events/RoomTopicEvent.js.map +1 -0
- package/lib/models/events/SpaceChildEvent.d.ts +53 -0
- package/lib/models/events/SpaceChildEvent.js +49 -0
- package/lib/models/events/SpaceChildEvent.js.map +1 -0
- package/lib/models/events/converter.d.ts +8 -0
- package/lib/models/events/converter.js +50 -0
- package/lib/models/events/converter.js.map +1 -0
- package/lib/models/unstable/MediaInfo.d.ts +16 -0
- package/lib/models/unstable/MediaInfo.js +3 -0
- package/lib/models/unstable/MediaInfo.js.map +1 -0
- package/lib/preprocessors/IPreprocessor.d.ts +22 -0
- package/lib/preprocessors/IPreprocessor.js +3 -0
- package/lib/preprocessors/IPreprocessor.js.map +1 -0
- package/lib/preprocessors/RichRepliesPreprocessor.d.ts +67 -0
- package/lib/preprocessors/RichRepliesPreprocessor.js +112 -0
- package/lib/preprocessors/RichRepliesPreprocessor.js.map +1 -0
- package/lib/request.d.ts +13 -0
- package/lib/request.js +23 -0
- package/lib/request.js.map +1 -0
- package/lib/simple-validation.d.ts +10 -0
- package/lib/simple-validation.js +30 -0
- package/lib/simple-validation.js.map +1 -0
- package/lib/storage/IAppserviceStorageProvider.d.ts +48 -0
- package/lib/storage/IAppserviceStorageProvider.js +3 -0
- package/lib/storage/IAppserviceStorageProvider.js.map +1 -0
- package/lib/storage/ICryptoStorageProvider.d.ts +32 -0
- package/lib/storage/ICryptoStorageProvider.js +3 -0
- package/lib/storage/ICryptoStorageProvider.js.map +1 -0
- package/lib/storage/IStorageProvider.d.ts +47 -0
- package/lib/storage/IStorageProvider.js +3 -0
- package/lib/storage/IStorageProvider.js.map +1 -0
- package/lib/storage/MemoryStorageProvider.d.ts +26 -0
- package/lib/storage/MemoryStorageProvider.js +55 -0
- package/lib/storage/MemoryStorageProvider.js.map +1 -0
- package/lib/storage/RustSdkCryptoStorageProvider.d.ts +38 -0
- package/lib/storage/RustSdkCryptoStorageProvider.js +69 -0
- package/lib/storage/RustSdkCryptoStorageProvider.js.map +1 -0
- package/lib/storage/SimpleFsStorageProvider.d.ts +31 -0
- package/lib/storage/SimpleFsStorageProvider.js +122 -0
- package/lib/storage/SimpleFsStorageProvider.js.map +1 -0
- package/lib/storage/SimplePostgresStorageProvider.d.ts +32 -0
- package/lib/storage/SimplePostgresStorageProvider.js +148 -0
- package/lib/storage/SimplePostgresStorageProvider.js.map +1 -0
- package/lib/strategies/AppserviceJoinRoomStrategy.d.ts +14 -0
- package/lib/strategies/AppserviceJoinRoomStrategy.js +54 -0
- package/lib/strategies/AppserviceJoinRoomStrategy.js.map +1 -0
- package/lib/strategies/JoinRoomStrategy.d.ts +11 -0
- package/lib/strategies/JoinRoomStrategy.js +44 -0
- package/lib/strategies/JoinRoomStrategy.js.map +1 -0
- package/package.json +136 -4
- package/src/AdminApis.ts +60 -0
- package/src/DMs.ts +164 -0
- package/src/IFilter.ts +7 -0
- package/src/MatrixAuth.ts +129 -0
- package/src/MatrixClient.ts +2046 -0
- package/src/PantalaimonClient.ts +62 -0
- package/src/SynapseAdminApis.ts +482 -0
- package/src/SynchronousMatrixClient.ts +129 -0
- package/src/UnstableApis.ts +75 -0
- package/src/appservice/Appservice.ts +1089 -0
- package/src/appservice/Intent.ts +342 -0
- package/src/appservice/MatrixBridge.ts +139 -0
- package/src/appservice/UnstableAppserviceApis.ts +63 -0
- package/src/appservice/http_responses.ts +77 -0
- package/src/b64.ts +63 -0
- package/src/e2ee/CrossSigningBootstrap.ts +141 -0
- package/src/e2ee/CryptoClient.ts +378 -0
- package/src/e2ee/ICryptoRoomInformation.ts +9 -0
- package/src/e2ee/RoomTracker.ts +99 -0
- package/src/e2ee/RustEngine.ts +580 -0
- package/src/e2ee/decorators.ts +38 -0
- package/src/helpers/MatrixEntity.ts +65 -0
- package/src/helpers/MatrixGlob.ts +38 -0
- package/src/helpers/MentionPill.ts +95 -0
- package/src/helpers/Permalinks.ts +101 -0
- package/src/helpers/ProfileCache.ts +119 -0
- package/src/helpers/RichReply.ts +46 -0
- package/src/helpers/UnpaddedBase64.ts +44 -0
- package/src/http.ts +166 -0
- package/src/identity/IdentityClient.ts +225 -0
- package/src/index.ts +125 -0
- package/src/logging/ConsoleLogger.ts +31 -0
- package/src/logging/ILogger.ts +40 -0
- package/src/logging/LogService.ts +167 -0
- package/src/logging/RichConsoleLogger.ts +70 -0
- package/src/metrics/IMetricListener.ts +57 -0
- package/src/metrics/Metrics.ts +134 -0
- package/src/metrics/contexts.ts +56 -0
- package/src/metrics/decorators.ts +94 -0
- package/src/metrics/names.ts +53 -0
- package/src/mixins/AutojoinRoomsMixin.ts +24 -0
- package/src/mixins/AutojoinUpgradedRoomsMixin.ts +37 -0
- package/src/models/Account.ts +8 -0
- package/src/models/CreateRoom.ts +144 -0
- package/src/models/Crypto.ts +188 -0
- package/src/models/EventContext.ts +23 -0
- package/src/models/IdentityServerModels.ts +18 -0
- package/src/models/MSC2176.ts +47 -0
- package/src/models/MatrixError.ts +39 -0
- package/src/models/MatrixProfile.ts +55 -0
- package/src/models/OpenIDConnect.ts +10 -0
- package/src/models/Policies.ts +28 -0
- package/src/models/PowerLevelAction.ts +31 -0
- package/src/models/PowerLevelBounds.ts +16 -0
- package/src/models/Presence.ts +38 -0
- package/src/models/ServerVersions.ts +8 -0
- package/src/models/Spaces.ts +167 -0
- package/src/models/Threepid.ts +8 -0
- package/src/models/events/AliasesEvent.ts +37 -0
- package/src/models/events/CanonicalAliasEvent.ts +30 -0
- package/src/models/events/CreateEvent.ts +82 -0
- package/src/models/events/EncryptedRoomEvent.ts +58 -0
- package/src/models/events/EncryptionEvent.ts +63 -0
- package/src/models/events/Event.ts +38 -0
- package/src/models/events/EventKind.ts +16 -0
- package/src/models/events/InvalidEventError.ts +19 -0
- package/src/models/events/JoinRulesEvent.ts +37 -0
- package/src/models/events/MembershipEvent.ts +77 -0
- package/src/models/events/MessageEvent.ts +292 -0
- package/src/models/events/PinnedEventsEvent.ts +30 -0
- package/src/models/events/PowerLevelsEvent.ts +135 -0
- package/src/models/events/PresenceEvent.ts +69 -0
- package/src/models/events/RedactionEvent.ts +44 -0
- package/src/models/events/RoomAvatarEvent.ts +36 -0
- package/src/models/events/RoomEvent.ts +83 -0
- package/src/models/events/RoomNameEvent.ts +27 -0
- package/src/models/events/RoomTopicEvent.ts +27 -0
- package/src/models/events/SpaceChildEvent.ts +74 -0
- package/src/models/events/_MissingEvents.md +35 -0
- package/src/models/events/converter.ts +47 -0
- package/src/models/unstable/MediaInfo.ts +16 -0
- package/src/preprocessors/IPreprocessor.ts +24 -0
- package/src/preprocessors/RichRepliesPreprocessor.ts +159 -0
- package/src/request.ts +21 -0
- package/src/simple-validation.ts +30 -0
- package/src/storage/IAppserviceStorageProvider.ts +54 -0
- package/src/storage/ICryptoStorageProvider.ts +36 -0
- package/src/storage/IStorageProvider.ts +53 -0
- package/src/storage/MemoryStorageProvider.ts +65 -0
- package/src/storage/RustSdkCryptoStorageProvider.ts +81 -0
- package/src/storage/SimpleFsStorageProvider.ts +142 -0
- package/src/storage/SimplePostgresStorageProvider.ts +168 -0
- package/src/strategies/AppserviceJoinRoomStrategy.ts +47 -0
- package/src/strategies/JoinRoomStrategy.ts +45 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a common Matrix glob. This is commonly used
|
|
3
|
+
* for server ACLs and similar functions.
|
|
4
|
+
* @category Utilities
|
|
5
|
+
*/
|
|
6
|
+
export declare class MatrixGlob {
|
|
7
|
+
/**
|
|
8
|
+
* The regular expression which represents this glob.
|
|
9
|
+
*/
|
|
10
|
+
readonly regex: RegExp;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Matrix Glob
|
|
13
|
+
* @param {string} glob The glob to convert. Eg: "*.example.org"
|
|
14
|
+
*/
|
|
15
|
+
constructor(glob: string);
|
|
16
|
+
/**
|
|
17
|
+
* Tests the glob against a value, returning true if it matches.
|
|
18
|
+
* @param {string} val The value to test.
|
|
19
|
+
* @returns {boolean} True if the value matches the glob, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
test(val: string): boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MatrixGlob = void 0;
|
|
4
|
+
const globToRegexp = require("glob-to-regexp");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a common Matrix glob. This is commonly used
|
|
7
|
+
* for server ACLs and similar functions.
|
|
8
|
+
* @category Utilities
|
|
9
|
+
*/
|
|
10
|
+
class MatrixGlob {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Matrix Glob
|
|
13
|
+
* @param {string} glob The glob to convert. Eg: "*.example.org"
|
|
14
|
+
*/
|
|
15
|
+
constructor(glob) {
|
|
16
|
+
const globRegex = globToRegexp(glob, {
|
|
17
|
+
extended: false,
|
|
18
|
+
globstar: false,
|
|
19
|
+
});
|
|
20
|
+
// We need to convert `?` manually because globToRegexp's extended mode
|
|
21
|
+
// does more than we want it to.
|
|
22
|
+
const replaced = globRegex.toString().replace(/\\\?/g, ".");
|
|
23
|
+
this.regex = new RegExp(replaced.substring(1, replaced.length - 1));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Tests the glob against a value, returning true if it matches.
|
|
27
|
+
* @param {string} val The value to test.
|
|
28
|
+
* @returns {boolean} True if the value matches the glob, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
test(val) {
|
|
31
|
+
return this.regex.test(val);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.MatrixGlob = MatrixGlob;
|
|
35
|
+
//# sourceMappingURL=MatrixGlob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatrixGlob.js","sourceRoot":"","sources":["../../src/helpers/MatrixGlob.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAE/C;;;;GAIG;AACH,MAAa,UAAU;IAMnB;;;OAGG;IACH,YAAY,IAAY;QACpB,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE;YACjC,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,KAAK;SAClB,CAAC,CAAC;QAEH,uEAAuE;QACvE,gCAAgC;QAChC,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC5D,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;CACJ;AA9BD,gCA8BC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MatrixClient } from "../MatrixClient";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a system for generating a mention pill for an entity.
|
|
4
|
+
* @category Utilities
|
|
5
|
+
*/
|
|
6
|
+
export declare class MentionPill {
|
|
7
|
+
private entityPermalink;
|
|
8
|
+
private displayName;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* The HTML component of the mention.
|
|
12
|
+
*/
|
|
13
|
+
get html(): string;
|
|
14
|
+
/**
|
|
15
|
+
* The plain text component of the mention.
|
|
16
|
+
*/
|
|
17
|
+
get text(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new mention for a user in an optional room.
|
|
20
|
+
* @param {string} userId The user ID the mention is for.
|
|
21
|
+
* @param {String} inRoomId Optional room ID the user is being mentioned in, for the aesthetics of the mention.
|
|
22
|
+
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
|
23
|
+
* @returns {Promise<MentionPill>} Resolves to the user's mention.
|
|
24
|
+
*/
|
|
25
|
+
static forUser(userId: string, inRoomId?: string, client?: MatrixClient): Promise<MentionPill>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new mention for a room (not @room, but the room itself to be linked).
|
|
28
|
+
* @param {string} roomIdOrAlias The room ID or alias to mention.
|
|
29
|
+
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
|
30
|
+
* @returns {Promise<MentionPill>} Resolves to the room's mention.
|
|
31
|
+
*/
|
|
32
|
+
static forRoom(roomIdOrAlias: string, client?: MatrixClient): Promise<MentionPill>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a mention from static information.
|
|
35
|
+
* @param {string} userId The user ID the mention is for.
|
|
36
|
+
* @param {string} displayName The user's display name.
|
|
37
|
+
* @returns {MentionPill} The mention for the user.
|
|
38
|
+
*/
|
|
39
|
+
static withDisplayName(userId: string, displayName: string): MentionPill;
|
|
40
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MentionPill = void 0;
|
|
4
|
+
const Permalinks_1 = require("./Permalinks");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
/**
|
|
7
|
+
* Represents a system for generating a mention pill for an entity.
|
|
8
|
+
* @category Utilities
|
|
9
|
+
*/
|
|
10
|
+
class MentionPill {
|
|
11
|
+
constructor(entityPermalink, displayName) {
|
|
12
|
+
this.entityPermalink = entityPermalink;
|
|
13
|
+
this.displayName = displayName;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The HTML component of the mention.
|
|
17
|
+
*/
|
|
18
|
+
get html() {
|
|
19
|
+
return `<a href="${this.entityPermalink}">${this.displayName}</a>`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The plain text component of the mention.
|
|
23
|
+
*/
|
|
24
|
+
get text() {
|
|
25
|
+
return this.displayName;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new mention for a user in an optional room.
|
|
29
|
+
* @param {string} userId The user ID the mention is for.
|
|
30
|
+
* @param {String} inRoomId Optional room ID the user is being mentioned in, for the aesthetics of the mention.
|
|
31
|
+
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
|
32
|
+
* @returns {Promise<MentionPill>} Resolves to the user's mention.
|
|
33
|
+
*/
|
|
34
|
+
static async forUser(userId, inRoomId = null, client = null) {
|
|
35
|
+
const permalink = Permalinks_1.Permalinks.forUser(userId);
|
|
36
|
+
let displayName = userId;
|
|
37
|
+
try {
|
|
38
|
+
if (client) {
|
|
39
|
+
let profile = null;
|
|
40
|
+
if (inRoomId) {
|
|
41
|
+
profile = await client.getRoomStateEvent(inRoomId, "m.room.member", userId);
|
|
42
|
+
}
|
|
43
|
+
if (!profile) {
|
|
44
|
+
profile = await client.getUserProfile(userId);
|
|
45
|
+
}
|
|
46
|
+
if (profile['displayname']) {
|
|
47
|
+
displayName = profile['displayname'];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
__1.LogService.warn("MentionPill", "Error getting profile", (0, __1.extractRequestError)(e));
|
|
53
|
+
}
|
|
54
|
+
return new MentionPill(permalink, displayName);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new mention for a room (not @room, but the room itself to be linked).
|
|
58
|
+
* @param {string} roomIdOrAlias The room ID or alias to mention.
|
|
59
|
+
* @param {MatrixClient} client Optional client for creating a more pleasing mention.
|
|
60
|
+
* @returns {Promise<MentionPill>} Resolves to the room's mention.
|
|
61
|
+
*/
|
|
62
|
+
static async forRoom(roomIdOrAlias, client = null) {
|
|
63
|
+
let permalink = Permalinks_1.Permalinks.forRoom(roomIdOrAlias);
|
|
64
|
+
let displayProp = roomIdOrAlias;
|
|
65
|
+
try {
|
|
66
|
+
if (client) {
|
|
67
|
+
const roomId = await client.resolveRoom(roomIdOrAlias);
|
|
68
|
+
const canonicalAlias = await client.getRoomStateEvent(roomId, "m.room.canonical_alias", "");
|
|
69
|
+
if (canonicalAlias?.alias) {
|
|
70
|
+
displayProp = canonicalAlias.alias;
|
|
71
|
+
permalink = Permalinks_1.Permalinks.forRoom(displayProp);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
__1.LogService.warn("MentionPill", "Error getting room information", (0, __1.extractRequestError)(e));
|
|
77
|
+
}
|
|
78
|
+
return new MentionPill(permalink, displayProp);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a mention from static information.
|
|
82
|
+
* @param {string} userId The user ID the mention is for.
|
|
83
|
+
* @param {string} displayName The user's display name.
|
|
84
|
+
* @returns {MentionPill} The mention for the user.
|
|
85
|
+
*/
|
|
86
|
+
static withDisplayName(userId, displayName) {
|
|
87
|
+
return new MentionPill(Permalinks_1.Permalinks.forUser(userId), displayName || userId);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.MentionPill = MentionPill;
|
|
91
|
+
//# sourceMappingURL=MentionPill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MentionPill.js","sourceRoot":"","sources":["../../src/helpers/MentionPill.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAC1C,0BAAqD;AAErD;;;GAGG;AACH,MAAa,WAAW;IACpB,YAA4B,eAAuB,EAAU,WAAmB;QAApD,oBAAe,GAAf,eAAe,CAAQ;QAAU,gBAAW,GAAX,WAAW,CAAQ;IAChF,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,YAAY,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,WAAmB,IAAI,EAAE,SAAuB,IAAI;QAC5F,MAAM,SAAS,GAAG,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAE7C,IAAI,WAAW,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACT,IAAI,OAAO,GAAG,IAAI,CAAC;gBAEnB,IAAI,QAAQ,EAAE,CAAC;oBACX,OAAO,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;gBAChF,CAAC;gBACD,IAAI,CAAC,OAAO,EAAE,CAAC;oBACX,OAAO,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;gBAClD,CAAC;gBAED,IAAI,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;oBACzB,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;gBACzC,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,cAAU,CAAC,IAAI,CAAC,aAAa,EAAE,uBAAuB,EAAE,IAAA,uBAAmB,EAAC,CAAC,CAAC,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,aAAqB,EAAE,SAAuB,IAAI;QAC1E,IAAI,SAAS,GAAG,uBAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAClD,IAAI,WAAW,GAAG,aAAa,CAAC;QAEhC,IAAI,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACT,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;gBACvD,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,wBAAwB,EAAE,EAAE,CAAC,CAAC;gBAC5F,IAAI,cAAc,EAAE,KAAK,EAAE,CAAC;oBACxB,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC;oBACnC,SAAS,GAAG,uBAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAChD,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,cAAU,CAAC,IAAI,CAAC,aAAa,EAAE,gCAAgC,EAAE,IAAA,uBAAmB,EAAC,CAAC,CAAC,CAAC,CAAC;QAC7F,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,WAAmB;QAC7D,OAAO,IAAI,WAAW,CAAC,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,MAAM,CAAC,CAAC;IAC9E,CAAC;CACJ;AAtFD,kCAsFC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of a permalink.
|
|
3
|
+
* @see Permalinks
|
|
4
|
+
* @category Utilities
|
|
5
|
+
*/
|
|
6
|
+
export interface PermalinkParts {
|
|
7
|
+
/**
|
|
8
|
+
* The room ID or alias the permalink references. May be undefined.
|
|
9
|
+
*/
|
|
10
|
+
roomIdOrAlias: string;
|
|
11
|
+
/**
|
|
12
|
+
* The user ID the permalink references. May be undefined.
|
|
13
|
+
*/
|
|
14
|
+
userId: string;
|
|
15
|
+
/**
|
|
16
|
+
* The event ID the permalink references. May be undefined.
|
|
17
|
+
*/
|
|
18
|
+
eventId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The servers the permalink is routed through. May be undefined or empty.
|
|
21
|
+
*/
|
|
22
|
+
viaServers: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Functions for handling permalinks
|
|
26
|
+
* @category Utilities
|
|
27
|
+
*/
|
|
28
|
+
export declare class Permalinks {
|
|
29
|
+
private constructor();
|
|
30
|
+
private static encodeViaArgs;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a room permalink.
|
|
33
|
+
* @param {string} roomIdOrAlias The room ID or alias to create a permalink for.
|
|
34
|
+
* @param {string[]} viaServers The servers to route the permalink through.
|
|
35
|
+
* @returns {string} A room permalink.
|
|
36
|
+
*/
|
|
37
|
+
static forRoom(roomIdOrAlias: string, viaServers?: string[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a user permalink.
|
|
40
|
+
* @param {string} userId The user ID to create a permalink for.
|
|
41
|
+
* @returns {string} A user permalink.
|
|
42
|
+
*/
|
|
43
|
+
static forUser(userId: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an event permalink.
|
|
46
|
+
* @param {string} roomIdOrAlias The room ID or alias to create a permalink in.
|
|
47
|
+
* @param {string} eventId The event ID to reference in the permalink.
|
|
48
|
+
* @param {string[]} viaServers The servers to route the permalink through.
|
|
49
|
+
* @returns {string} An event permalink.
|
|
50
|
+
*/
|
|
51
|
+
static forEvent(roomIdOrAlias: string, eventId: string, viaServers?: string[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* Parses a permalink URL into usable parts.
|
|
54
|
+
* @param {string} matrixTo The matrix.to URL to parse.
|
|
55
|
+
* @returns {PermalinkParts} The parts of the permalink.
|
|
56
|
+
*/
|
|
57
|
+
static parseUrl(matrixTo: string): PermalinkParts;
|
|
58
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Permalinks = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Functions for handling permalinks
|
|
6
|
+
* @category Utilities
|
|
7
|
+
*/
|
|
8
|
+
class Permalinks {
|
|
9
|
+
constructor() {
|
|
10
|
+
}
|
|
11
|
+
// TODO: Encode permalinks
|
|
12
|
+
static encodeViaArgs(servers) {
|
|
13
|
+
if (!servers || !servers.length)
|
|
14
|
+
return "";
|
|
15
|
+
return `?via=${servers.join("&via=")}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a room permalink.
|
|
19
|
+
* @param {string} roomIdOrAlias The room ID or alias to create a permalink for.
|
|
20
|
+
* @param {string[]} viaServers The servers to route the permalink through.
|
|
21
|
+
* @returns {string} A room permalink.
|
|
22
|
+
*/
|
|
23
|
+
static forRoom(roomIdOrAlias, viaServers = []) {
|
|
24
|
+
return `https://matrix.to/#/${roomIdOrAlias}${Permalinks.encodeViaArgs(viaServers)}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a user permalink.
|
|
28
|
+
* @param {string} userId The user ID to create a permalink for.
|
|
29
|
+
* @returns {string} A user permalink.
|
|
30
|
+
*/
|
|
31
|
+
static forUser(userId) {
|
|
32
|
+
return `https://matrix.to/#/${userId}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an event permalink.
|
|
36
|
+
* @param {string} roomIdOrAlias The room ID or alias to create a permalink in.
|
|
37
|
+
* @param {string} eventId The event ID to reference in the permalink.
|
|
38
|
+
* @param {string[]} viaServers The servers to route the permalink through.
|
|
39
|
+
* @returns {string} An event permalink.
|
|
40
|
+
*/
|
|
41
|
+
static forEvent(roomIdOrAlias, eventId, viaServers = []) {
|
|
42
|
+
return `https://matrix.to/#/${roomIdOrAlias}/${eventId}${Permalinks.encodeViaArgs(viaServers)}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parses a permalink URL into usable parts.
|
|
46
|
+
* @param {string} matrixTo The matrix.to URL to parse.
|
|
47
|
+
* @returns {PermalinkParts} The parts of the permalink.
|
|
48
|
+
*/
|
|
49
|
+
static parseUrl(matrixTo) {
|
|
50
|
+
const matrixToRegexp = /^https:\/\/matrix\.to\/#\/(?<entity>[^/?]+)\/?(?<eventId>[^?]+)?(?<query>\?[^]*)?$/;
|
|
51
|
+
const url = matrixToRegexp.exec(matrixTo)?.groups;
|
|
52
|
+
if (!url) {
|
|
53
|
+
throw new Error("Not a valid matrix.to URL");
|
|
54
|
+
}
|
|
55
|
+
const entity = decodeURIComponent(url.entity);
|
|
56
|
+
if (entity[0] === '@') {
|
|
57
|
+
return { userId: entity, roomIdOrAlias: undefined, eventId: undefined, viaServers: undefined };
|
|
58
|
+
}
|
|
59
|
+
else if (entity[0] === '#' || entity[0] === '!') {
|
|
60
|
+
return {
|
|
61
|
+
userId: undefined,
|
|
62
|
+
roomIdOrAlias: entity,
|
|
63
|
+
eventId: url.eventId && decodeURIComponent(url.eventId),
|
|
64
|
+
viaServers: new URLSearchParams(url.query).getAll('via'),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error("Unexpected entity");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Permalinks = Permalinks;
|
|
73
|
+
//# sourceMappingURL=Permalinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Permalinks.js","sourceRoot":"","sources":["../../src/helpers/Permalinks.ts"],"names":[],"mappings":";;;AA2BA;;;GAGG;AACH,MAAa,UAAU;IACnB;IACA,CAAC;IAED,0BAA0B;IAElB,MAAM,CAAC,aAAa,CAAC,OAAiB;QAC1C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAE3C,OAAO,QAAQ,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,CAAC,aAAqB,EAAE,aAAuB,EAAE;QAClE,OAAO,uBAAuB,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;IACzF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,MAAc;QAChC,OAAO,uBAAuB,MAAM,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAAQ,CAAC,aAAqB,EAAE,OAAe,EAAE,aAAuB,EAAE;QACpF,OAAO,uBAAuB,aAAa,IAAI,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;IACpG,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,QAAgB;QACnC,MAAM,cAAc,GAAG,oFAAoF,CAAC;QAE5G,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClD,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACpB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QACnG,CAAC;aAAM,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAChD,OAAO;gBACH,MAAM,EAAE,SAAS;gBACjB,aAAa,EAAE,MAAM;gBACrB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;gBACvD,UAAU,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3D,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;CACJ;AArED,gCAqEC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MatrixClient, MatrixProfile } from "..";
|
|
2
|
+
import { Appservice } from "../appservice/Appservice";
|
|
3
|
+
/**
|
|
4
|
+
* Functions for avoiding calls to profile endpoints. Useful for bots when
|
|
5
|
+
* people are mentioned often or bridges which need profile information
|
|
6
|
+
* often.
|
|
7
|
+
* @category Utilities
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProfileCache {
|
|
10
|
+
private client;
|
|
11
|
+
private cache;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new profile cache.
|
|
14
|
+
* @param {number} maxEntries The maximum number of entries to cache.
|
|
15
|
+
* @param {number} maxAgeMs The maximum age of an entry in milliseconds.
|
|
16
|
+
* @param {MatrixClient} client The client to use to get profile updates.
|
|
17
|
+
*/
|
|
18
|
+
constructor(maxEntries: number, maxAgeMs: number, client: MatrixClient);
|
|
19
|
+
private getCacheKey;
|
|
20
|
+
/**
|
|
21
|
+
* Watch for profile changes to cached entries with the provided client. The
|
|
22
|
+
* same client will also be used to update the user's profile in the cache.
|
|
23
|
+
* @param {MatrixClient} client The client to watch for profile changes with.
|
|
24
|
+
*/
|
|
25
|
+
watchWithClient(client: MatrixClient): void;
|
|
26
|
+
/**
|
|
27
|
+
* Watch for profile changes to cached entries with the provided application
|
|
28
|
+
* service. The clientFn will be called to get the relevant client for any
|
|
29
|
+
* updates. If the clientFn is null, the appservice's bot user will be used.
|
|
30
|
+
* The clientFn takes two arguments: the user ID being updated and the room ID
|
|
31
|
+
* they are being updated in (shouldn't be null). The return value should be the
|
|
32
|
+
* MatrixClient to use, or null to use the appservice's bot client. The same
|
|
33
|
+
* client will be used to update the user's general profile, if that profile
|
|
34
|
+
* is cached.
|
|
35
|
+
* @param {Appservice} appservice The application service to watch for profile changes with.
|
|
36
|
+
* @param {Function} clientFn The function to use to acquire profile updates with. If null, the appservice's bot client will be used.
|
|
37
|
+
*/
|
|
38
|
+
watchWithAppservice(appservice: Appservice, clientFn?: (userId: string, roomId: string) => MatrixClient): void;
|
|
39
|
+
/**
|
|
40
|
+
* Gets a profile for a user in optional room.
|
|
41
|
+
* @param {string} userId The user ID to get a profile for.
|
|
42
|
+
* @param {string|null} roomId Optional room ID to get a per-room profile for the user.
|
|
43
|
+
* @returns {Promise<MatrixProfile>} Resolves to the user's profile.
|
|
44
|
+
*/
|
|
45
|
+
getUserProfile(userId: string, roomId?: string): Promise<MatrixProfile>;
|
|
46
|
+
private getUserProfileWith;
|
|
47
|
+
private tryUpdateProfile;
|
|
48
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileCache = void 0;
|
|
4
|
+
const LRU = require("lru-cache");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const MembershipEvent_1 = require("../models/events/MembershipEvent");
|
|
7
|
+
/**
|
|
8
|
+
* Functions for avoiding calls to profile endpoints. Useful for bots when
|
|
9
|
+
* people are mentioned often or bridges which need profile information
|
|
10
|
+
* often.
|
|
11
|
+
* @category Utilities
|
|
12
|
+
*/
|
|
13
|
+
class ProfileCache {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new profile cache.
|
|
16
|
+
* @param {number} maxEntries The maximum number of entries to cache.
|
|
17
|
+
* @param {number} maxAgeMs The maximum age of an entry in milliseconds.
|
|
18
|
+
* @param {MatrixClient} client The client to use to get profile updates.
|
|
19
|
+
*/
|
|
20
|
+
constructor(maxEntries, maxAgeMs, client) {
|
|
21
|
+
this.client = client;
|
|
22
|
+
this.cache = new LRU.LRUCache({
|
|
23
|
+
max: maxEntries,
|
|
24
|
+
ttl: maxAgeMs,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getCacheKey(userId, roomId) {
|
|
28
|
+
return `${userId}@${roomId || '<none>'}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Watch for profile changes to cached entries with the provided client. The
|
|
32
|
+
* same client will also be used to update the user's profile in the cache.
|
|
33
|
+
* @param {MatrixClient} client The client to watch for profile changes with.
|
|
34
|
+
*/
|
|
35
|
+
watchWithClient(client) {
|
|
36
|
+
client.on("room.event", async (roomId, event) => {
|
|
37
|
+
if (!event['state_key'] || !event['content'] || event['type'] !== 'm.room.member')
|
|
38
|
+
return;
|
|
39
|
+
await this.tryUpdateProfile(roomId, new MembershipEvent_1.MembershipEvent(event), client);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Watch for profile changes to cached entries with the provided application
|
|
44
|
+
* service. The clientFn will be called to get the relevant client for any
|
|
45
|
+
* updates. If the clientFn is null, the appservice's bot user will be used.
|
|
46
|
+
* The clientFn takes two arguments: the user ID being updated and the room ID
|
|
47
|
+
* they are being updated in (shouldn't be null). The return value should be the
|
|
48
|
+
* MatrixClient to use, or null to use the appservice's bot client. The same
|
|
49
|
+
* client will be used to update the user's general profile, if that profile
|
|
50
|
+
* is cached.
|
|
51
|
+
* @param {Appservice} appservice The application service to watch for profile changes with.
|
|
52
|
+
* @param {Function} clientFn The function to use to acquire profile updates with. If null, the appservice's bot client will be used.
|
|
53
|
+
*/
|
|
54
|
+
watchWithAppservice(appservice, clientFn = null) {
|
|
55
|
+
if (!clientFn)
|
|
56
|
+
clientFn = () => appservice.botClient;
|
|
57
|
+
appservice.on("room.event", async (roomId, event) => {
|
|
58
|
+
if (!event['state_key'] || !event['content'] || event['type'] !== 'm.room.member')
|
|
59
|
+
return;
|
|
60
|
+
const memberEvent = new MembershipEvent_1.MembershipEvent(event);
|
|
61
|
+
let client = clientFn(memberEvent.membershipFor, roomId);
|
|
62
|
+
if (!client)
|
|
63
|
+
client = appservice.botClient;
|
|
64
|
+
await this.tryUpdateProfile(roomId, memberEvent, client);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets a profile for a user in optional room.
|
|
69
|
+
* @param {string} userId The user ID to get a profile for.
|
|
70
|
+
* @param {string|null} roomId Optional room ID to get a per-room profile for the user.
|
|
71
|
+
* @returns {Promise<MatrixProfile>} Resolves to the user's profile.
|
|
72
|
+
*/
|
|
73
|
+
async getUserProfile(userId, roomId = null) {
|
|
74
|
+
const cacheKey = this.getCacheKey(userId, roomId);
|
|
75
|
+
const cached = this.cache.get(cacheKey);
|
|
76
|
+
if (cached)
|
|
77
|
+
return Promise.resolve(cached);
|
|
78
|
+
const profile = await this.getUserProfileWith(userId, roomId, this.client);
|
|
79
|
+
this.cache.set(cacheKey, profile);
|
|
80
|
+
return profile;
|
|
81
|
+
}
|
|
82
|
+
async getUserProfileWith(userId, roomId, client) {
|
|
83
|
+
try {
|
|
84
|
+
if (roomId) {
|
|
85
|
+
const membership = await client.getRoomStateEvent(roomId, "m.room.member", userId);
|
|
86
|
+
return new __1.MatrixProfile(userId, membership);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const profile = await client.getUserProfile(userId);
|
|
90
|
+
return new __1.MatrixProfile(userId, profile);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
__1.LogService.warn("ProfileCache", "Non-fatal error getting user profile. They might not exist.");
|
|
95
|
+
__1.LogService.warn("ProfileCache", (0, __1.extractRequestError)(e));
|
|
96
|
+
return new __1.MatrixProfile(userId, {});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async tryUpdateProfile(roomId, memberEvent, client) {
|
|
100
|
+
const roomCacheKey = this.getCacheKey(memberEvent.membershipFor, roomId);
|
|
101
|
+
const generalCacheKey = this.getCacheKey(memberEvent.membershipFor, null);
|
|
102
|
+
if (this.cache.has(roomCacheKey)) {
|
|
103
|
+
this.cache.set(roomCacheKey, new __1.MatrixProfile(memberEvent.membershipFor, memberEvent.content));
|
|
104
|
+
}
|
|
105
|
+
// TODO: Try and figure out semantics for this updating.
|
|
106
|
+
// Large accounts could cause hammering on the profile endpoint, but hopefully it is cached by the server.
|
|
107
|
+
if (this.cache.has(generalCacheKey)) {
|
|
108
|
+
const profile = await this.getUserProfileWith(memberEvent.membershipFor, null, client);
|
|
109
|
+
this.cache.set(generalCacheKey, profile);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ProfileCache = ProfileCache;
|
|
114
|
+
//# sourceMappingURL=ProfileCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProfileCache.js","sourceRoot":"","sources":["../../src/helpers/ProfileCache.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for creating rich replies.
|
|
3
|
+
* @category Utilities
|
|
4
|
+
*/
|
|
5
|
+
export declare class RichReply {
|
|
6
|
+
private constructor();
|
|
7
|
+
/**
|
|
8
|
+
* Generates the event content required to reply to the provided event with the
|
|
9
|
+
* provided text.
|
|
10
|
+
* @param {string} roomId the room ID the event being replied to resides in
|
|
11
|
+
* @param {any} event the event to reply to
|
|
12
|
+
* @param {string} withText the plain text to reply with
|
|
13
|
+
* @param {string} withHtml the HTML to reply with
|
|
14
|
+
* @returns {any} the content of the event representing the reply
|
|
15
|
+
*/
|
|
16
|
+
static createFor(roomId: string, event: any, withText: string, withHtml: string): any;
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RichReply = void 0;
|
|
4
|
+
const sanitizeHtml = require("sanitize-html");
|
|
5
|
+
/**
|
|
6
|
+
* Helper for creating rich replies.
|
|
7
|
+
* @category Utilities
|
|
8
|
+
*/
|
|
9
|
+
class RichReply {
|
|
10
|
+
constructor() {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates the event content required to reply to the provided event with the
|
|
14
|
+
* provided text.
|
|
15
|
+
* @param {string} roomId the room ID the event being replied to resides in
|
|
16
|
+
* @param {any} event the event to reply to
|
|
17
|
+
* @param {string} withText the plain text to reply with
|
|
18
|
+
* @param {string} withHtml the HTML to reply with
|
|
19
|
+
* @returns {any} the content of the event representing the reply
|
|
20
|
+
*/
|
|
21
|
+
static createFor(roomId, event, withText, withHtml) {
|
|
22
|
+
const originalBody = (event["content"] ? event["content"]["body"] : "") || "";
|
|
23
|
+
let originalHtml = (event["content"] ? event["content"]["formatted_body"] : "") || null;
|
|
24
|
+
if (originalHtml === null) {
|
|
25
|
+
originalHtml = sanitizeHtml(originalBody);
|
|
26
|
+
}
|
|
27
|
+
const fallbackText = "> <" + event["sender"] + "> " + originalBody.split("\n").join("\n> ");
|
|
28
|
+
const fallbackHtml = "<mx-reply><blockquote>"
|
|
29
|
+
+ `<a href="https://matrix.to/#/${roomId}/${event["event_id"]}">In reply to</a> `
|
|
30
|
+
+ `<a href="https://matrix.to/#/${event["sender"]}">${event["sender"]}</a>`
|
|
31
|
+
+ "<br />" + originalHtml
|
|
32
|
+
+ "</blockquote></mx-reply>";
|
|
33
|
+
return {
|
|
34
|
+
"m.relates_to": {
|
|
35
|
+
"m.in_reply_to": {
|
|
36
|
+
"event_id": event["event_id"],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
"msgtype": "m.text", // for those who just want to send the reply as-is
|
|
40
|
+
"body": fallbackText + "\n\n" + withText,
|
|
41
|
+
"format": "org.matrix.custom.html",
|
|
42
|
+
"formatted_body": fallbackHtml + withHtml,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.RichReply = RichReply;
|
|
47
|
+
//# sourceMappingURL=RichReply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RichReply.js","sourceRoot":"","sources":["../../src/helpers/RichReply.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAE9C;;;GAGG;AACH,MAAa,SAAS;IAClB;IACA,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,SAAS,CAAC,MAAc,EAAE,KAAU,EAAE,QAAgB,EAAE,QAAgB;QAClF,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QAC9E,IAAI,YAAY,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;QACxF,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YACxB,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5F,MAAM,YAAY,GAAG,wBAAwB;cACvC,gCAAgC,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,oBAAoB;cAC/E,gCAAgC,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,MAAM;cACzE,QAAQ,GAAG,YAAY;cACvB,0BAA0B,CAAC;QAEjC,OAAO;YACH,cAAc,EAAE;gBACZ,eAAe,EAAE;oBACb,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC;iBAChC;aACJ;YACD,SAAS,EAAE,QAAQ,EAAE,kDAAkD;YACvE,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,QAAQ;YACxC,QAAQ,EAAE,wBAAwB;YAClC,gBAAgB,EAAE,YAAY,GAAG,QAAQ;SAC5C,CAAC;IACN,CAAC;CACJ;AAvCD,8BAuCC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unpadded Base64 utilities for Matrix.
|
|
3
|
+
* @category Utilities
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnpaddedBase64 {
|
|
6
|
+
private constructor();
|
|
7
|
+
/**
|
|
8
|
+
* Encodes a buffer to Unpadded Base64
|
|
9
|
+
* @param {Buffer} buf The buffer to encode.
|
|
10
|
+
* @returns {string} The Unpadded Base64 string
|
|
11
|
+
*/
|
|
12
|
+
static encodeBuffer(buf: Buffer): string;
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a string to Unpadded Base64
|
|
15
|
+
* @param {string} str The string to encode.
|
|
16
|
+
* @returns {string} The Unpadded Base64 string
|
|
17
|
+
*/
|
|
18
|
+
static encodeString(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Encodes a buffer to Unpadded Base64 (URL Safe Edition)
|
|
21
|
+
* @param {Buffer} buf The buffer to encode.
|
|
22
|
+
* @returns {string} The Unpadded Base64 string
|
|
23
|
+
*/
|
|
24
|
+
static encodeBufferUrlSafe(buf: Buffer): string;
|
|
25
|
+
/**
|
|
26
|
+
* Encodes a string to Unpadded Base64 (URL Safe Edition)
|
|
27
|
+
* @param {string} str The string to encode.
|
|
28
|
+
* @returns {string} The Unpadded Base64 string
|
|
29
|
+
*/
|
|
30
|
+
static encodeStringUrlSafe(str: string): string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnpaddedBase64 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Unpadded Base64 utilities for Matrix.
|
|
6
|
+
* @category Utilities
|
|
7
|
+
*/
|
|
8
|
+
class UnpaddedBase64 {
|
|
9
|
+
constructor() {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Encodes a buffer to Unpadded Base64
|
|
13
|
+
* @param {Buffer} buf The buffer to encode.
|
|
14
|
+
* @returns {string} The Unpadded Base64 string
|
|
15
|
+
*/
|
|
16
|
+
static encodeBuffer(buf) {
|
|
17
|
+
return buf.toString('base64').replace(/[=]*$/g, '');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Encodes a string to Unpadded Base64
|
|
21
|
+
* @param {string} str The string to encode.
|
|
22
|
+
* @returns {string} The Unpadded Base64 string
|
|
23
|
+
*/
|
|
24
|
+
static encodeString(str) {
|
|
25
|
+
return UnpaddedBase64.encodeBuffer(Buffer.from(str));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Encodes a buffer to Unpadded Base64 (URL Safe Edition)
|
|
29
|
+
* @param {Buffer} buf The buffer to encode.
|
|
30
|
+
* @returns {string} The Unpadded Base64 string
|
|
31
|
+
*/
|
|
32
|
+
static encodeBufferUrlSafe(buf) {
|
|
33
|
+
return UnpaddedBase64.encodeBuffer(buf).replace(/\+/g, '-').replace(/\//g, '_');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Encodes a string to Unpadded Base64 (URL Safe Edition)
|
|
37
|
+
* @param {string} str The string to encode.
|
|
38
|
+
* @returns {string} The Unpadded Base64 string
|
|
39
|
+
*/
|
|
40
|
+
static encodeStringUrlSafe(str) {
|
|
41
|
+
return UnpaddedBase64.encodeBufferUrlSafe(Buffer.from(str));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.UnpaddedBase64 = UnpaddedBase64;
|
|
45
|
+
//# sourceMappingURL=UnpaddedBase64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnpaddedBase64.js","sourceRoot":"","sources":["../../src/helpers/UnpaddedBase64.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,cAAc;IACvB;IACA,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,GAAW;QAClC,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,GAAW;QAClC,OAAO,cAAc,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,GAAW;QACzC,OAAO,cAAc,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,GAAW;QACzC,OAAO,cAAc,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;CACJ;AAvCD,wCAuCC"}
|