@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.
Files changed (377) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/lib/AdminApis.d.ts +52 -0
  4. package/lib/AdminApis.js +29 -0
  5. package/lib/AdminApis.js.map +1 -0
  6. package/lib/DMs.d.ts +48 -0
  7. package/lib/DMs.js +160 -0
  8. package/lib/DMs.js.map +1 -0
  9. package/lib/IFilter.d.ts +7 -0
  10. package/lib/IFilter.js +3 -0
  11. package/lib/IFilter.js.map +1 -0
  12. package/lib/MatrixAuth.d.ts +45 -0
  13. package/lib/MatrixAuth.js +125 -0
  14. package/lib/MatrixAuth.js.map +1 -0
  15. package/lib/MatrixClient.d.ts +834 -0
  16. package/lib/MatrixClient.js +2268 -0
  17. package/lib/MatrixClient.js.map +1 -0
  18. package/lib/PantalaimonClient.d.ts +42 -0
  19. package/lib/PantalaimonClient.js +44 -0
  20. package/lib/PantalaimonClient.js.map +1 -0
  21. package/lib/SynapseAdminApis.d.ts +350 -0
  22. package/lib/SynapseAdminApis.js +244 -0
  23. package/lib/SynapseAdminApis.js.map +1 -0
  24. package/lib/SynchronousMatrixClient.d.ts +82 -0
  25. package/lib/SynchronousMatrixClient.js +130 -0
  26. package/lib/SynchronousMatrixClient.js.map +1 -0
  27. package/lib/UnstableApis.d.ts +43 -0
  28. package/lib/UnstableApis.js +74 -0
  29. package/lib/UnstableApis.js.map +1 -0
  30. package/lib/appservice/Appservice.d.ts +328 -0
  31. package/lib/appservice/Appservice.js +803 -0
  32. package/lib/appservice/Appservice.js.map +1 -0
  33. package/lib/appservice/Intent.d.ts +113 -0
  34. package/lib/appservice/Intent.js +363 -0
  35. package/lib/appservice/Intent.js.map +1 -0
  36. package/lib/appservice/MatrixBridge.d.ts +85 -0
  37. package/lib/appservice/MatrixBridge.js +111 -0
  38. package/lib/appservice/MatrixBridge.js.map +1 -0
  39. package/lib/appservice/UnstableAppserviceApis.d.ts +41 -0
  40. package/lib/appservice/UnstableAppserviceApis.js +62 -0
  41. package/lib/appservice/UnstableAppserviceApis.js.map +1 -0
  42. package/lib/appservice/http_responses.d.ts +77 -0
  43. package/lib/appservice/http_responses.js +3 -0
  44. package/lib/appservice/http_responses.js.map +1 -0
  45. package/lib/b64.d.ts +42 -0
  46. package/lib/b64.js +68 -0
  47. package/lib/b64.js.map +1 -0
  48. package/lib/e2ee/CrossSigningBootstrap.d.ts +73 -0
  49. package/lib/e2ee/CrossSigningBootstrap.js +86 -0
  50. package/lib/e2ee/CrossSigningBootstrap.js.map +1 -0
  51. package/lib/e2ee/CryptoClient.d.ts +163 -0
  52. package/lib/e2ee/CryptoClient.js +382 -0
  53. package/lib/e2ee/CryptoClient.js.map +1 -0
  54. package/lib/e2ee/ICryptoRoomInformation.d.ts +8 -0
  55. package/lib/e2ee/ICryptoRoomInformation.js +3 -0
  56. package/lib/e2ee/ICryptoRoomInformation.js.map +1 -0
  57. package/lib/e2ee/RoomTracker.d.ts +41 -0
  58. package/lib/e2ee/RoomTracker.js +96 -0
  59. package/lib/e2ee/RoomTracker.js.map +1 -0
  60. package/lib/e2ee/RustEngine.d.ts +149 -0
  61. package/lib/e2ee/RustEngine.js +467 -0
  62. package/lib/e2ee/RustEngine.js.map +1 -0
  63. package/lib/e2ee/decorators.d.ts +10 -0
  64. package/lib/e2ee/decorators.js +37 -0
  65. package/lib/e2ee/decorators.js.map +1 -0
  66. package/lib/helpers/MatrixEntity.d.ts +37 -0
  67. package/lib/helpers/MatrixEntity.js +67 -0
  68. package/lib/helpers/MatrixEntity.js.map +1 -0
  69. package/lib/helpers/MatrixGlob.d.ts +22 -0
  70. package/lib/helpers/MatrixGlob.js +35 -0
  71. package/lib/helpers/MatrixGlob.js.map +1 -0
  72. package/lib/helpers/MentionPill.d.ts +40 -0
  73. package/lib/helpers/MentionPill.js +91 -0
  74. package/lib/helpers/MentionPill.js.map +1 -0
  75. package/lib/helpers/Permalinks.d.ts +58 -0
  76. package/lib/helpers/Permalinks.js +73 -0
  77. package/lib/helpers/Permalinks.js.map +1 -0
  78. package/lib/helpers/ProfileCache.d.ts +48 -0
  79. package/lib/helpers/ProfileCache.js +114 -0
  80. package/lib/helpers/ProfileCache.js.map +1 -0
  81. package/lib/helpers/RichReply.d.ts +17 -0
  82. package/lib/helpers/RichReply.js +47 -0
  83. package/lib/helpers/RichReply.js.map +1 -0
  84. package/lib/helpers/UnpaddedBase64.d.ts +31 -0
  85. package/lib/helpers/UnpaddedBase64.js +45 -0
  86. package/lib/helpers/UnpaddedBase64.js.map +1 -0
  87. package/lib/http.d.ts +17 -0
  88. package/lib/http.js +147 -0
  89. package/lib/http.js.map +1 -0
  90. package/lib/identity/IdentityClient.d.ts +93 -0
  91. package/lib/identity/IdentityClient.js +248 -0
  92. package/lib/identity/IdentityClient.js.map +1 -0
  93. package/lib/index.d.ts +91 -0
  94. package/lib/index.js +125 -0
  95. package/lib/index.js.map +1 -0
  96. package/lib/logging/ConsoleLogger.d.ts +12 -0
  97. package/lib/logging/ConsoleLogger.js +28 -0
  98. package/lib/logging/ConsoleLogger.js.map +1 -0
  99. package/lib/logging/ILogger.d.ts +36 -0
  100. package/lib/logging/ILogger.js +3 -0
  101. package/lib/logging/ILogger.js.map +1 -0
  102. package/lib/logging/LogService.d.ts +100 -0
  103. package/lib/logging/LogService.js +169 -0
  104. package/lib/logging/LogService.js.map +1 -0
  105. package/lib/logging/RichConsoleLogger.d.ts +20 -0
  106. package/lib/logging/RichConsoleLogger.js +41 -0
  107. package/lib/logging/RichConsoleLogger.js.map +1 -0
  108. package/lib/metrics/IMetricListener.d.ts +52 -0
  109. package/lib/metrics/IMetricListener.js +3 -0
  110. package/lib/metrics/IMetricListener.js.map +1 -0
  111. package/lib/metrics/Metrics.d.ts +66 -0
  112. package/lib/metrics/Metrics.js +128 -0
  113. package/lib/metrics/Metrics.js.map +1 -0
  114. package/lib/metrics/contexts.d.ts +51 -0
  115. package/lib/metrics/contexts.js +3 -0
  116. package/lib/metrics/contexts.js.map +1 -0
  117. package/lib/metrics/decorators.d.ts +15 -0
  118. package/lib/metrics/decorators.js +92 -0
  119. package/lib/metrics/decorators.js.map +1 -0
  120. package/lib/metrics/names.d.ts +45 -0
  121. package/lib/metrics/names.js +49 -0
  122. package/lib/metrics/names.js.map +1 -0
  123. package/lib/mixins/AutojoinRoomsMixin.d.ts +10 -0
  124. package/lib/mixins/AutojoinRoomsMixin.js +25 -0
  125. package/lib/mixins/AutojoinRoomsMixin.js.map +1 -0
  126. package/lib/mixins/AutojoinUpgradedRoomsMixin.d.ts +10 -0
  127. package/lib/mixins/AutojoinUpgradedRoomsMixin.js +40 -0
  128. package/lib/mixins/AutojoinUpgradedRoomsMixin.js.map +1 -0
  129. package/lib/models/Account.d.ts +8 -0
  130. package/lib/models/Account.js +3 -0
  131. package/lib/models/Account.js.map +1 -0
  132. package/lib/models/CreateRoom.d.ts +125 -0
  133. package/lib/models/CreateRoom.js +3 -0
  134. package/lib/models/CreateRoom.js.map +1 -0
  135. package/lib/models/Crypto.d.ts +167 -0
  136. package/lib/models/Crypto.js +31 -0
  137. package/lib/models/Crypto.js.map +1 -0
  138. package/lib/models/EventContext.d.ts +19 -0
  139. package/lib/models/EventContext.js +3 -0
  140. package/lib/models/EventContext.js.map +1 -0
  141. package/lib/models/IdentityServerModels.d.ts +20 -0
  142. package/lib/models/IdentityServerModels.js +3 -0
  143. package/lib/models/IdentityServerModels.js.map +1 -0
  144. package/lib/models/MSC2176.d.ts +42 -0
  145. package/lib/models/MSC2176.js +3 -0
  146. package/lib/models/MSC2176.js.map +1 -0
  147. package/lib/models/MatrixError.d.ts +38 -0
  148. package/lib/models/MatrixError.js +30 -0
  149. package/lib/models/MatrixError.js.map +1 -0
  150. package/lib/models/MatrixProfile.d.ts +43 -0
  151. package/lib/models/MatrixProfile.js +43 -0
  152. package/lib/models/MatrixProfile.js.map +1 -0
  153. package/lib/models/OpenIDConnect.d.ts +10 -0
  154. package/lib/models/OpenIDConnect.js +3 -0
  155. package/lib/models/OpenIDConnect.js.map +1 -0
  156. package/lib/models/Policies.d.ts +25 -0
  157. package/lib/models/Policies.js +3 -0
  158. package/lib/models/Policies.js.map +1 -0
  159. package/lib/models/PowerLevelAction.d.ts +27 -0
  160. package/lib/models/PowerLevelAction.js +32 -0
  161. package/lib/models/PowerLevelAction.js.map +1 -0
  162. package/lib/models/PowerLevelBounds.d.ts +15 -0
  163. package/lib/models/PowerLevelBounds.js +3 -0
  164. package/lib/models/PowerLevelBounds.js.map +1 -0
  165. package/lib/models/Presence.d.ts +25 -0
  166. package/lib/models/Presence.js +38 -0
  167. package/lib/models/Presence.js.map +1 -0
  168. package/lib/models/ServerVersions.d.ts +8 -0
  169. package/lib/models/ServerVersions.js +3 -0
  170. package/lib/models/ServerVersions.js.map +1 -0
  171. package/lib/models/Spaces.d.ts +116 -0
  172. package/lib/models/Spaces.js +91 -0
  173. package/lib/models/Spaces.js.map +1 -0
  174. package/lib/models/Threepid.d.ts +8 -0
  175. package/lib/models/Threepid.js +3 -0
  176. package/lib/models/Threepid.js.map +1 -0
  177. package/lib/models/events/AliasesEvent.d.ts +27 -0
  178. package/lib/models/events/AliasesEvent.js +27 -0
  179. package/lib/models/events/AliasesEvent.js.map +1 -0
  180. package/lib/models/events/CanonicalAliasEvent.d.ts +23 -0
  181. package/lib/models/events/CanonicalAliasEvent.js +21 -0
  182. package/lib/models/events/CanonicalAliasEvent.js.map +1 -0
  183. package/lib/models/events/CreateEvent.d.ts +63 -0
  184. package/lib/models/events/CreateEvent.js +33 -0
  185. package/lib/models/events/CreateEvent.js.map +1 -0
  186. package/lib/models/events/EncryptedRoomEvent.d.ts +42 -0
  187. package/lib/models/events/EncryptedRoomEvent.js +28 -0
  188. package/lib/models/events/EncryptedRoomEvent.js.map +1 -0
  189. package/lib/models/events/EncryptionEvent.d.ts +47 -0
  190. package/lib/models/events/EncryptionEvent.js +42 -0
  191. package/lib/models/events/EncryptionEvent.js.map +1 -0
  192. package/lib/models/events/Event.d.ts +26 -0
  193. package/lib/models/events/Event.js +40 -0
  194. package/lib/models/events/Event.js.map +1 -0
  195. package/lib/models/events/EventKind.d.ts +15 -0
  196. package/lib/models/events/EventKind.js +20 -0
  197. package/lib/models/events/EventKind.js.map +1 -0
  198. package/lib/models/events/InvalidEventError.d.ts +14 -0
  199. package/lib/models/events/InvalidEventError.js +24 -0
  200. package/lib/models/events/InvalidEventError.js.map +1 -0
  201. package/lib/models/events/JoinRulesEvent.d.ts +29 -0
  202. package/lib/models/events/JoinRulesEvent.js +21 -0
  203. package/lib/models/events/JoinRulesEvent.js.map +1 -0
  204. package/lib/models/events/MembershipEvent.d.ts +54 -0
  205. package/lib/models/events/MembershipEvent.js +49 -0
  206. package/lib/models/events/MembershipEvent.js.map +1 -0
  207. package/lib/models/events/MessageEvent.d.ts +233 -0
  208. package/lib/models/events/MessageEvent.js +49 -0
  209. package/lib/models/events/MessageEvent.js.map +1 -0
  210. package/lib/models/events/PinnedEventsEvent.d.ts +23 -0
  211. package/lib/models/events/PinnedEventsEvent.js +21 -0
  212. package/lib/models/events/PinnedEventsEvent.js.map +1 -0
  213. package/lib/models/events/PowerLevelsEvent.d.ts +96 -0
  214. package/lib/models/events/PowerLevelsEvent.js +70 -0
  215. package/lib/models/events/PowerLevelsEvent.js.map +1 -0
  216. package/lib/models/events/PresenceEvent.d.ts +56 -0
  217. package/lib/models/events/PresenceEvent.js +21 -0
  218. package/lib/models/events/PresenceEvent.js.map +1 -0
  219. package/lib/models/events/RedactionEvent.d.ts +28 -0
  220. package/lib/models/events/RedactionEvent.js +36 -0
  221. package/lib/models/events/RedactionEvent.js.map +1 -0
  222. package/lib/models/events/RoomAvatarEvent.d.ts +28 -0
  223. package/lib/models/events/RoomAvatarEvent.js +21 -0
  224. package/lib/models/events/RoomAvatarEvent.js.map +1 -0
  225. package/lib/models/events/RoomEvent.d.ts +58 -0
  226. package/lib/models/events/RoomEvent.js +57 -0
  227. package/lib/models/events/RoomEvent.js.map +1 -0
  228. package/lib/models/events/RoomNameEvent.d.ts +20 -0
  229. package/lib/models/events/RoomNameEvent.js +21 -0
  230. package/lib/models/events/RoomNameEvent.js.map +1 -0
  231. package/lib/models/events/RoomTopicEvent.d.ts +20 -0
  232. package/lib/models/events/RoomTopicEvent.js +21 -0
  233. package/lib/models/events/RoomTopicEvent.js.map +1 -0
  234. package/lib/models/events/SpaceChildEvent.d.ts +53 -0
  235. package/lib/models/events/SpaceChildEvent.js +49 -0
  236. package/lib/models/events/SpaceChildEvent.js.map +1 -0
  237. package/lib/models/events/converter.d.ts +8 -0
  238. package/lib/models/events/converter.js +50 -0
  239. package/lib/models/events/converter.js.map +1 -0
  240. package/lib/models/unstable/MediaInfo.d.ts +16 -0
  241. package/lib/models/unstable/MediaInfo.js +3 -0
  242. package/lib/models/unstable/MediaInfo.js.map +1 -0
  243. package/lib/preprocessors/IPreprocessor.d.ts +22 -0
  244. package/lib/preprocessors/IPreprocessor.js +3 -0
  245. package/lib/preprocessors/IPreprocessor.js.map +1 -0
  246. package/lib/preprocessors/RichRepliesPreprocessor.d.ts +67 -0
  247. package/lib/preprocessors/RichRepliesPreprocessor.js +112 -0
  248. package/lib/preprocessors/RichRepliesPreprocessor.js.map +1 -0
  249. package/lib/request.d.ts +13 -0
  250. package/lib/request.js +23 -0
  251. package/lib/request.js.map +1 -0
  252. package/lib/simple-validation.d.ts +10 -0
  253. package/lib/simple-validation.js +30 -0
  254. package/lib/simple-validation.js.map +1 -0
  255. package/lib/storage/IAppserviceStorageProvider.d.ts +48 -0
  256. package/lib/storage/IAppserviceStorageProvider.js +3 -0
  257. package/lib/storage/IAppserviceStorageProvider.js.map +1 -0
  258. package/lib/storage/ICryptoStorageProvider.d.ts +32 -0
  259. package/lib/storage/ICryptoStorageProvider.js +3 -0
  260. package/lib/storage/ICryptoStorageProvider.js.map +1 -0
  261. package/lib/storage/IStorageProvider.d.ts +47 -0
  262. package/lib/storage/IStorageProvider.js +3 -0
  263. package/lib/storage/IStorageProvider.js.map +1 -0
  264. package/lib/storage/MemoryStorageProvider.d.ts +26 -0
  265. package/lib/storage/MemoryStorageProvider.js +55 -0
  266. package/lib/storage/MemoryStorageProvider.js.map +1 -0
  267. package/lib/storage/RustSdkCryptoStorageProvider.d.ts +38 -0
  268. package/lib/storage/RustSdkCryptoStorageProvider.js +69 -0
  269. package/lib/storage/RustSdkCryptoStorageProvider.js.map +1 -0
  270. package/lib/storage/SimpleFsStorageProvider.d.ts +31 -0
  271. package/lib/storage/SimpleFsStorageProvider.js +122 -0
  272. package/lib/storage/SimpleFsStorageProvider.js.map +1 -0
  273. package/lib/storage/SimplePostgresStorageProvider.d.ts +32 -0
  274. package/lib/storage/SimplePostgresStorageProvider.js +148 -0
  275. package/lib/storage/SimplePostgresStorageProvider.js.map +1 -0
  276. package/lib/strategies/AppserviceJoinRoomStrategy.d.ts +14 -0
  277. package/lib/strategies/AppserviceJoinRoomStrategy.js +54 -0
  278. package/lib/strategies/AppserviceJoinRoomStrategy.js.map +1 -0
  279. package/lib/strategies/JoinRoomStrategy.d.ts +11 -0
  280. package/lib/strategies/JoinRoomStrategy.js +44 -0
  281. package/lib/strategies/JoinRoomStrategy.js.map +1 -0
  282. package/package.json +136 -4
  283. package/src/AdminApis.ts +60 -0
  284. package/src/DMs.ts +164 -0
  285. package/src/IFilter.ts +7 -0
  286. package/src/MatrixAuth.ts +129 -0
  287. package/src/MatrixClient.ts +2046 -0
  288. package/src/PantalaimonClient.ts +62 -0
  289. package/src/SynapseAdminApis.ts +482 -0
  290. package/src/SynchronousMatrixClient.ts +129 -0
  291. package/src/UnstableApis.ts +75 -0
  292. package/src/appservice/Appservice.ts +1089 -0
  293. package/src/appservice/Intent.ts +342 -0
  294. package/src/appservice/MatrixBridge.ts +139 -0
  295. package/src/appservice/UnstableAppserviceApis.ts +63 -0
  296. package/src/appservice/http_responses.ts +77 -0
  297. package/src/b64.ts +63 -0
  298. package/src/e2ee/CrossSigningBootstrap.ts +141 -0
  299. package/src/e2ee/CryptoClient.ts +378 -0
  300. package/src/e2ee/ICryptoRoomInformation.ts +9 -0
  301. package/src/e2ee/RoomTracker.ts +99 -0
  302. package/src/e2ee/RustEngine.ts +580 -0
  303. package/src/e2ee/decorators.ts +38 -0
  304. package/src/helpers/MatrixEntity.ts +65 -0
  305. package/src/helpers/MatrixGlob.ts +38 -0
  306. package/src/helpers/MentionPill.ts +95 -0
  307. package/src/helpers/Permalinks.ts +101 -0
  308. package/src/helpers/ProfileCache.ts +119 -0
  309. package/src/helpers/RichReply.ts +46 -0
  310. package/src/helpers/UnpaddedBase64.ts +44 -0
  311. package/src/http.ts +166 -0
  312. package/src/identity/IdentityClient.ts +225 -0
  313. package/src/index.ts +125 -0
  314. package/src/logging/ConsoleLogger.ts +31 -0
  315. package/src/logging/ILogger.ts +40 -0
  316. package/src/logging/LogService.ts +167 -0
  317. package/src/logging/RichConsoleLogger.ts +70 -0
  318. package/src/metrics/IMetricListener.ts +57 -0
  319. package/src/metrics/Metrics.ts +134 -0
  320. package/src/metrics/contexts.ts +56 -0
  321. package/src/metrics/decorators.ts +94 -0
  322. package/src/metrics/names.ts +53 -0
  323. package/src/mixins/AutojoinRoomsMixin.ts +24 -0
  324. package/src/mixins/AutojoinUpgradedRoomsMixin.ts +37 -0
  325. package/src/models/Account.ts +8 -0
  326. package/src/models/CreateRoom.ts +144 -0
  327. package/src/models/Crypto.ts +188 -0
  328. package/src/models/EventContext.ts +23 -0
  329. package/src/models/IdentityServerModels.ts +18 -0
  330. package/src/models/MSC2176.ts +47 -0
  331. package/src/models/MatrixError.ts +39 -0
  332. package/src/models/MatrixProfile.ts +55 -0
  333. package/src/models/OpenIDConnect.ts +10 -0
  334. package/src/models/Policies.ts +28 -0
  335. package/src/models/PowerLevelAction.ts +31 -0
  336. package/src/models/PowerLevelBounds.ts +16 -0
  337. package/src/models/Presence.ts +38 -0
  338. package/src/models/ServerVersions.ts +8 -0
  339. package/src/models/Spaces.ts +167 -0
  340. package/src/models/Threepid.ts +8 -0
  341. package/src/models/events/AliasesEvent.ts +37 -0
  342. package/src/models/events/CanonicalAliasEvent.ts +30 -0
  343. package/src/models/events/CreateEvent.ts +82 -0
  344. package/src/models/events/EncryptedRoomEvent.ts +58 -0
  345. package/src/models/events/EncryptionEvent.ts +63 -0
  346. package/src/models/events/Event.ts +38 -0
  347. package/src/models/events/EventKind.ts +16 -0
  348. package/src/models/events/InvalidEventError.ts +19 -0
  349. package/src/models/events/JoinRulesEvent.ts +37 -0
  350. package/src/models/events/MembershipEvent.ts +77 -0
  351. package/src/models/events/MessageEvent.ts +292 -0
  352. package/src/models/events/PinnedEventsEvent.ts +30 -0
  353. package/src/models/events/PowerLevelsEvent.ts +135 -0
  354. package/src/models/events/PresenceEvent.ts +69 -0
  355. package/src/models/events/RedactionEvent.ts +44 -0
  356. package/src/models/events/RoomAvatarEvent.ts +36 -0
  357. package/src/models/events/RoomEvent.ts +83 -0
  358. package/src/models/events/RoomNameEvent.ts +27 -0
  359. package/src/models/events/RoomTopicEvent.ts +27 -0
  360. package/src/models/events/SpaceChildEvent.ts +74 -0
  361. package/src/models/events/_MissingEvents.md +35 -0
  362. package/src/models/events/converter.ts +47 -0
  363. package/src/models/unstable/MediaInfo.ts +16 -0
  364. package/src/preprocessors/IPreprocessor.ts +24 -0
  365. package/src/preprocessors/RichRepliesPreprocessor.ts +159 -0
  366. package/src/request.ts +21 -0
  367. package/src/simple-validation.ts +30 -0
  368. package/src/storage/IAppserviceStorageProvider.ts +54 -0
  369. package/src/storage/ICryptoStorageProvider.ts +36 -0
  370. package/src/storage/IStorageProvider.ts +53 -0
  371. package/src/storage/MemoryStorageProvider.ts +65 -0
  372. package/src/storage/RustSdkCryptoStorageProvider.ts +81 -0
  373. package/src/storage/SimpleFsStorageProvider.ts +142 -0
  374. package/src/storage/SimplePostgresStorageProvider.ts +168 -0
  375. package/src/strategies/AppserviceJoinRoomStrategy.ts +47 -0
  376. package/src/strategies/JoinRoomStrategy.ts +45 -0
  377. 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;IACh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AC,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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AAM,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":";;;AAAA,iCAAiC;AAEjC,0BAAkF;AAClF,sEAAmE;AAKnE;;;;;GAKG;AACH,MAAa,YAAY;IAGrB;;;;;OAKG;IACH,YAAY,UAAkB,EAAE,QAAgB,EAAU,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QAC1E,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;YAC1B,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,QAAQ;SAChB,CAAC,CAAC;IACP,CAAC;IAEO,WAAW,CAAC,MAAc,EAAE,MAAqB;QACrD,OAAO,GAAG,MAAM,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;I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AAW,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QACzE,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,iBAAa,CAAC,WAAW,CAAC,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QACpG,CAAC;QAED,wDAAwD;QACxD,0GAA0G;QAC1G,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;YAClC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACvF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;CACJ;AAxGD,oCAwGC"}
@@ -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"}