@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,27 @@
|
|
|
1
|
+
import { StateEvent } from "./RoomEvent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The content definition for m.room.topic events
|
|
5
|
+
* @category Matrix event contents
|
|
6
|
+
* @see RoomTopicEvent
|
|
7
|
+
*/
|
|
8
|
+
export interface RoomTopicEventContent {
|
|
9
|
+
topic: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents an m.room.topic state event
|
|
14
|
+
* @category Matrix events
|
|
15
|
+
*/
|
|
16
|
+
export class RoomTopicEvent extends StateEvent<RoomTopicEventContent> {
|
|
17
|
+
constructor(event: any) {
|
|
18
|
+
super(event);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The topic of the room.
|
|
23
|
+
*/
|
|
24
|
+
public get topic(): string {
|
|
25
|
+
return this.content.topic;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { StateEvent } from "./RoomEvent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The content definition for m.space.child events
|
|
5
|
+
* @category Matrix event contents
|
|
6
|
+
* @see SpaceChildEvent
|
|
7
|
+
*/
|
|
8
|
+
export interface SpaceChildEventContent {
|
|
9
|
+
/**
|
|
10
|
+
* The servers the client should provide to the server when trying to join the room.
|
|
11
|
+
* When not provided or empty, the child is considered not part of the space.
|
|
12
|
+
*/
|
|
13
|
+
via: string[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A short string to differentiate the rendering order of entities.
|
|
17
|
+
* @see validateSpaceOrderString
|
|
18
|
+
*/
|
|
19
|
+
order?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not the entity is intended to be a suggested entity.
|
|
23
|
+
*/
|
|
24
|
+
suggested?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Represents an m.space.child state event
|
|
29
|
+
* @category Matrix events
|
|
30
|
+
*/
|
|
31
|
+
export class SpaceChildEvent extends StateEvent<SpaceChildEventContent> {
|
|
32
|
+
constructor(event: any) {
|
|
33
|
+
super(event);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The room ID of the space or room this child represents.
|
|
38
|
+
*/
|
|
39
|
+
public get entityRoomId(): string {
|
|
40
|
+
return this.stateKey;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether or not this child is "active" or valid. Inactive children are
|
|
45
|
+
* not considered part of a space.
|
|
46
|
+
*/
|
|
47
|
+
public get isActiveChild(): boolean {
|
|
48
|
+
return !!this.viaServers?.length;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The servers the client should provide to the homeserver when trying to
|
|
53
|
+
* join the entity (room). May be empty or falsey to denote the child is
|
|
54
|
+
* inactive.
|
|
55
|
+
*/
|
|
56
|
+
public get viaServers(): string[] {
|
|
57
|
+
return this.content.via;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* An optional short string to differentiate the rendering order of entities.
|
|
62
|
+
* @see validateSpaceOrderString
|
|
63
|
+
*/
|
|
64
|
+
public get order(): string {
|
|
65
|
+
return this.content.order;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether or not the child is a suggested entity for users to join.
|
|
70
|
+
*/
|
|
71
|
+
public get suggested(): boolean {
|
|
72
|
+
return this.content.suggested ?? false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
## Missing event types
|
|
2
|
+
|
|
3
|
+
These are the event types that need definitions.
|
|
4
|
+
|
|
5
|
+
### r0.6.0
|
|
6
|
+
|
|
7
|
+
* `m.call.invite`
|
|
8
|
+
* `m.call.candidates`
|
|
9
|
+
* `m.call.answer`
|
|
10
|
+
* `m.call.hangup`
|
|
11
|
+
* `m.typing`
|
|
12
|
+
* `m.receipt`
|
|
13
|
+
* `m.fully_read`
|
|
14
|
+
* `m.key.verification.request`
|
|
15
|
+
* `m.key.verification.start`
|
|
16
|
+
* `m.key.verification.cancel`
|
|
17
|
+
* `m.key.verification.start` (SAS)
|
|
18
|
+
* `m.key.verification.accept`
|
|
19
|
+
* `m.key.verification.key`
|
|
20
|
+
* `m.key.verification.mac`
|
|
21
|
+
* `m.room_key`
|
|
22
|
+
* `m.room_key_request`
|
|
23
|
+
* `m.forwarded_room_key`
|
|
24
|
+
* `m.dummy`
|
|
25
|
+
* `m.room.history_visibility`
|
|
26
|
+
* `m.push_rules`
|
|
27
|
+
* `m.room.third_party_invite`
|
|
28
|
+
* `m.room.guest_access`
|
|
29
|
+
* `m.tag`
|
|
30
|
+
* `m.direct`
|
|
31
|
+
* `m.ignored_user_list`
|
|
32
|
+
* `m.sticker`
|
|
33
|
+
* `m.room.server_acl`
|
|
34
|
+
* `m.room.tombstone`
|
|
35
|
+
* `m.room.message` of type `m.server_notice`
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MembershipEvent } from "./MembershipEvent";
|
|
2
|
+
import { RoomEvent, StateEvent } from "./RoomEvent";
|
|
3
|
+
import {
|
|
4
|
+
AudioMessageEventContent,
|
|
5
|
+
ImageMessageEventContent,
|
|
6
|
+
LocationMessageEventContent,
|
|
7
|
+
MessageEvent,
|
|
8
|
+
MessageEventContent,
|
|
9
|
+
TextualMessageEventContent,
|
|
10
|
+
VideoMessageEventContent,
|
|
11
|
+
} from "./MessageEvent";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wraps a room event into a more suitable container.
|
|
15
|
+
* @param {any} event The event object to wrap.
|
|
16
|
+
* @returns {RoomEvent<any>} An instance of the most suitable container for the event.
|
|
17
|
+
* @category Matrix events
|
|
18
|
+
*/
|
|
19
|
+
export function wrapRoomEvent(event: any): RoomEvent<any> {
|
|
20
|
+
if (!event) return null;
|
|
21
|
+
|
|
22
|
+
if (typeof (event['state_key']) === 'string') {
|
|
23
|
+
if (event['type'] === 'm.room.member') {
|
|
24
|
+
return new MembershipEvent(event);
|
|
25
|
+
} else {
|
|
26
|
+
return new StateEvent<any>(event);
|
|
27
|
+
}
|
|
28
|
+
} else if (event['type'] === 'm.room.message') {
|
|
29
|
+
const content = event['content'];
|
|
30
|
+
const msgtype = content ? content['msgtype'] : null;
|
|
31
|
+
if (msgtype === "m.text" || msgtype === "m.notice" || msgtype === "m.emote") {
|
|
32
|
+
return new MessageEvent<TextualMessageEventContent>(event);
|
|
33
|
+
} else if (msgtype === "m.audio") {
|
|
34
|
+
return new MessageEvent<AudioMessageEventContent>(event);
|
|
35
|
+
} else if (msgtype === "m.video") {
|
|
36
|
+
return new MessageEvent<VideoMessageEventContent>(event);
|
|
37
|
+
} else if (msgtype === "m.image") {
|
|
38
|
+
return new MessageEvent<ImageMessageEventContent>(event);
|
|
39
|
+
} else if (msgtype === "m.location") {
|
|
40
|
+
return new MessageEvent<LocationMessageEventContent>(event);
|
|
41
|
+
} else {
|
|
42
|
+
return new MessageEvent<MessageEventContent>(event);
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
return new RoomEvent<any>(event);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface implements the schema defined in [MSC2380](https://github.com/matrix-org/matrix-doc/pull/2380).
|
|
3
|
+
* @category Unstable APIs
|
|
4
|
+
*/
|
|
5
|
+
export interface MSC2380MediaInfo {
|
|
6
|
+
content_type: string;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
size: number;
|
|
10
|
+
thumbnails?: {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
ready: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
duration?: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MatrixClient } from "../MatrixClient";
|
|
2
|
+
import { EventKind } from "..";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a preprocessor.
|
|
6
|
+
* @category Preprocessors
|
|
7
|
+
*/
|
|
8
|
+
export interface IPreprocessor {
|
|
9
|
+
/**
|
|
10
|
+
* Gets the types of events this preprocessor supports.
|
|
11
|
+
*/
|
|
12
|
+
getSupportedEventTypes(): string[];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Processes an event, modifying it in-place if needed.
|
|
16
|
+
* @param {any} event The event that should be processed.
|
|
17
|
+
* @param {MatrixClient} client The Matrix client that is providing the event.
|
|
18
|
+
* @param {EventKind|null|undefined} kind Optional kind identifier for an event. When not
|
|
19
|
+
* supplied, the event is assumed to be a RoomEvent.
|
|
20
|
+
* @returns {Promise<any>} Resolved when the event is has been modified. The resolved
|
|
21
|
+
* value is ignored.
|
|
22
|
+
*/
|
|
23
|
+
processEvent(event: any, client: MatrixClient, kind?: EventKind): Promise<any>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { MatrixClient } from "../MatrixClient";
|
|
2
|
+
import { IPreprocessor } from "./IPreprocessor";
|
|
3
|
+
import { EventKind, extractRequestError, LogService } from "..";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Metadata for a rich reply. Usually stored under the "mx_richreply"
|
|
7
|
+
* field of an event (at the top level).
|
|
8
|
+
* @category Preprocessors
|
|
9
|
+
* @see RichRepliesPreprocessor
|
|
10
|
+
*/
|
|
11
|
+
export interface IRichReplyMetadata {
|
|
12
|
+
/**
|
|
13
|
+
* If true, the preprocessor found some inconsistencies in the reply
|
|
14
|
+
* information that does not match the specification. For example,
|
|
15
|
+
* this may indicate that a reply was sent without an HTML component.
|
|
16
|
+
*/
|
|
17
|
+
wasLenient: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The event ID the event references. May be an empty string if
|
|
21
|
+
* wasLenient is true.
|
|
22
|
+
*/
|
|
23
|
+
parentEventId: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The fallback plain text the preprocessor found. May be an empty
|
|
27
|
+
* string if wasLenient is true. The prefix characters to indicate
|
|
28
|
+
* this is a fallback will have already been removed.
|
|
29
|
+
*/
|
|
30
|
+
fallbackPlainBody: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The fallback HTML the processor found. May be an empty string if
|
|
34
|
+
* wasLenient is true. The fallback structure will have already been
|
|
35
|
+
* removed, leaving just the original assumed HTML.
|
|
36
|
+
*/
|
|
37
|
+
fallbackHtmlBody: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The user ID that sent the parent event, as determined by the fallback
|
|
41
|
+
* text. This should not be relied upon for anything serious, and instead
|
|
42
|
+
* the preprocessor should be configured to fetch the real event to
|
|
43
|
+
* populate the realEvent property. May be an empty string if wasLenient
|
|
44
|
+
* is true.
|
|
45
|
+
*/
|
|
46
|
+
fallbackSender: string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* If the preprocessor is configured to fetch event content, this field
|
|
50
|
+
* will contain the event as reported by the homeserver. May be null if
|
|
51
|
+
* wasLenient is true.
|
|
52
|
+
*/
|
|
53
|
+
realEvent: any;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Processes rich replies found in events. This automatically strips
|
|
58
|
+
* the fallback representation from events, providing the information
|
|
59
|
+
* as a top level "mx_richreply" key. The "mx_richreply" property may
|
|
60
|
+
* be cast to the type IRichReplyMetadata.
|
|
61
|
+
* @category Preprocessors
|
|
62
|
+
*/
|
|
63
|
+
export class RichRepliesPreprocessor implements IPreprocessor {
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new rich replies preprocessor.
|
|
66
|
+
* @param fetchRealEventContents If enabled, this preprocessor will
|
|
67
|
+
* attempt to get the real event contents and append them to the event
|
|
68
|
+
* information.
|
|
69
|
+
*/
|
|
70
|
+
public constructor(private fetchRealEventContents = false) {
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getSupportedEventTypes(): string[] {
|
|
74
|
+
return ["m.room.message"];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async processEvent(event: any, client: MatrixClient, kind?: EventKind): Promise<any> {
|
|
78
|
+
if (kind && kind !== EventKind.RoomEvent) return;
|
|
79
|
+
|
|
80
|
+
if (!event["content"]) return;
|
|
81
|
+
if (!event["content"]["m.relates_to"]) return;
|
|
82
|
+
if (!event["content"]["m.relates_to"]["m.in_reply_to"]) return;
|
|
83
|
+
|
|
84
|
+
const parentEventId = event["content"]["m.relates_to"]["m.in_reply_to"]["event_id"];
|
|
85
|
+
if (!parentEventId) return;
|
|
86
|
+
|
|
87
|
+
let fallbackHtml = "";
|
|
88
|
+
let fallbackText = "";
|
|
89
|
+
let fallbackSender = "";
|
|
90
|
+
let realHtml = event["content"]["formatted_body"];
|
|
91
|
+
let realText = event["content"]["body"];
|
|
92
|
+
let lenient = false;
|
|
93
|
+
|
|
94
|
+
if (event["content"]["format"] !== "org.matrix.custom.html" || !event["content"]["formatted_body"]) {
|
|
95
|
+
lenient = true; // Not safe to parse: probably not HTML
|
|
96
|
+
} else {
|
|
97
|
+
const formattedBody = event["content"]["formatted_body"];
|
|
98
|
+
if (!formattedBody.startsWith("<mx-reply>") || formattedBody.indexOf("</mx-reply>") === -1) {
|
|
99
|
+
lenient = true; // Doesn't look like a reply
|
|
100
|
+
} else {
|
|
101
|
+
const parts = formattedBody.split("</mx-reply>");
|
|
102
|
+
const fbHtml = parts[0];
|
|
103
|
+
realHtml = parts[1];
|
|
104
|
+
|
|
105
|
+
const results = fbHtml.match(/<br[ ]*[/]{0,2}>(.*)<\/blockquote>\s*$/i);
|
|
106
|
+
if (!results) {
|
|
107
|
+
lenient = true;
|
|
108
|
+
} else {
|
|
109
|
+
fallbackHtml = results[1];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let processedFallback = false;
|
|
115
|
+
const body = event["content"]["body"] || "";
|
|
116
|
+
for (const line of body.split("\n")) {
|
|
117
|
+
if (line.startsWith("> ") && !processedFallback) {
|
|
118
|
+
fallbackText += line.substring(2) + "\n";
|
|
119
|
+
} else if (!processedFallback) {
|
|
120
|
+
realText = "";
|
|
121
|
+
processedFallback = true;
|
|
122
|
+
} else {
|
|
123
|
+
realText += line + "\n";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const firstFallbackLine = fallbackText.split("\n")[0];
|
|
128
|
+
const matches = firstFallbackLine.match(/<(@.*:.*)>/);
|
|
129
|
+
if (!matches) {
|
|
130
|
+
lenient = true;
|
|
131
|
+
} else {
|
|
132
|
+
fallbackSender = matches[1];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const metadata: IRichReplyMetadata = {
|
|
136
|
+
wasLenient: lenient,
|
|
137
|
+
fallbackHtmlBody: fallbackHtml ? fallbackHtml.trim() : "",
|
|
138
|
+
fallbackPlainBody: fallbackText ? fallbackText.trim() : "",
|
|
139
|
+
fallbackSender: fallbackSender ? fallbackSender.trim() : "",
|
|
140
|
+
parentEventId: parentEventId ? parentEventId.trim() : "",
|
|
141
|
+
realEvent: null,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (this.fetchRealEventContents) {
|
|
145
|
+
try {
|
|
146
|
+
metadata.realEvent = await client.getEvent(event["room_id"], parentEventId);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
LogService.error("RichRepliesPreprocessor", "Failed to fetch real event:");
|
|
149
|
+
LogService.error("RichRepliesPreprocessor", extractRequestError(e));
|
|
150
|
+
metadata.wasLenient = true; // failed to fetch event
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
event["mx_richreply"] = metadata;
|
|
155
|
+
event["content"]["body"] = realText.trim();
|
|
156
|
+
if (realHtml) event["content"]["formatted_body"] = realHtml.trim();
|
|
157
|
+
return event;
|
|
158
|
+
}
|
|
159
|
+
}
|
package/src/request.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as origRequestFn from "request";
|
|
2
|
+
|
|
3
|
+
let requestFn = origRequestFn;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sets the function to use for performing HTTP requests. Must be compatible with `request`.
|
|
7
|
+
* @param fn The new request function.
|
|
8
|
+
* @category Unit testing
|
|
9
|
+
*/
|
|
10
|
+
export function setRequestFn(fn) {
|
|
11
|
+
requestFn = fn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Gets the `request`-compatible function for performing HTTP requests.
|
|
16
|
+
* @returns The request function.
|
|
17
|
+
* @category Unit testing
|
|
18
|
+
*/
|
|
19
|
+
export function getRequestFn(): typeof origRequestFn {
|
|
20
|
+
return requestFn;
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate the 'order' parameter of a child space entry. It must be a
|
|
3
|
+
* string between the range of \x20 - \x7F and contain no more than 50
|
|
4
|
+
* characters.
|
|
5
|
+
* @param {string} order The 'order' parameter of a m.space.child
|
|
6
|
+
* @throws {Error} If the string is not valid
|
|
7
|
+
* @returns {boolean} True if the string is valid
|
|
8
|
+
* @category Utilities
|
|
9
|
+
*/
|
|
10
|
+
export function validateSpaceOrderString(order: string): true {
|
|
11
|
+
if (typeof (order) !== 'string') {
|
|
12
|
+
// Just in case, even though TS should catch this.
|
|
13
|
+
throw Error('order is not a string');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (order.length === 0) {
|
|
17
|
+
throw Error('order cannot be empty');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (order.length > 50) {
|
|
21
|
+
throw Error('order is more than 50 characters and is disallowed');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!order.match(/^[\x20-\x7E]+$/)) {
|
|
25
|
+
// String must be between this range
|
|
26
|
+
throw Error('order contained characters outside the range of the spec.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ICryptoStorageProvider } from "./ICryptoStorageProvider";
|
|
2
|
+
import { IStorageProvider } from "./IStorageProvider";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A storage provider definition for appservices to use.
|
|
6
|
+
* @category Storage providers
|
|
7
|
+
*/
|
|
8
|
+
export interface IAppserviceStorageProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Tracks a user ID as "registered".
|
|
11
|
+
* @returns {Promise<any>|void} Resolves when complete.
|
|
12
|
+
*/
|
|
13
|
+
addRegisteredUser(userId: string): Promise<any> | void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Determines if a user ID is registered or not.
|
|
17
|
+
* @returns {boolean|Promise<boolean>} True if registered. This may be a promise.
|
|
18
|
+
*/
|
|
19
|
+
isUserRegistered(userId: string): boolean | Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Flags a transaction as completed.
|
|
23
|
+
* @param {string} transactionId The transaction ID.
|
|
24
|
+
* @returns {Promise<any>|void} Resolves when complete.
|
|
25
|
+
*/
|
|
26
|
+
setTransactionCompleted(transactionId: string): Promise<any> | void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Determines if a transaction has been flagged as completed.
|
|
30
|
+
* @param {string} transactionId The transaction ID to check.
|
|
31
|
+
* @returns {boolean} True if the transaction has been completed. This may be a promise.
|
|
32
|
+
*/
|
|
33
|
+
isTransactionCompleted(transactionId: string): boolean | Promise<boolean>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets a storage provider to use for the given user ID.
|
|
37
|
+
* @param {string} userId The user ID.
|
|
38
|
+
* @returns {ICryptoStorageProvider} The storage provider.
|
|
39
|
+
*/
|
|
40
|
+
storageForUser?(userId: string): IStorageProvider;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A storage provider capable of only providing crypto-related storage to appservices.
|
|
45
|
+
* @category Storage providers
|
|
46
|
+
*/
|
|
47
|
+
export interface IAppserviceCryptoStorageProvider {
|
|
48
|
+
/**
|
|
49
|
+
* Gets a storage provider to use for the given user ID.
|
|
50
|
+
* @param {string} userId The user ID.
|
|
51
|
+
* @returns {ICryptoStorageProvider} The storage provider.
|
|
52
|
+
*/
|
|
53
|
+
storageForUser(userId: string): ICryptoStorageProvider;
|
|
54
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ICryptoRoomInformation } from "../e2ee/ICryptoRoomInformation";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A storage provider capable of only providing crypto-related storage.
|
|
5
|
+
* @category Storage providers
|
|
6
|
+
*/
|
|
7
|
+
export interface ICryptoStorageProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Sets the client's device ID.
|
|
10
|
+
* @param {string} deviceId The device ID.
|
|
11
|
+
* @returns {Promise<void>} Resolves when complete.
|
|
12
|
+
*/
|
|
13
|
+
setDeviceId(deviceId: string): Promise<void>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the client's device ID, if known.
|
|
17
|
+
* @returns {Promise<string>} Resolves to the device ID, or falsy if not known.
|
|
18
|
+
*/
|
|
19
|
+
getDeviceId(): Promise<string>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Stores a room's configuration.
|
|
23
|
+
* @param {string} roomId The room ID to store the configuration for.
|
|
24
|
+
* @param {ICryptoRoomInformation} config The room's encryption config. May be empty.
|
|
25
|
+
* @returns {Promise<void>} Resolves when complete.
|
|
26
|
+
*/
|
|
27
|
+
storeRoom(roomId: string, config: ICryptoRoomInformation): Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets a room's configuration. If the room is unknown, a falsy value is returned.
|
|
31
|
+
* @param {string} roomId The room ID to get the configuration for.
|
|
32
|
+
* @returns {Promise<ICryptoRoomInformation>} Resolves to the room's configuration, or
|
|
33
|
+
* to falsy if the room is unknown.
|
|
34
|
+
*/
|
|
35
|
+
getRoom(roomId: string): Promise<ICryptoRoomInformation>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IFilterInfo } from "../IFilter";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a storage provider for the matrix client
|
|
5
|
+
* @category Storage providers
|
|
6
|
+
*/
|
|
7
|
+
export interface IStorageProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Sets the sync token, saving it for later retrieval
|
|
10
|
+
* @param {string} token The token to save
|
|
11
|
+
* @returns {Promise<any>|void} Resolves when complete.
|
|
12
|
+
*/
|
|
13
|
+
setSyncToken(token: string | null): Promise<any> | void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the last saved sync token, or null if none has been persisted.
|
|
17
|
+
* @returns {String|Promise<String>} The last sync token, or null. This can
|
|
18
|
+
* also be a promise for the value.
|
|
19
|
+
*/
|
|
20
|
+
getSyncToken(): string | Promise<string | null> | null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Sets the filter to be used by future clients
|
|
24
|
+
* @param {IFilterInfo} filter The filter to store
|
|
25
|
+
* @returns {Promise<any>|void} Resolves when complete.
|
|
26
|
+
*/
|
|
27
|
+
setFilter(filter: IFilterInfo): Promise<any> | void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets the last preferred filter for this client
|
|
31
|
+
* @returns {IFilterInfo|Promise<IFilterInfo>} The last saved filter, or null.
|
|
32
|
+
* This can also be a promise for the filter.
|
|
33
|
+
*/
|
|
34
|
+
getFilter(): IFilterInfo | Promise<IFilterInfo>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Store a simple string value into the provided key.
|
|
38
|
+
* @param {string} key The key to store the value under.
|
|
39
|
+
* @param {string} value The value to store.
|
|
40
|
+
* @returns {Promise<any> | void} Resolves when complete.
|
|
41
|
+
*/
|
|
42
|
+
storeValue(key: string, value: string): Promise<any> | void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reads a previously stored value under the given key. If the
|
|
46
|
+
* key does not exist, null or undefined is returned.
|
|
47
|
+
* @param {string} key The key to read.
|
|
48
|
+
* @returns {string|Promise<string|null|undefined>|null|undefined} The
|
|
49
|
+
* value, or null/undefined if not found. This may also return a promise
|
|
50
|
+
* of those same values.
|
|
51
|
+
*/
|
|
52
|
+
readValue(key: string): string | Promise<string | null | undefined> | null | undefined;
|
|
53
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { IStorageProvider } from "./IStorageProvider";
|
|
2
|
+
import { IFilterInfo } from "../IFilter";
|
|
3
|
+
import { IAppserviceStorageProvider } from "./IAppserviceStorageProvider";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A storage provider that persists no information by keeping it all in memory.
|
|
7
|
+
* @category Storage providers
|
|
8
|
+
*/
|
|
9
|
+
export class MemoryStorageProvider implements IStorageProvider, IAppserviceStorageProvider {
|
|
10
|
+
private namespaced = new Map<string, MemoryStorageProvider>();
|
|
11
|
+
private syncToken: string;
|
|
12
|
+
private filter: IFilterInfo;
|
|
13
|
+
private appserviceUsers: { [userId: string]: { registered: boolean } } = {};
|
|
14
|
+
private appserviceTransactions: { [txnId: string]: boolean } = {};
|
|
15
|
+
private kvStore: { [key: string]: string } = {};
|
|
16
|
+
|
|
17
|
+
setSyncToken(token: string | null): void {
|
|
18
|
+
this.syncToken = token;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getSyncToken(): string | null {
|
|
22
|
+
return this.syncToken;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setFilter(filter: IFilterInfo): void {
|
|
26
|
+
this.filter = filter;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getFilter(): IFilterInfo {
|
|
30
|
+
return this.filter;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addRegisteredUser(userId: string) {
|
|
34
|
+
this.appserviceUsers[userId] = {
|
|
35
|
+
registered: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
isUserRegistered(userId: string): boolean {
|
|
40
|
+
return this.appserviceUsers[userId] && this.appserviceUsers[userId].registered;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
isTransactionCompleted(transactionId: string): boolean {
|
|
44
|
+
return !!this.appserviceTransactions[transactionId];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
setTransactionCompleted(transactionId: string) {
|
|
48
|
+
this.appserviceTransactions[transactionId] = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
readValue(key: string): string | null | undefined {
|
|
52
|
+
return this.kvStore[key];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
storeValue(key: string, value: string): void {
|
|
56
|
+
this.kvStore[key] = value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
storageForUser(userId: string): IStorageProvider {
|
|
60
|
+
if (!this.namespaced.has(userId)) {
|
|
61
|
+
this.namespaced.set(userId, new MemoryStorageProvider());
|
|
62
|
+
}
|
|
63
|
+
return this.namespaced.get(userId);
|
|
64
|
+
}
|
|
65
|
+
}
|