@textrp/briij-js-sdk 41.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1104) hide show
  1. package/CHANGELOG.md +6464 -0
  2. package/LICENSE +177 -0
  3. package/README.md +477 -0
  4. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts +14 -0
  5. package/lib/@types/AESEncryptedSecretStoragePayload.d.ts.map +1 -0
  6. package/lib/@types/AESEncryptedSecretStoragePayload.js +1 -0
  7. package/lib/@types/AESEncryptedSecretStoragePayload.js.map +1 -0
  8. package/lib/@types/IIdentityServerProvider.d.ts +9 -0
  9. package/lib/@types/IIdentityServerProvider.d.ts.map +1 -0
  10. package/lib/@types/IIdentityServerProvider.js +1 -0
  11. package/lib/@types/IIdentityServerProvider.js.map +1 -0
  12. package/lib/@types/PushRules.d.ts +140 -0
  13. package/lib/@types/PushRules.d.ts.map +1 -0
  14. package/lib/@types/PushRules.js +94 -0
  15. package/lib/@types/PushRules.js.map +1 -0
  16. package/lib/@types/another-json.d.js +0 -0
  17. package/lib/@types/another-json.d.js.map +1 -0
  18. package/lib/@types/auth.d.ts +213 -0
  19. package/lib/@types/auth.d.ts.map +1 -0
  20. package/lib/@types/auth.js +107 -0
  21. package/lib/@types/auth.js.map +1 -0
  22. package/lib/@types/beacon.d.ts +106 -0
  23. package/lib/@types/beacon.d.ts.map +1 -0
  24. package/lib/@types/beacon.js +119 -0
  25. package/lib/@types/beacon.js.map +1 -0
  26. package/lib/@types/common.d.ts +10 -0
  27. package/lib/@types/common.d.ts.map +1 -0
  28. package/lib/@types/common.js +1 -0
  29. package/lib/@types/common.js.map +1 -0
  30. package/lib/@types/crypto.d.ts +46 -0
  31. package/lib/@types/crypto.d.ts.map +1 -0
  32. package/lib/@types/crypto.js +1 -0
  33. package/lib/@types/crypto.js.map +1 -0
  34. package/lib/@types/event.d.ts +356 -0
  35. package/lib/@types/event.d.ts.map +1 -0
  36. package/lib/@types/event.js +280 -0
  37. package/lib/@types/event.js.map +1 -0
  38. package/lib/@types/events.d.ts +92 -0
  39. package/lib/@types/events.d.ts.map +1 -0
  40. package/lib/@types/events.js +1 -0
  41. package/lib/@types/events.js.map +1 -0
  42. package/lib/@types/extensible_events.d.ts +98 -0
  43. package/lib/@types/extensible_events.d.ts.map +1 -0
  44. package/lib/@types/extensible_events.js +116 -0
  45. package/lib/@types/extensible_events.js.map +1 -0
  46. package/lib/@types/global.d.js +18 -0
  47. package/lib/@types/global.d.js.map +1 -0
  48. package/lib/@types/local_notifications.d.ts +4 -0
  49. package/lib/@types/local_notifications.d.ts.map +1 -0
  50. package/lib/@types/local_notifications.js +1 -0
  51. package/lib/@types/local_notifications.js.map +1 -0
  52. package/lib/@types/location.d.ts +60 -0
  53. package/lib/@types/location.d.ts.map +1 -0
  54. package/lib/@types/location.js +66 -0
  55. package/lib/@types/location.js.map +1 -0
  56. package/lib/@types/matrix-sdk-crypto-wasm.d.js +1 -0
  57. package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -0
  58. package/lib/@types/media.d.ts +220 -0
  59. package/lib/@types/media.d.ts.map +1 -0
  60. package/lib/@types/media.js +1 -0
  61. package/lib/@types/media.js.map +1 -0
  62. package/lib/@types/membership.d.ts +41 -0
  63. package/lib/@types/membership.d.ts.map +1 -0
  64. package/lib/@types/membership.js +58 -0
  65. package/lib/@types/membership.js.map +1 -0
  66. package/lib/@types/partials.d.ts +72 -0
  67. package/lib/@types/partials.d.ts.map +1 -0
  68. package/lib/@types/partials.js +71 -0
  69. package/lib/@types/partials.js.map +1 -0
  70. package/lib/@types/polls.d.ts +89 -0
  71. package/lib/@types/polls.d.ts.map +1 -0
  72. package/lib/@types/polls.js +86 -0
  73. package/lib/@types/polls.js.map +1 -0
  74. package/lib/@types/read_receipts.d.ts +36 -0
  75. package/lib/@types/read_receipts.d.ts.map +1 -0
  76. package/lib/@types/read_receipts.js +27 -0
  77. package/lib/@types/read_receipts.js.map +1 -0
  78. package/lib/@types/registration.d.ts +85 -0
  79. package/lib/@types/registration.d.ts.map +1 -0
  80. package/lib/@types/registration.js +1 -0
  81. package/lib/@types/registration.js.map +1 -0
  82. package/lib/@types/requests.d.ts +267 -0
  83. package/lib/@types/requests.d.ts.map +1 -0
  84. package/lib/@types/requests.js +42 -0
  85. package/lib/@types/requests.js.map +1 -0
  86. package/lib/@types/search.d.ts +90 -0
  87. package/lib/@types/search.d.ts.map +1 -0
  88. package/lib/@types/search.js +30 -0
  89. package/lib/@types/search.js.map +1 -0
  90. package/lib/@types/signed.d.ts +9 -0
  91. package/lib/@types/signed.d.ts.map +1 -0
  92. package/lib/@types/signed.js +1 -0
  93. package/lib/@types/signed.js.map +1 -0
  94. package/lib/@types/spaces.d.ts +16 -0
  95. package/lib/@types/spaces.d.ts.map +1 -0
  96. package/lib/@types/spaces.js +1 -0
  97. package/lib/@types/spaces.js.map +1 -0
  98. package/lib/@types/state_events.d.ts +121 -0
  99. package/lib/@types/state_events.d.ts.map +1 -0
  100. package/lib/@types/state_events.js +1 -0
  101. package/lib/@types/state_events.js.map +1 -0
  102. package/lib/@types/synapse.d.ts +19 -0
  103. package/lib/@types/synapse.d.ts.map +1 -0
  104. package/lib/@types/synapse.js +1 -0
  105. package/lib/@types/synapse.js.map +1 -0
  106. package/lib/@types/sync.d.ts +8 -0
  107. package/lib/@types/sync.d.ts.map +1 -0
  108. package/lib/@types/sync.js +25 -0
  109. package/lib/@types/sync.js.map +1 -0
  110. package/lib/@types/threepids.d.ts +12 -0
  111. package/lib/@types/threepids.d.ts.map +1 -0
  112. package/lib/@types/threepids.js +24 -0
  113. package/lib/@types/threepids.js.map +1 -0
  114. package/lib/@types/topic.d.ts +55 -0
  115. package/lib/@types/topic.d.ts.map +1 -0
  116. package/lib/@types/topic.js +62 -0
  117. package/lib/@types/topic.js.map +1 -0
  118. package/lib/@types/uia.d.ts +8 -0
  119. package/lib/@types/uia.d.ts.map +1 -0
  120. package/lib/@types/uia.js +1 -0
  121. package/lib/@types/uia.js.map +1 -0
  122. package/lib/NamespacedValue.d.ts +32 -0
  123. package/lib/NamespacedValue.d.ts.map +1 -0
  124. package/lib/NamespacedValue.js +113 -0
  125. package/lib/NamespacedValue.js.map +1 -0
  126. package/lib/ReEmitter.d.ts +15 -0
  127. package/lib/ReEmitter.d.ts.map +1 -0
  128. package/lib/ReEmitter.js +87 -0
  129. package/lib/ReEmitter.js.map +1 -0
  130. package/lib/ToDeviceMessageQueue.d.ts +30 -0
  131. package/lib/ToDeviceMessageQueue.d.ts.map +1 -0
  132. package/lib/ToDeviceMessageQueue.js +135 -0
  133. package/lib/ToDeviceMessageQueue.js.map +1 -0
  134. package/lib/autodiscovery.d.ts +136 -0
  135. package/lib/autodiscovery.d.ts.map +1 -0
  136. package/lib/autodiscovery.js +464 -0
  137. package/lib/autodiscovery.js.map +1 -0
  138. package/lib/base64.d.ts +25 -0
  139. package/lib/base64.d.ts.map +1 -0
  140. package/lib/base64.js +95 -0
  141. package/lib/base64.js.map +1 -0
  142. package/lib/briij.d.ts +116 -0
  143. package/lib/briij.d.ts.map +1 -0
  144. package/lib/briij.js +145 -0
  145. package/lib/briij.js.map +1 -0
  146. package/lib/browser-index.d.ts +8 -0
  147. package/lib/browser-index.d.ts.map +1 -0
  148. package/lib/browser-index.js +35 -0
  149. package/lib/browser-index.js.map +1 -0
  150. package/lib/client.d.ts +3493 -0
  151. package/lib/client.d.ts.map +1 -0
  152. package/lib/client.js +7482 -0
  153. package/lib/client.js.map +1 -0
  154. package/lib/common-crypto/CryptoBackend.d.ts +234 -0
  155. package/lib/common-crypto/CryptoBackend.d.ts.map +1 -0
  156. package/lib/common-crypto/CryptoBackend.js +69 -0
  157. package/lib/common-crypto/CryptoBackend.js.map +1 -0
  158. package/lib/common-crypto/key-passphrase.d.ts +14 -0
  159. package/lib/common-crypto/key-passphrase.d.ts.map +1 -0
  160. package/lib/common-crypto/key-passphrase.js +33 -0
  161. package/lib/common-crypto/key-passphrase.js.map +1 -0
  162. package/lib/content-helpers.d.ts +90 -0
  163. package/lib/content-helpers.d.ts.map +1 -0
  164. package/lib/content-helpers.js +262 -0
  165. package/lib/content-helpers.js.map +1 -0
  166. package/lib/content-repo.d.ts +25 -0
  167. package/lib/content-repo.d.ts.map +1 -0
  168. package/lib/content-repo.js +109 -0
  169. package/lib/content-repo.js.map +1 -0
  170. package/lib/crypto/store/base.d.ts +301 -0
  171. package/lib/crypto/store/base.d.ts.map +1 -0
  172. package/lib/crypto/store/base.js +145 -0
  173. package/lib/crypto/store/base.js.map +1 -0
  174. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts +94 -0
  175. package/lib/crypto/store/indexeddb-crypto-store-backend.d.ts.map +1 -0
  176. package/lib/crypto/store/indexeddb-crypto-store-backend.js +604 -0
  177. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -0
  178. package/lib/crypto/store/indexeddb-crypto-store.d.ts +251 -0
  179. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +1 -0
  180. package/lib/crypto/store/indexeddb-crypto-store.js +477 -0
  181. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -0
  182. package/lib/crypto/store/localStorage-crypto-store.d.ts +102 -0
  183. package/lib/crypto/store/localStorage-crypto-store.d.ts.map +1 -0
  184. package/lib/crypto/store/localStorage-crypto-store.js +374 -0
  185. package/lib/crypto/store/localStorage-crypto-store.js.map +1 -0
  186. package/lib/crypto/store/memory-crypto-store.d.ts +117 -0
  187. package/lib/crypto/store/memory-crypto-store.d.ts.map +1 -0
  188. package/lib/crypto/store/memory-crypto-store.js +311 -0
  189. package/lib/crypto/store/memory-crypto-store.js.map +1 -0
  190. package/lib/crypto-api/CryptoEvent.d.ts +120 -0
  191. package/lib/crypto-api/CryptoEvent.d.ts.map +1 -0
  192. package/lib/crypto-api/CryptoEvent.js +137 -0
  193. package/lib/crypto-api/CryptoEvent.js.map +1 -0
  194. package/lib/crypto-api/CryptoEventHandlerMap.d.ts +26 -0
  195. package/lib/crypto-api/CryptoEventHandlerMap.d.ts.map +1 -0
  196. package/lib/crypto-api/CryptoEventHandlerMap.js +1 -0
  197. package/lib/crypto-api/CryptoEventHandlerMap.js.map +1 -0
  198. package/lib/crypto-api/index.d.ts +1160 -0
  199. package/lib/crypto-api/index.d.ts.map +1 -0
  200. package/lib/crypto-api/index.js +410 -0
  201. package/lib/crypto-api/index.js.map +1 -0
  202. package/lib/crypto-api/key-passphrase.d.ts +11 -0
  203. package/lib/crypto-api/key-passphrase.d.ts.map +1 -0
  204. package/lib/crypto-api/key-passphrase.js +51 -0
  205. package/lib/crypto-api/key-passphrase.js.map +1 -0
  206. package/lib/crypto-api/keybackup.d.ts +87 -0
  207. package/lib/crypto-api/keybackup.d.ts.map +1 -0
  208. package/lib/crypto-api/keybackup.js +1 -0
  209. package/lib/crypto-api/keybackup.js.map +1 -0
  210. package/lib/crypto-api/recovery-key.d.ts +11 -0
  211. package/lib/crypto-api/recovery-key.d.ts.map +1 -0
  212. package/lib/crypto-api/recovery-key.js +65 -0
  213. package/lib/crypto-api/recovery-key.js.map +1 -0
  214. package/lib/crypto-api/verification.d.ts +315 -0
  215. package/lib/crypto-api/verification.d.ts.map +1 -0
  216. package/lib/crypto-api/verification.js +130 -0
  217. package/lib/crypto-api/verification.js.map +1 -0
  218. package/lib/digest.d.ts +10 -0
  219. package/lib/digest.d.ts.map +1 -0
  220. package/lib/digest.js +40 -0
  221. package/lib/digest.js.map +1 -0
  222. package/lib/embedded.d.ts +182 -0
  223. package/lib/embedded.d.ts.map +1 -0
  224. package/lib/embedded.js +746 -0
  225. package/lib/embedded.js.map +1 -0
  226. package/lib/errors.d.ts +38 -0
  227. package/lib/errors.d.ts.map +1 -0
  228. package/lib/errors.js +73 -0
  229. package/lib/errors.js.map +1 -0
  230. package/lib/event-mapper.d.ts +9 -0
  231. package/lib/event-mapper.d.ts.map +1 -0
  232. package/lib/event-mapper.js +74 -0
  233. package/lib/event-mapper.js.map +1 -0
  234. package/lib/extensible_events_v1/ExtensibleEvent.d.ts +38 -0
  235. package/lib/extensible_events_v1/ExtensibleEvent.d.ts.map +1 -0
  236. package/lib/extensible_events_v1/ExtensibleEvent.js +57 -0
  237. package/lib/extensible_events_v1/ExtensibleEvent.js.map +1 -0
  238. package/lib/extensible_events_v1/InvalidEventError.d.ts +7 -0
  239. package/lib/extensible_events_v1/InvalidEventError.d.ts.map +1 -0
  240. package/lib/extensible_events_v1/InvalidEventError.js +25 -0
  241. package/lib/extensible_events_v1/InvalidEventError.js.map +1 -0
  242. package/lib/extensible_events_v1/MessageEvent.d.ts +44 -0
  243. package/lib/extensible_events_v1/MessageEvent.d.ts.map +1 -0
  244. package/lib/extensible_events_v1/MessageEvent.js +134 -0
  245. package/lib/extensible_events_v1/MessageEvent.js.map +1 -0
  246. package/lib/extensible_events_v1/PollEndEvent.d.ts +33 -0
  247. package/lib/extensible_events_v1/PollEndEvent.d.ts.map +1 -0
  248. package/lib/extensible_events_v1/PollEndEvent.js +88 -0
  249. package/lib/extensible_events_v1/PollEndEvent.js.map +1 -0
  250. package/lib/extensible_events_v1/PollResponseEvent.d.ts +49 -0
  251. package/lib/extensible_events_v1/PollResponseEvent.d.ts.map +1 -0
  252. package/lib/extensible_events_v1/PollResponseEvent.js +135 -0
  253. package/lib/extensible_events_v1/PollResponseEvent.js.map +1 -0
  254. package/lib/extensible_events_v1/PollStartEvent.d.ts +71 -0
  255. package/lib/extensible_events_v1/PollStartEvent.d.ts.map +1 -0
  256. package/lib/extensible_events_v1/PollStartEvent.js +185 -0
  257. package/lib/extensible_events_v1/PollStartEvent.js.map +1 -0
  258. package/lib/extensible_events_v1/utilities.d.ts +14 -0
  259. package/lib/extensible_events_v1/utilities.d.ts.map +1 -0
  260. package/lib/extensible_events_v1/utilities.js +34 -0
  261. package/lib/extensible_events_v1/utilities.js.map +1 -0
  262. package/lib/feature.d.ts +20 -0
  263. package/lib/feature.d.ts.map +1 -0
  264. package/lib/feature.js +89 -0
  265. package/lib/feature.js.map +1 -0
  266. package/lib/filter-component.d.ts +64 -0
  267. package/lib/filter-component.d.ts.map +1 -0
  268. package/lib/filter-component.js +170 -0
  269. package/lib/filter-component.js.map +1 -0
  270. package/lib/filter.d.ts +97 -0
  271. package/lib/filter.d.ts.map +1 -0
  272. package/lib/filter.js +207 -0
  273. package/lib/filter.js.map +1 -0
  274. package/lib/http-api/errors.d.ts +117 -0
  275. package/lib/http-api/errors.d.ts.map +1 -0
  276. package/lib/http-api/errors.js +245 -0
  277. package/lib/http-api/errors.js.map +1 -0
  278. package/lib/http-api/fetch.d.ts +80 -0
  279. package/lib/http-api/fetch.d.ts.map +1 -0
  280. package/lib/http-api/fetch.js +332 -0
  281. package/lib/http-api/fetch.js.map +1 -0
  282. package/lib/http-api/index.d.ts +33 -0
  283. package/lib/http-api/index.d.ts.map +1 -0
  284. package/lib/http-api/index.js +178 -0
  285. package/lib/http-api/index.js.map +1 -0
  286. package/lib/http-api/interface.d.ts +186 -0
  287. package/lib/http-api/interface.d.ts.map +1 -0
  288. package/lib/http-api/interface.js +39 -0
  289. package/lib/http-api/interface.js.map +1 -0
  290. package/lib/http-api/method.d.ts +10 -0
  291. package/lib/http-api/method.d.ts.map +1 -0
  292. package/lib/http-api/method.js +27 -0
  293. package/lib/http-api/method.js.map +1 -0
  294. package/lib/http-api/prefix.d.ts +31 -0
  295. package/lib/http-api/prefix.d.ts.map +1 -0
  296. package/lib/http-api/prefix.js +50 -0
  297. package/lib/http-api/prefix.js.map +1 -0
  298. package/lib/http-api/refresh.d.ts +53 -0
  299. package/lib/http-api/refresh.d.ts.map +1 -0
  300. package/lib/http-api/refresh.js +174 -0
  301. package/lib/http-api/refresh.js.map +1 -0
  302. package/lib/http-api/utils.d.ts +37 -0
  303. package/lib/http-api/utils.d.ts.map +1 -0
  304. package/lib/http-api/utils.js +182 -0
  305. package/lib/http-api/utils.js.map +1 -0
  306. package/lib/index.d.ts +4 -0
  307. package/lib/index.d.ts.map +1 -0
  308. package/lib/index.js +24 -0
  309. package/lib/index.js.map +1 -0
  310. package/lib/indexeddb-helpers.d.ts +10 -0
  311. package/lib/indexeddb-helpers.d.ts.map +1 -0
  312. package/lib/indexeddb-helpers.js +51 -0
  313. package/lib/indexeddb-helpers.js.map +1 -0
  314. package/lib/indexeddb-worker.d.ts +7 -0
  315. package/lib/indexeddb-worker.d.ts.map +1 -0
  316. package/lib/indexeddb-worker.js +25 -0
  317. package/lib/indexeddb-worker.js.map +1 -0
  318. package/lib/interactive-auth.d.ts +341 -0
  319. package/lib/interactive-auth.d.ts.map +1 -0
  320. package/lib/interactive-auth.js +563 -0
  321. package/lib/interactive-auth.js.map +1 -0
  322. package/lib/logger.d.ts +124 -0
  323. package/lib/logger.d.ts.map +1 -0
  324. package/lib/logger.js +230 -0
  325. package/lib/logger.js.map +1 -0
  326. package/lib/matrixrtc/CallMembership.d.ts +154 -0
  327. package/lib/matrixrtc/CallMembership.d.ts.map +1 -0
  328. package/lib/matrixrtc/CallMembership.js +469 -0
  329. package/lib/matrixrtc/CallMembership.js.map +1 -0
  330. package/lib/matrixrtc/EncryptionManager.d.ts +44 -0
  331. package/lib/matrixrtc/EncryptionManager.d.ts.map +1 -0
  332. package/lib/matrixrtc/EncryptionManager.js +13 -0
  333. package/lib/matrixrtc/EncryptionManager.js.map +1 -0
  334. package/lib/matrixrtc/IKeyTransport.d.ts +37 -0
  335. package/lib/matrixrtc/IKeyTransport.d.ts.map +1 -0
  336. package/lib/matrixrtc/IKeyTransport.js +27 -0
  337. package/lib/matrixrtc/IKeyTransport.js.map +1 -0
  338. package/lib/matrixrtc/IMembershipManager.d.ts +94 -0
  339. package/lib/matrixrtc/IMembershipManager.d.ts.map +1 -0
  340. package/lib/matrixrtc/IMembershipManager.js +40 -0
  341. package/lib/matrixrtc/IMembershipManager.js.map +1 -0
  342. package/lib/matrixrtc/LivekitTransport.d.ts +23 -0
  343. package/lib/matrixrtc/LivekitTransport.d.ts.map +1 -0
  344. package/lib/matrixrtc/LivekitTransport.js +29 -0
  345. package/lib/matrixrtc/LivekitTransport.js.map +1 -0
  346. package/lib/matrixrtc/MatrixRTCSession.d.ts +343 -0
  347. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -0
  348. package/lib/matrixrtc/MatrixRTCSession.js +623 -0
  349. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -0
  350. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +46 -0
  351. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +1 -0
  352. package/lib/matrixrtc/MatrixRTCSessionManager.js +149 -0
  353. package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -0
  354. package/lib/matrixrtc/MembershipManager.d.ts +210 -0
  355. package/lib/matrixrtc/MembershipManager.d.ts.map +1 -0
  356. package/lib/matrixrtc/MembershipManager.js +977 -0
  357. package/lib/matrixrtc/MembershipManager.js.map +1 -0
  358. package/lib/matrixrtc/MembershipManagerActionScheduler.d.ts +59 -0
  359. package/lib/matrixrtc/MembershipManagerActionScheduler.d.ts.map +1 -0
  360. package/lib/matrixrtc/MembershipManagerActionScheduler.js +125 -0
  361. package/lib/matrixrtc/MembershipManagerActionScheduler.js.map +1 -0
  362. package/lib/matrixrtc/RTCEncryptionManager.d.ts +110 -0
  363. package/lib/matrixrtc/RTCEncryptionManager.d.ts.map +1 -0
  364. package/lib/matrixrtc/RTCEncryptionManager.js +376 -0
  365. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -0
  366. package/lib/matrixrtc/ToDeviceKeyTransport.d.ts +30 -0
  367. package/lib/matrixrtc/ToDeviceKeyTransport.d.ts.map +1 -0
  368. package/lib/matrixrtc/ToDeviceKeyTransport.js +164 -0
  369. package/lib/matrixrtc/ToDeviceKeyTransport.js.map +1 -0
  370. package/lib/matrixrtc/index.d.ts +9 -0
  371. package/lib/matrixrtc/index.d.ts.map +1 -0
  372. package/lib/matrixrtc/index.js +23 -0
  373. package/lib/matrixrtc/index.js.map +1 -0
  374. package/lib/matrixrtc/membershipData/common.d.ts +8 -0
  375. package/lib/matrixrtc/membershipData/common.d.ts.map +1 -0
  376. package/lib/matrixrtc/membershipData/common.js +26 -0
  377. package/lib/matrixrtc/membershipData/common.js.map +1 -0
  378. package/lib/matrixrtc/membershipData/index.d.ts +4 -0
  379. package/lib/matrixrtc/membershipData/index.d.ts.map +1 -0
  380. package/lib/matrixrtc/membershipData/index.js +20 -0
  381. package/lib/matrixrtc/membershipData/index.js.map +1 -0
  382. package/lib/matrixrtc/membershipData/rtc.d.ts +33 -0
  383. package/lib/matrixrtc/membershipData/rtc.d.ts.map +1 -0
  384. package/lib/matrixrtc/membershipData/rtc.js +137 -0
  385. package/lib/matrixrtc/membershipData/rtc.js.map +1 -0
  386. package/lib/matrixrtc/membershipData/session.d.ts +77 -0
  387. package/lib/matrixrtc/membershipData/session.d.ts.map +1 -0
  388. package/lib/matrixrtc/membershipData/session.js +62 -0
  389. package/lib/matrixrtc/membershipData/session.js.map +1 -0
  390. package/lib/matrixrtc/types.d.ts +169 -0
  391. package/lib/matrixrtc/types.d.ts.map +1 -0
  392. package/lib/matrixrtc/types.js +117 -0
  393. package/lib/matrixrtc/types.js.map +1 -0
  394. package/lib/matrixrtc/utils.d.ts +27 -0
  395. package/lib/matrixrtc/utils.d.ts.map +1 -0
  396. package/lib/matrixrtc/utils.js +72 -0
  397. package/lib/matrixrtc/utils.js.map +1 -0
  398. package/lib/models/MSC3089Branch.d.ts +98 -0
  399. package/lib/models/MSC3089Branch.d.ts.map +1 -0
  400. package/lib/models/MSC3089Branch.js +240 -0
  401. package/lib/models/MSC3089Branch.js.map +1 -0
  402. package/lib/models/MSC3089TreeSpace.d.ts +166 -0
  403. package/lib/models/MSC3089TreeSpace.d.ts.map +1 -0
  404. package/lib/models/MSC3089TreeSpace.js +521 -0
  405. package/lib/models/MSC3089TreeSpace.js.map +1 -0
  406. package/lib/models/ToDeviceMessage.d.ts +17 -0
  407. package/lib/models/ToDeviceMessage.d.ts.map +1 -0
  408. package/lib/models/ToDeviceMessage.js +1 -0
  409. package/lib/models/ToDeviceMessage.js.map +1 -0
  410. package/lib/models/beacon.d.ts +52 -0
  411. package/lib/models/beacon.d.ts.map +1 -0
  412. package/lib/models/beacon.js +174 -0
  413. package/lib/models/beacon.js.map +1 -0
  414. package/lib/models/compare-event-ordering.d.ts +24 -0
  415. package/lib/models/compare-event-ordering.d.ts.map +1 -0
  416. package/lib/models/compare-event-ordering.js +120 -0
  417. package/lib/models/compare-event-ordering.js.map +1 -0
  418. package/lib/models/device.d.ts +45 -0
  419. package/lib/models/device.d.ts.map +1 -0
  420. package/lib/models/device.js +77 -0
  421. package/lib/models/device.js.map +1 -0
  422. package/lib/models/event-context.d.ts +62 -0
  423. package/lib/models/event-context.d.ts.map +1 -0
  424. package/lib/models/event-context.js +113 -0
  425. package/lib/models/event-context.js.map +1 -0
  426. package/lib/models/event-status.d.ts +19 -0
  427. package/lib/models/event-status.d.ts.map +1 -0
  428. package/lib/models/event-status.js +36 -0
  429. package/lib/models/event-status.js.map +1 -0
  430. package/lib/models/event-timeline-set.d.ts +308 -0
  431. package/lib/models/event-timeline-set.d.ts.map +1 -0
  432. package/lib/models/event-timeline-set.js +805 -0
  433. package/lib/models/event-timeline-set.js.map +1 -0
  434. package/lib/models/event-timeline.d.ts +224 -0
  435. package/lib/models/event-timeline.d.ts.map +1 -0
  436. package/lib/models/event-timeline.js +434 -0
  437. package/lib/models/event-timeline.js.map +1 -0
  438. package/lib/models/event.d.ts +844 -0
  439. package/lib/models/event.d.ts.map +1 -0
  440. package/lib/models/event.js +1600 -0
  441. package/lib/models/event.js.map +1 -0
  442. package/lib/models/invites-ignorer-types.d.ts +27 -0
  443. package/lib/models/invites-ignorer-types.d.ts.map +1 -0
  444. package/lib/models/invites-ignorer-types.js +56 -0
  445. package/lib/models/invites-ignorer-types.js.map +1 -0
  446. package/lib/models/invites-ignorer.d.ts +112 -0
  447. package/lib/models/invites-ignorer.d.ts.map +1 -0
  448. package/lib/models/invites-ignorer.js +357 -0
  449. package/lib/models/invites-ignorer.js.map +1 -0
  450. package/lib/models/poll.d.ts +67 -0
  451. package/lib/models/poll.d.ts.map +1 -0
  452. package/lib/models/poll.js +241 -0
  453. package/lib/models/poll.js.map +1 -0
  454. package/lib/models/profile-keys.d.ts +17 -0
  455. package/lib/models/profile-keys.d.ts.map +1 -0
  456. package/lib/models/profile-keys.js +34 -0
  457. package/lib/models/profile-keys.js.map +1 -0
  458. package/lib/models/read-receipt.d.ts +115 -0
  459. package/lib/models/read-receipt.d.ts.map +1 -0
  460. package/lib/models/read-receipt.js +366 -0
  461. package/lib/models/read-receipt.js.map +1 -0
  462. package/lib/models/related-relations.d.ts +11 -0
  463. package/lib/models/related-relations.d.ts.map +1 -0
  464. package/lib/models/related-relations.js +33 -0
  465. package/lib/models/related-relations.js.map +1 -0
  466. package/lib/models/relations-container.d.ts +44 -0
  467. package/lib/models/relations-container.d.ts.map +1 -0
  468. package/lib/models/relations-container.js +132 -0
  469. package/lib/models/relations-container.js.map +1 -0
  470. package/lib/models/relations.d.ts +123 -0
  471. package/lib/models/relations.d.ts.map +1 -0
  472. package/lib/models/relations.js +378 -0
  473. package/lib/models/relations.js.map +1 -0
  474. package/lib/models/room-member.d.ts +221 -0
  475. package/lib/models/room-member.d.ts.map +1 -0
  476. package/lib/models/room-member.js +376 -0
  477. package/lib/models/room-member.js.map +1 -0
  478. package/lib/models/room-receipts.d.ts +39 -0
  479. package/lib/models/room-receipts.d.ts.map +1 -0
  480. package/lib/models/room-receipts.js +392 -0
  481. package/lib/models/room-receipts.js.map +1 -0
  482. package/lib/models/room-state.d.ts +463 -0
  483. package/lib/models/room-state.d.ts.map +1 -0
  484. package/lib/models/room-state.js +1066 -0
  485. package/lib/models/room-state.js.map +1 -0
  486. package/lib/models/room-sticky-events.d.ts +110 -0
  487. package/lib/models/room-sticky-events.d.ts.map +1 -0
  488. package/lib/models/room-sticky-events.js +353 -0
  489. package/lib/models/room-sticky-events.js.map +1 -0
  490. package/lib/models/room-summary.d.ts +59 -0
  491. package/lib/models/room-summary.d.ts.map +1 -0
  492. package/lib/models/room-summary.js +39 -0
  493. package/lib/models/room-summary.js.map +1 -0
  494. package/lib/models/room.d.ts +1285 -0
  495. package/lib/models/room.d.ts.map +1 -0
  496. package/lib/models/room.js +3548 -0
  497. package/lib/models/room.js.map +1 -0
  498. package/lib/models/search-result.d.ts +20 -0
  499. package/lib/models/search-result.d.ts.map +1 -0
  500. package/lib/models/search-result.js +52 -0
  501. package/lib/models/search-result.js.map +1 -0
  502. package/lib/models/thread.d.ts +245 -0
  503. package/lib/models/thread.d.ts.map +1 -0
  504. package/lib/models/thread.js +866 -0
  505. package/lib/models/thread.js.map +1 -0
  506. package/lib/models/typed-event-emitter.d.ts +157 -0
  507. package/lib/models/typed-event-emitter.d.ts.map +1 -0
  508. package/lib/models/typed-event-emitter.js +227 -0
  509. package/lib/models/typed-event-emitter.js.map +1 -0
  510. package/lib/models/user.d.ts +195 -0
  511. package/lib/models/user.d.ts.map +1 -0
  512. package/lib/models/user.js +218 -0
  513. package/lib/models/user.js.map +1 -0
  514. package/lib/oidc/authorize.d.ts +93 -0
  515. package/lib/oidc/authorize.d.ts.map +1 -0
  516. package/lib/oidc/authorize.js +282 -0
  517. package/lib/oidc/authorize.js.map +1 -0
  518. package/lib/oidc/discovery.d.ts +22 -0
  519. package/lib/oidc/discovery.d.ts.map +1 -0
  520. package/lib/oidc/discovery.js +78 -0
  521. package/lib/oidc/discovery.js.map +1 -0
  522. package/lib/oidc/error.d.ts +18 -0
  523. package/lib/oidc/error.d.ts.map +1 -0
  524. package/lib/oidc/error.js +35 -0
  525. package/lib/oidc/error.js.map +1 -0
  526. package/lib/oidc/index.d.ts +16 -0
  527. package/lib/oidc/index.d.ts.map +1 -0
  528. package/lib/oidc/index.js +29 -0
  529. package/lib/oidc/index.js.map +1 -0
  530. package/lib/oidc/register.d.ts +70 -0
  531. package/lib/oidc/register.d.ts.map +1 -0
  532. package/lib/oidc/register.js +135 -0
  533. package/lib/oidc/register.js.map +1 -0
  534. package/lib/oidc/tokenRefresher.d.ts +91 -0
  535. package/lib/oidc/tokenRefresher.d.ts.map +1 -0
  536. package/lib/oidc/tokenRefresher.js +187 -0
  537. package/lib/oidc/tokenRefresher.js.map +1 -0
  538. package/lib/oidc/validate.d.ts +78 -0
  539. package/lib/oidc/validate.d.ts.map +1 -0
  540. package/lib/oidc/validate.js +181 -0
  541. package/lib/oidc/validate.js.map +1 -0
  542. package/lib/pushprocessor.d.ts +140 -0
  543. package/lib/pushprocessor.d.ts.map +1 -0
  544. package/lib/pushprocessor.js +702 -0
  545. package/lib/pushprocessor.js.map +1 -0
  546. package/lib/randomstring.d.ts +32 -0
  547. package/lib/randomstring.d.ts.map +1 -0
  548. package/lib/randomstring.js +97 -0
  549. package/lib/randomstring.js.map +1 -0
  550. package/lib/realtime-callbacks.d.ts +18 -0
  551. package/lib/realtime-callbacks.d.ts.map +1 -0
  552. package/lib/realtime-callbacks.js +177 -0
  553. package/lib/realtime-callbacks.js.map +1 -0
  554. package/lib/receipt-accumulator.d.ts +51 -0
  555. package/lib/receipt-accumulator.d.ts.map +1 -0
  556. package/lib/receipt-accumulator.js +164 -0
  557. package/lib/receipt-accumulator.js.map +1 -0
  558. package/lib/rendezvous/MSC4108SignInWithQR.d.ts +112 -0
  559. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +1 -0
  560. package/lib/rendezvous/MSC4108SignInWithQR.js +389 -0
  561. package/lib/rendezvous/MSC4108SignInWithQR.js.map +1 -0
  562. package/lib/rendezvous/RendezvousChannel.d.ts +27 -0
  563. package/lib/rendezvous/RendezvousChannel.d.ts.map +1 -0
  564. package/lib/rendezvous/RendezvousChannel.js +1 -0
  565. package/lib/rendezvous/RendezvousChannel.js.map +1 -0
  566. package/lib/rendezvous/RendezvousCode.d.ts +9 -0
  567. package/lib/rendezvous/RendezvousCode.d.ts.map +1 -0
  568. package/lib/rendezvous/RendezvousCode.js +1 -0
  569. package/lib/rendezvous/RendezvousCode.js.map +1 -0
  570. package/lib/rendezvous/RendezvousError.d.ts +6 -0
  571. package/lib/rendezvous/RendezvousError.d.ts.map +1 -0
  572. package/lib/rendezvous/RendezvousError.js +23 -0
  573. package/lib/rendezvous/RendezvousError.js.map +1 -0
  574. package/lib/rendezvous/RendezvousFailureReason.d.ts +31 -0
  575. package/lib/rendezvous/RendezvousFailureReason.d.ts.map +1 -0
  576. package/lib/rendezvous/RendezvousFailureReason.js +47 -0
  577. package/lib/rendezvous/RendezvousFailureReason.js.map +1 -0
  578. package/lib/rendezvous/RendezvousIntent.d.ts +5 -0
  579. package/lib/rendezvous/RendezvousIntent.d.ts.map +1 -0
  580. package/lib/rendezvous/RendezvousIntent.js +22 -0
  581. package/lib/rendezvous/RendezvousIntent.js.map +1 -0
  582. package/lib/rendezvous/RendezvousTransport.d.ts +36 -0
  583. package/lib/rendezvous/RendezvousTransport.d.ts.map +1 -0
  584. package/lib/rendezvous/RendezvousTransport.js +1 -0
  585. package/lib/rendezvous/RendezvousTransport.js.map +1 -0
  586. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts +58 -0
  587. package/lib/rendezvous/channels/MSC4108SecureChannel.d.ts.map +1 -0
  588. package/lib/rendezvous/channels/MSC4108SecureChannel.js +246 -0
  589. package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +1 -0
  590. package/lib/rendezvous/channels/index.d.ts +2 -0
  591. package/lib/rendezvous/channels/index.d.ts.map +1 -0
  592. package/lib/rendezvous/channels/index.js +18 -0
  593. package/lib/rendezvous/channels/index.js.map +1 -0
  594. package/lib/rendezvous/index.d.ts +10 -0
  595. package/lib/rendezvous/index.d.ts.map +1 -0
  596. package/lib/rendezvous/index.js +23 -0
  597. package/lib/rendezvous/index.js.map +1 -0
  598. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts +61 -0
  599. package/lib/rendezvous/transports/MSC4108RendezvousSession.d.ts.map +1 -0
  600. package/lib/rendezvous/transports/MSC4108RendezvousSession.js +254 -0
  601. package/lib/rendezvous/transports/MSC4108RendezvousSession.js.map +1 -0
  602. package/lib/rendezvous/transports/index.d.ts +2 -0
  603. package/lib/rendezvous/transports/index.d.ts.map +1 -0
  604. package/lib/rendezvous/transports/index.js +18 -0
  605. package/lib/rendezvous/transports/index.js.map +1 -0
  606. package/lib/room-hierarchy.d.ts +35 -0
  607. package/lib/room-hierarchy.d.ts.map +1 -0
  608. package/lib/room-hierarchy.js +136 -0
  609. package/lib/room-hierarchy.js.map +1 -0
  610. package/lib/rust-crypto/CrossSigningIdentity.d.ts +35 -0
  611. package/lib/rust-crypto/CrossSigningIdentity.d.ts.map +1 -0
  612. package/lib/rust-crypto/CrossSigningIdentity.js +163 -0
  613. package/lib/rust-crypto/CrossSigningIdentity.js.map +1 -0
  614. package/lib/rust-crypto/DehydratedDeviceManager.d.ts +118 -0
  615. package/lib/rust-crypto/DehydratedDeviceManager.d.ts.map +1 -0
  616. package/lib/rust-crypto/DehydratedDeviceManager.js +361 -0
  617. package/lib/rust-crypto/DehydratedDeviceManager.js.map +1 -0
  618. package/lib/rust-crypto/KeyClaimManager.d.ts +33 -0
  619. package/lib/rust-crypto/KeyClaimManager.d.ts.map +1 -0
  620. package/lib/rust-crypto/KeyClaimManager.js +82 -0
  621. package/lib/rust-crypto/KeyClaimManager.js.map +1 -0
  622. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts +36 -0
  623. package/lib/rust-crypto/OutgoingRequestProcessor.d.ts.map +1 -0
  624. package/lib/rust-crypto/OutgoingRequestProcessor.js +194 -0
  625. package/lib/rust-crypto/OutgoingRequestProcessor.js.map +1 -0
  626. package/lib/rust-crypto/OutgoingRequestsManager.d.ts +47 -0
  627. package/lib/rust-crypto/OutgoingRequestsManager.d.ts.map +1 -0
  628. package/lib/rust-crypto/OutgoingRequestsManager.js +175 -0
  629. package/lib/rust-crypto/OutgoingRequestsManager.js.map +1 -0
  630. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts +120 -0
  631. package/lib/rust-crypto/PerSessionKeyBackupDownloader.d.ts.map +1 -0
  632. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js +469 -0
  633. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +1 -0
  634. package/lib/rust-crypto/RoomEncryptor.d.ts +100 -0
  635. package/lib/rust-crypto/RoomEncryptor.d.ts.map +1 -0
  636. package/lib/rust-crypto/RoomEncryptor.js +308 -0
  637. package/lib/rust-crypto/RoomEncryptor.js.map +1 -0
  638. package/lib/rust-crypto/backup.d.ts +278 -0
  639. package/lib/rust-crypto/backup.d.ts.map +1 -0
  640. package/lib/rust-crypto/backup.js +898 -0
  641. package/lib/rust-crypto/backup.js.map +1 -0
  642. package/lib/rust-crypto/constants.d.ts +3 -0
  643. package/lib/rust-crypto/constants.d.ts.map +1 -0
  644. package/lib/rust-crypto/constants.js +19 -0
  645. package/lib/rust-crypto/constants.js.map +1 -0
  646. package/lib/rust-crypto/device-converter.d.ts +28 -0
  647. package/lib/rust-crypto/device-converter.d.ts.map +1 -0
  648. package/lib/rust-crypto/device-converter.js +123 -0
  649. package/lib/rust-crypto/device-converter.js.map +1 -0
  650. package/lib/rust-crypto/index.d.ts +65 -0
  651. package/lib/rust-crypto/index.d.ts.map +1 -0
  652. package/lib/rust-crypto/index.js +149 -0
  653. package/lib/rust-crypto/index.js.map +1 -0
  654. package/lib/rust-crypto/libolm_migration.d.ts +81 -0
  655. package/lib/rust-crypto/libolm_migration.d.ts.map +1 -0
  656. package/lib/rust-crypto/libolm_migration.js +456 -0
  657. package/lib/rust-crypto/libolm_migration.js.map +1 -0
  658. package/lib/rust-crypto/rust-crypto.d.ts +576 -0
  659. package/lib/rust-crypto/rust-crypto.d.ts.map +1 -0
  660. package/lib/rust-crypto/rust-crypto.js +2324 -0
  661. package/lib/rust-crypto/rust-crypto.js.map +1 -0
  662. package/lib/rust-crypto/secret-storage.d.ts +22 -0
  663. package/lib/rust-crypto/secret-storage.d.ts.map +1 -0
  664. package/lib/rust-crypto/secret-storage.js +63 -0
  665. package/lib/rust-crypto/secret-storage.js.map +1 -0
  666. package/lib/rust-crypto/verification.d.ts +321 -0
  667. package/lib/rust-crypto/verification.d.ts.map +1 -0
  668. package/lib/rust-crypto/verification.js +817 -0
  669. package/lib/rust-crypto/verification.js.map +1 -0
  670. package/lib/scheduler.d.ts +132 -0
  671. package/lib/scheduler.d.ts.map +1 -0
  672. package/lib/scheduler.js +259 -0
  673. package/lib/scheduler.js.map +1 -0
  674. package/lib/secret-storage.d.ts +383 -0
  675. package/lib/secret-storage.d.ts.map +1 -0
  676. package/lib/secret-storage.js +487 -0
  677. package/lib/secret-storage.js.map +1 -0
  678. package/lib/serverCapabilities.d.ts +78 -0
  679. package/lib/serverCapabilities.d.ts.map +1 -0
  680. package/lib/serverCapabilities.js +104 -0
  681. package/lib/serverCapabilities.js.map +1 -0
  682. package/lib/service-types.d.ts +5 -0
  683. package/lib/service-types.d.ts.map +1 -0
  684. package/lib/service-types.js +23 -0
  685. package/lib/service-types.js.map +1 -0
  686. package/lib/sliding-sync-sdk.d.ts +107 -0
  687. package/lib/sliding-sync-sdk.d.ts.map +1 -0
  688. package/lib/sliding-sync-sdk.js +892 -0
  689. package/lib/sliding-sync-sdk.js.map +1 -0
  690. package/lib/sliding-sync.d.ts +306 -0
  691. package/lib/sliding-sync.d.ts.map +1 -0
  692. package/lib/sliding-sync.js +585 -0
  693. package/lib/sliding-sync.js.map +1 -0
  694. package/lib/store/index.d.ts +201 -0
  695. package/lib/store/index.d.ts.map +1 -0
  696. package/lib/store/index.js +1 -0
  697. package/lib/store/index.js.map +1 -0
  698. package/lib/store/indexeddb-backend.d.ts +24 -0
  699. package/lib/store/indexeddb-backend.d.ts.map +1 -0
  700. package/lib/store/indexeddb-backend.js +1 -0
  701. package/lib/store/indexeddb-backend.js.map +1 -0
  702. package/lib/store/indexeddb-local-backend.d.ts +129 -0
  703. package/lib/store/indexeddb-local-backend.d.ts.map +1 -0
  704. package/lib/store/indexeddb-local-backend.js +599 -0
  705. package/lib/store/indexeddb-local-backend.js.map +1 -0
  706. package/lib/store/indexeddb-remote-backend.d.ts +79 -0
  707. package/lib/store/indexeddb-remote-backend.d.ts.map +1 -0
  708. package/lib/store/indexeddb-remote-backend.js +209 -0
  709. package/lib/store/indexeddb-remote-backend.js.map +1 -0
  710. package/lib/store/indexeddb-store-worker.d.ts +35 -0
  711. package/lib/store/indexeddb-store-worker.d.ts.map +1 -0
  712. package/lib/store/indexeddb-store-worker.js +146 -0
  713. package/lib/store/indexeddb-store-worker.js.map +1 -0
  714. package/lib/store/indexeddb.d.ts +142 -0
  715. package/lib/store/indexeddb.d.ts.map +1 -0
  716. package/lib/store/indexeddb.js +347 -0
  717. package/lib/store/indexeddb.js.map +1 -0
  718. package/lib/store/local-storage-events-emitter.d.ts +30 -0
  719. package/lib/store/local-storage-events-emitter.d.ts.map +1 -0
  720. package/lib/store/local-storage-events-emitter.js +37 -0
  721. package/lib/store/local-storage-events-emitter.js.map +1 -0
  722. package/lib/store/memory.d.ts +209 -0
  723. package/lib/store/memory.d.ts.map +1 -0
  724. package/lib/store/memory.js +432 -0
  725. package/lib/store/memory.js.map +1 -0
  726. package/lib/store/stub.d.ts +161 -0
  727. package/lib/store/stub.d.ts.map +1 -0
  728. package/lib/store/stub.js +268 -0
  729. package/lib/store/stub.js.map +1 -0
  730. package/lib/sync-accumulator.d.ts +207 -0
  731. package/lib/sync-accumulator.d.ts.map +1 -0
  732. package/lib/sync-accumulator.js +588 -0
  733. package/lib/sync-accumulator.js.map +1 -0
  734. package/lib/sync.d.ts +273 -0
  735. package/lib/sync.d.ts.map +1 -0
  736. package/lib/sync.js +1764 -0
  737. package/lib/sync.js.map +1 -0
  738. package/lib/testing.d.ts +98 -0
  739. package/lib/testing.d.ts.map +1 -0
  740. package/lib/testing.js +205 -0
  741. package/lib/testing.js.map +1 -0
  742. package/lib/thread-utils.d.ts +10 -0
  743. package/lib/thread-utils.d.ts.map +1 -0
  744. package/lib/thread-utils.js +31 -0
  745. package/lib/thread-utils.js.map +1 -0
  746. package/lib/timeline-window.d.ts +168 -0
  747. package/lib/timeline-window.d.ts.map +1 -0
  748. package/lib/timeline-window.js +494 -0
  749. package/lib/timeline-window.js.map +1 -0
  750. package/lib/types.d.ts +33 -0
  751. package/lib/types.d.ts.map +1 -0
  752. package/lib/types.js +52 -0
  753. package/lib/types.js.map +1 -0
  754. package/lib/utils/decryptAESSecretStorageItem.d.ts +12 -0
  755. package/lib/utils/decryptAESSecretStorageItem.d.ts.map +1 -0
  756. package/lib/utils/decryptAESSecretStorageItem.js +50 -0
  757. package/lib/utils/decryptAESSecretStorageItem.js.map +1 -0
  758. package/lib/utils/encryptAESSecretStorageItem.d.ts +16 -0
  759. package/lib/utils/encryptAESSecretStorageItem.d.ts.map +1 -0
  760. package/lib/utils/encryptAESSecretStorageItem.js +68 -0
  761. package/lib/utils/encryptAESSecretStorageItem.js.map +1 -0
  762. package/lib/utils/internal/deriveKeys.d.ts +10 -0
  763. package/lib/utils/internal/deriveKeys.d.ts.map +1 -0
  764. package/lib/utils/internal/deriveKeys.js +60 -0
  765. package/lib/utils/internal/deriveKeys.js.map +1 -0
  766. package/lib/utils/roomVersion.d.ts +13 -0
  767. package/lib/utils/roomVersion.d.ts.map +1 -0
  768. package/lib/utils/roomVersion.js +36 -0
  769. package/lib/utils/roomVersion.js.map +1 -0
  770. package/lib/utils.d.ts +270 -0
  771. package/lib/utils.d.ts.map +1 -0
  772. package/lib/utils.js +764 -0
  773. package/lib/utils.js.map +1 -0
  774. package/lib/version-support.d.ts +19 -0
  775. package/lib/version-support.d.ts.map +1 -0
  776. package/lib/version-support.js +37 -0
  777. package/lib/version-support.js.map +1 -0
  778. package/lib/webrtc/audioContext.d.ts +15 -0
  779. package/lib/webrtc/audioContext.d.ts.map +1 -0
  780. package/lib/webrtc/audioContext.js +46 -0
  781. package/lib/webrtc/audioContext.js.map +1 -0
  782. package/lib/webrtc/call.d.ts +560 -0
  783. package/lib/webrtc/call.d.ts.map +1 -0
  784. package/lib/webrtc/call.js +2596 -0
  785. package/lib/webrtc/call.js.map +1 -0
  786. package/lib/webrtc/callEventHandler.d.ts +37 -0
  787. package/lib/webrtc/callEventHandler.d.ts.map +1 -0
  788. package/lib/webrtc/callEventHandler.js +344 -0
  789. package/lib/webrtc/callEventHandler.js.map +1 -0
  790. package/lib/webrtc/callEventTypes.d.ts +79 -0
  791. package/lib/webrtc/callEventTypes.d.ts.map +1 -0
  792. package/lib/webrtc/callEventTypes.js +13 -0
  793. package/lib/webrtc/callEventTypes.js.map +1 -0
  794. package/lib/webrtc/callFeed.d.ts +128 -0
  795. package/lib/webrtc/callFeed.d.ts.map +1 -0
  796. package/lib/webrtc/callFeed.js +289 -0
  797. package/lib/webrtc/callFeed.js.map +1 -0
  798. package/lib/webrtc/groupCall.d.ts +319 -0
  799. package/lib/webrtc/groupCall.d.ts.map +1 -0
  800. package/lib/webrtc/groupCall.js +1334 -0
  801. package/lib/webrtc/groupCall.js.map +1 -0
  802. package/lib/webrtc/groupCallEventHandler.d.ts +31 -0
  803. package/lib/webrtc/groupCallEventHandler.d.ts.map +1 -0
  804. package/lib/webrtc/groupCallEventHandler.js +178 -0
  805. package/lib/webrtc/groupCallEventHandler.js.map +1 -0
  806. package/lib/webrtc/mediaHandler.d.ts +89 -0
  807. package/lib/webrtc/mediaHandler.d.ts.map +1 -0
  808. package/lib/webrtc/mediaHandler.js +454 -0
  809. package/lib/webrtc/mediaHandler.js.map +1 -0
  810. package/lib/webrtc/stats/callFeedStatsReporter.d.ts +8 -0
  811. package/lib/webrtc/stats/callFeedStatsReporter.d.ts.map +1 -0
  812. package/lib/webrtc/stats/callFeedStatsReporter.js +79 -0
  813. package/lib/webrtc/stats/callFeedStatsReporter.js.map +1 -0
  814. package/lib/webrtc/stats/callStatsReportGatherer.d.ts +25 -0
  815. package/lib/webrtc/stats/callStatsReportGatherer.d.ts.map +1 -0
  816. package/lib/webrtc/stats/callStatsReportGatherer.js +199 -0
  817. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -0
  818. package/lib/webrtc/stats/callStatsReportSummary.d.ts +17 -0
  819. package/lib/webrtc/stats/callStatsReportSummary.d.ts.map +1 -0
  820. package/lib/webrtc/stats/callStatsReportSummary.js +1 -0
  821. package/lib/webrtc/stats/callStatsReportSummary.js.map +1 -0
  822. package/lib/webrtc/stats/connectionStats.d.ts +28 -0
  823. package/lib/webrtc/stats/connectionStats.d.ts.map +1 -0
  824. package/lib/webrtc/stats/connectionStats.js +26 -0
  825. package/lib/webrtc/stats/connectionStats.js.map +1 -0
  826. package/lib/webrtc/stats/connectionStatsBuilder.d.ts +5 -0
  827. package/lib/webrtc/stats/connectionStatsBuilder.d.ts.map +1 -0
  828. package/lib/webrtc/stats/connectionStatsBuilder.js +27 -0
  829. package/lib/webrtc/stats/connectionStatsBuilder.js.map +1 -0
  830. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts +7 -0
  831. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts.map +1 -0
  832. package/lib/webrtc/stats/connectionStatsReportBuilder.js +121 -0
  833. package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +1 -0
  834. package/lib/webrtc/stats/groupCallStats.d.ts +22 -0
  835. package/lib/webrtc/stats/groupCallStats.d.ts.map +1 -0
  836. package/lib/webrtc/stats/groupCallStats.js +78 -0
  837. package/lib/webrtc/stats/groupCallStats.js.map +1 -0
  838. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts +10 -0
  839. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts.map +1 -0
  840. package/lib/webrtc/stats/media/mediaSsrcHandler.js +57 -0
  841. package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +1 -0
  842. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts +12 -0
  843. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts.map +1 -0
  844. package/lib/webrtc/stats/media/mediaTrackHandler.js +58 -0
  845. package/lib/webrtc/stats/media/mediaTrackHandler.js.map +1 -0
  846. package/lib/webrtc/stats/media/mediaTrackStats.d.ts +86 -0
  847. package/lib/webrtc/stats/media/mediaTrackStats.d.ts.map +1 -0
  848. package/lib/webrtc/stats/media/mediaTrackStats.js +142 -0
  849. package/lib/webrtc/stats/media/mediaTrackStats.js.map +1 -0
  850. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts +22 -0
  851. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts.map +1 -0
  852. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +76 -0
  853. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +1 -0
  854. package/lib/webrtc/stats/statsReport.d.ts +99 -0
  855. package/lib/webrtc/stats/statsReport.d.ts.map +1 -0
  856. package/lib/webrtc/stats/statsReport.js +32 -0
  857. package/lib/webrtc/stats/statsReport.js.map +1 -0
  858. package/lib/webrtc/stats/statsReportEmitter.d.ts +15 -0
  859. package/lib/webrtc/stats/statsReportEmitter.d.ts.map +1 -0
  860. package/lib/webrtc/stats/statsReportEmitter.js +33 -0
  861. package/lib/webrtc/stats/statsReportEmitter.js.map +1 -0
  862. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts +16 -0
  863. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts.map +1 -0
  864. package/lib/webrtc/stats/summaryStatsReportGatherer.js +116 -0
  865. package/lib/webrtc/stats/summaryStatsReportGatherer.js.map +1 -0
  866. package/lib/webrtc/stats/trackStatsBuilder.d.ts +19 -0
  867. package/lib/webrtc/stats/trackStatsBuilder.d.ts.map +1 -0
  868. package/lib/webrtc/stats/trackStatsBuilder.js +168 -0
  869. package/lib/webrtc/stats/trackStatsBuilder.js.map +1 -0
  870. package/lib/webrtc/stats/transportStats.d.ts +11 -0
  871. package/lib/webrtc/stats/transportStats.d.ts.map +1 -0
  872. package/lib/webrtc/stats/transportStats.js +1 -0
  873. package/lib/webrtc/stats/transportStats.js.map +1 -0
  874. package/lib/webrtc/stats/transportStatsBuilder.d.ts +5 -0
  875. package/lib/webrtc/stats/transportStatsBuilder.d.ts.map +1 -0
  876. package/lib/webrtc/stats/transportStatsBuilder.js +34 -0
  877. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -0
  878. package/lib/webrtc/stats/valueFormatter.d.ts +4 -0
  879. package/lib/webrtc/stats/valueFormatter.d.ts.map +1 -0
  880. package/lib/webrtc/stats/valueFormatter.js +25 -0
  881. package/lib/webrtc/stats/valueFormatter.js.map +1 -0
  882. package/package.json +129 -0
  883. package/src/@types/AESEncryptedSecretStoragePayload.ts +29 -0
  884. package/src/@types/IIdentityServerProvider.ts +24 -0
  885. package/src/@types/PushRules.ts +208 -0
  886. package/src/@types/another-json.d.ts +19 -0
  887. package/src/@types/auth.ts +258 -0
  888. package/src/@types/beacon.ts +140 -0
  889. package/src/@types/common.ts +24 -0
  890. package/src/@types/crypto.ts +71 -0
  891. package/src/@types/event.ts +449 -0
  892. package/src/@types/events.ts +119 -0
  893. package/src/@types/extensible_events.ts +147 -0
  894. package/src/@types/global.d.ts +67 -0
  895. package/src/@types/local_notifications.ts +19 -0
  896. package/src/@types/location.ts +92 -0
  897. package/src/@types/matrix-sdk-crypto-wasm.d.ts +39 -0
  898. package/src/@types/media.ts +245 -0
  899. package/src/@types/membership.ts +57 -0
  900. package/src/@types/partials.ts +103 -0
  901. package/src/@types/polls.ts +120 -0
  902. package/src/@types/read_receipts.ts +61 -0
  903. package/src/@types/registration.ts +102 -0
  904. package/src/@types/requests.ts +346 -0
  905. package/src/@types/search.ts +119 -0
  906. package/src/@types/signed.ts +25 -0
  907. package/src/@types/spaces.ts +37 -0
  908. package/src/@types/state_events.ts +153 -0
  909. package/src/@types/synapse.ts +40 -0
  910. package/src/@types/sync.ts +27 -0
  911. package/src/@types/threepids.ts +29 -0
  912. package/src/@types/topic.ts +69 -0
  913. package/src/@types/uia.ts +24 -0
  914. package/src/NamespacedValue.ts +121 -0
  915. package/src/ReEmitter.ts +93 -0
  916. package/src/ToDeviceMessageQueue.ts +156 -0
  917. package/src/autodiscovery.ts +505 -0
  918. package/src/base64.ts +86 -0
  919. package/src/briij.ts +173 -0
  920. package/src/browser-index.ts +44 -0
  921. package/src/client.ts +9031 -0
  922. package/src/common-crypto/CryptoBackend.ts +295 -0
  923. package/src/common-crypto/README.md +4 -0
  924. package/src/common-crypto/key-passphrase.ts +43 -0
  925. package/src/content-helpers.ts +298 -0
  926. package/src/content-repo.ts +122 -0
  927. package/src/crypto/store/base.ts +388 -0
  928. package/src/crypto/store/indexeddb-crypto-store-backend.ts +655 -0
  929. package/src/crypto/store/indexeddb-crypto-store.ts +555 -0
  930. package/src/crypto/store/localStorage-crypto-store.ts +409 -0
  931. package/src/crypto/store/memory-crypto-store.ts +326 -0
  932. package/src/crypto-api/CryptoEvent.ts +152 -0
  933. package/src/crypto-api/CryptoEventHandlerMap.ts +42 -0
  934. package/src/crypto-api/index.ts +1362 -0
  935. package/src/crypto-api/key-passphrase.ts +58 -0
  936. package/src/crypto-api/keybackup.ts +114 -0
  937. package/src/crypto-api/recovery-key.ts +69 -0
  938. package/src/crypto-api/verification.ts +382 -0
  939. package/src/digest.ts +34 -0
  940. package/src/embedded.ts +865 -0
  941. package/src/errors.ts +87 -0
  942. package/src/event-mapper.ts +88 -0
  943. package/src/extensible_events_v1/ExtensibleEvent.ts +58 -0
  944. package/src/extensible_events_v1/InvalidEventError.ts +24 -0
  945. package/src/extensible_events_v1/MessageEvent.ts +143 -0
  946. package/src/extensible_events_v1/PollEndEvent.ts +97 -0
  947. package/src/extensible_events_v1/PollResponseEvent.ts +148 -0
  948. package/src/extensible_events_v1/PollStartEvent.ts +207 -0
  949. package/src/extensible_events_v1/utilities.ts +35 -0
  950. package/src/feature.ts +88 -0
  951. package/src/filter-component.ts +209 -0
  952. package/src/filter.ts +245 -0
  953. package/src/http-api/errors.ts +261 -0
  954. package/src/http-api/fetch.ts +377 -0
  955. package/src/http-api/index.ts +194 -0
  956. package/src/http-api/interface.ts +229 -0
  957. package/src/http-api/method.ts +25 -0
  958. package/src/http-api/prefix.ts +48 -0
  959. package/src/http-api/refresh.ts +167 -0
  960. package/src/http-api/utils.ts +217 -0
  961. package/src/index.ts +25 -0
  962. package/src/indexeddb-helpers.ts +50 -0
  963. package/src/indexeddb-worker.ts +24 -0
  964. package/src/interactive-auth.ts +700 -0
  965. package/src/logger.ts +279 -0
  966. package/src/matrixrtc/CallMembership.ts +438 -0
  967. package/src/matrixrtc/EncryptionManager.ts +54 -0
  968. package/src/matrixrtc/IKeyTransport.ts +63 -0
  969. package/src/matrixrtc/IMembershipManager.ts +120 -0
  970. package/src/matrixrtc/LivekitTransport.ts +46 -0
  971. package/src/matrixrtc/MatrixRTCSession.ts +934 -0
  972. package/src/matrixrtc/MatrixRTCSessionManager.ts +170 -0
  973. package/src/matrixrtc/MembershipManager.ts +1122 -0
  974. package/src/matrixrtc/MembershipManagerActionScheduler.ts +135 -0
  975. package/src/matrixrtc/RTCEncryptionManager.ts +459 -0
  976. package/src/matrixrtc/ToDeviceKeyTransport.ts +197 -0
  977. package/src/matrixrtc/index.ts +24 -0
  978. package/src/matrixrtc/membershipData/common.ts +27 -0
  979. package/src/matrixrtc/membershipData/index.ts +19 -0
  980. package/src/matrixrtc/membershipData/rtc.ts +156 -0
  981. package/src/matrixrtc/membershipData/session.ts +146 -0
  982. package/src/matrixrtc/types.ts +227 -0
  983. package/src/matrixrtc/utils.ts +71 -0
  984. package/src/models/MSC3089Branch.ts +272 -0
  985. package/src/models/MSC3089TreeSpace.ts +565 -0
  986. package/src/models/ToDeviceMessage.ts +38 -0
  987. package/src/models/beacon.ts +213 -0
  988. package/src/models/compare-event-ordering.ts +139 -0
  989. package/src/models/device.ts +85 -0
  990. package/src/models/event-context.ts +110 -0
  991. package/src/models/event-status.ts +39 -0
  992. package/src/models/event-timeline-set.ts +962 -0
  993. package/src/models/event-timeline.ts +461 -0
  994. package/src/models/event.ts +1819 -0
  995. package/src/models/invites-ignorer-types.ts +58 -0
  996. package/src/models/invites-ignorer.ts +341 -0
  997. package/src/models/poll.ts +285 -0
  998. package/src/models/profile-keys.ts +33 -0
  999. package/src/models/read-receipt.ts +422 -0
  1000. package/src/models/related-relations.ts +39 -0
  1001. package/src/models/relations-container.ts +149 -0
  1002. package/src/models/relations.ts +392 -0
  1003. package/src/models/room-member.ts +486 -0
  1004. package/src/models/room-receipts.ts +439 -0
  1005. package/src/models/room-state.ts +1230 -0
  1006. package/src/models/room-sticky-events.ts +383 -0
  1007. package/src/models/room-summary.ts +78 -0
  1008. package/src/models/room.ts +4067 -0
  1009. package/src/models/search-result.ts +57 -0
  1010. package/src/models/thread.ts +928 -0
  1011. package/src/models/typed-event-emitter.ts +246 -0
  1012. package/src/models/user.ts +302 -0
  1013. package/src/oidc/authorize.ts +279 -0
  1014. package/src/oidc/discovery.ts +67 -0
  1015. package/src/oidc/error.ts +33 -0
  1016. package/src/oidc/index.ts +33 -0
  1017. package/src/oidc/register.ts +163 -0
  1018. package/src/oidc/tokenRefresher.ts +184 -0
  1019. package/src/oidc/validate.ts +265 -0
  1020. package/src/pushprocessor.ts +856 -0
  1021. package/src/randomstring.ts +103 -0
  1022. package/src/realtime-callbacks.ts +191 -0
  1023. package/src/receipt-accumulator.ts +189 -0
  1024. package/src/rendezvous/MSC4108SignInWithQR.ts +443 -0
  1025. package/src/rendezvous/RendezvousChannel.ts +48 -0
  1026. package/src/rendezvous/RendezvousCode.ts +25 -0
  1027. package/src/rendezvous/RendezvousError.ts +26 -0
  1028. package/src/rendezvous/RendezvousFailureReason.ts +49 -0
  1029. package/src/rendezvous/RendezvousIntent.ts +20 -0
  1030. package/src/rendezvous/RendezvousTransport.ts +58 -0
  1031. package/src/rendezvous/channels/MSC4108SecureChannel.ts +270 -0
  1032. package/src/rendezvous/channels/index.ts +17 -0
  1033. package/src/rendezvous/index.ts +25 -0
  1034. package/src/rendezvous/transports/MSC4108RendezvousSession.ts +272 -0
  1035. package/src/rendezvous/transports/index.ts +17 -0
  1036. package/src/room-hierarchy.ts +152 -0
  1037. package/src/rust-crypto/CrossSigningIdentity.ts +195 -0
  1038. package/src/rust-crypto/DehydratedDeviceManager.ts +392 -0
  1039. package/src/rust-crypto/KeyClaimManager.ts +86 -0
  1040. package/src/rust-crypto/OutgoingRequestProcessor.ts +233 -0
  1041. package/src/rust-crypto/OutgoingRequestsManager.ts +170 -0
  1042. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +501 -0
  1043. package/src/rust-crypto/RoomEncryptor.ts +362 -0
  1044. package/src/rust-crypto/backup.ts +942 -0
  1045. package/src/rust-crypto/constants.ts +18 -0
  1046. package/src/rust-crypto/device-converter.ts +128 -0
  1047. package/src/rust-crypto/index.ts +251 -0
  1048. package/src/rust-crypto/libolm_migration.ts +532 -0
  1049. package/src/rust-crypto/rust-crypto.ts +2542 -0
  1050. package/src/rust-crypto/secret-storage.ts +60 -0
  1051. package/src/rust-crypto/verification.ts +833 -0
  1052. package/src/scheduler.ts +309 -0
  1053. package/src/secret-storage.ts +714 -0
  1054. package/src/serverCapabilities.ts +146 -0
  1055. package/src/service-types.ts +20 -0
  1056. package/src/sliding-sync-sdk.ts +1005 -0
  1057. package/src/sliding-sync.ts +674 -0
  1058. package/src/store/index.ts +261 -0
  1059. package/src/store/indexeddb-backend.ts +41 -0
  1060. package/src/store/indexeddb-local-backend.ts +610 -0
  1061. package/src/store/indexeddb-remote-backend.ts +212 -0
  1062. package/src/store/indexeddb-store-worker.ts +157 -0
  1063. package/src/store/indexeddb.ts +397 -0
  1064. package/src/store/local-storage-events-emitter.ts +46 -0
  1065. package/src/store/memory.ts +448 -0
  1066. package/src/store/stub.ts +280 -0
  1067. package/src/sync-accumulator.ts +779 -0
  1068. package/src/sync.ts +2020 -0
  1069. package/src/testing.ts +231 -0
  1070. package/src/thread-utils.ts +31 -0
  1071. package/src/timeline-window.ts +534 -0
  1072. package/src/types.ts +59 -0
  1073. package/src/utils/decryptAESSecretStorageItem.ts +54 -0
  1074. package/src/utils/encryptAESSecretStorageItem.ts +73 -0
  1075. package/src/utils/internal/deriveKeys.ts +63 -0
  1076. package/src/utils/roomVersion.ts +35 -0
  1077. package/src/utils.ts +775 -0
  1078. package/src/version-support.ts +50 -0
  1079. package/src/webrtc/audioContext.ts +44 -0
  1080. package/src/webrtc/call.ts +3061 -0
  1081. package/src/webrtc/callEventHandler.ts +425 -0
  1082. package/src/webrtc/callEventTypes.ts +101 -0
  1083. package/src/webrtc/callFeed.ts +364 -0
  1084. package/src/webrtc/groupCall.ts +1729 -0
  1085. package/src/webrtc/groupCallEventHandler.ts +234 -0
  1086. package/src/webrtc/mediaHandler.ts +501 -0
  1087. package/src/webrtc/stats/callFeedStatsReporter.ts +91 -0
  1088. package/src/webrtc/stats/callStatsReportGatherer.ts +219 -0
  1089. package/src/webrtc/stats/callStatsReportSummary.ts +30 -0
  1090. package/src/webrtc/stats/connectionStats.ts +47 -0
  1091. package/src/webrtc/stats/connectionStatsBuilder.ts +28 -0
  1092. package/src/webrtc/stats/connectionStatsReportBuilder.ts +140 -0
  1093. package/src/webrtc/stats/groupCallStats.ts +93 -0
  1094. package/src/webrtc/stats/media/mediaSsrcHandler.ts +57 -0
  1095. package/src/webrtc/stats/media/mediaTrackHandler.ts +70 -0
  1096. package/src/webrtc/stats/media/mediaTrackStats.ts +176 -0
  1097. package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +90 -0
  1098. package/src/webrtc/stats/statsReport.ts +133 -0
  1099. package/src/webrtc/stats/statsReportEmitter.ts +49 -0
  1100. package/src/webrtc/stats/summaryStatsReportGatherer.ts +148 -0
  1101. package/src/webrtc/stats/trackStatsBuilder.ts +207 -0
  1102. package/src/webrtc/stats/transportStats.ts +26 -0
  1103. package/src/webrtc/stats/transportStatsBuilder.ts +48 -0
  1104. package/src/webrtc/stats/valueFormatter.ts +27 -0
@@ -0,0 +1,1819 @@
1
+ /*
2
+ Copyright 2015 - 2023 The Matrix.org Foundation C.I.C.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * This is an internal module. See {@link BriijEvent} and {@link RoomEvent} for
19
+ * the public classes.
20
+ */
21
+
22
+ import { type ExtensibleEvent, ExtensibleEvents } from "matrix-events-sdk";
23
+
24
+ import { logger } from "../logger.ts";
25
+ import {
26
+ EVENT_VISIBILITY_CHANGE_TYPE,
27
+ EventType,
28
+ type MsgType,
29
+ RelationType,
30
+ ToDeviceMessageId,
31
+ UNSIGNED_THREAD_ID_FIELD,
32
+ UNSIGNED_MEMBERSHIP_FIELD,
33
+ } from "../@types/event.ts";
34
+ import { deepSortedObjectEntries, internaliseString } from "../utils.ts";
35
+ import { type RoomMember } from "./room-member.ts";
36
+ import { type Thread, THREAD_RELATION_TYPE, ThreadEvent, type ThreadEventHandlerMap } from "./thread.ts";
37
+ import { type IActionsObject } from "../pushprocessor.ts";
38
+ import { TypedReEmitter } from "../ReEmitter.ts";
39
+ import { type BriijError } from "../http-api/index.ts";
40
+ import { TypedEventEmitter } from "./typed-event-emitter.ts";
41
+ import { type EventStatus } from "./event-status.ts";
42
+ import { type CryptoBackend, DecryptionError, type EventDecryptionResult } from "../common-crypto/CryptoBackend.ts";
43
+ import { type IAnnotatedPushRule } from "../@types/PushRules.ts";
44
+ import { type Room } from "./room.ts";
45
+ import { EventTimeline } from "./event-timeline.ts";
46
+ import { type Membership } from "../@types/membership.ts";
47
+ import { DecryptionFailureCode } from "../crypto-api/index.ts";
48
+ import { type RoomState } from "./room-state.ts";
49
+ import { type EmptyObject } from "../@types/common.ts";
50
+
51
+ export { EventStatus } from "./event-status.ts";
52
+
53
+ /* eslint-disable camelcase */
54
+ export interface IContent {
55
+ [key: string]: any;
56
+ "msgtype"?: MsgType | string;
57
+ "membership"?: Membership;
58
+ "avatar_url"?: string;
59
+ "displayname"?: string;
60
+ "m.relates_to"?: IEventRelation;
61
+
62
+ "m.mentions"?: IMentions;
63
+ }
64
+
65
+ type StrippedState = Required<Pick<IEvent, "content" | "state_key" | "type" | "sender">>;
66
+
67
+ export interface IUnsigned {
68
+ [key: string]: any;
69
+ "age"?: number;
70
+ "prev_sender"?: string;
71
+ "prev_content"?: IContent;
72
+ "redacted_because"?: IEvent;
73
+ "replaces_state"?: string;
74
+ "transaction_id"?: string;
75
+ "invite_room_state"?: StrippedState[];
76
+ "m.relations"?: Record<RelationType | string, any>; // No common pattern for aggregated relations
77
+ "msc4354_sticky_duration_ttl_ms"?: number;
78
+ [UNSIGNED_THREAD_ID_FIELD.name]?: string;
79
+ "membership"?: Membership;
80
+ "io.element.msc4115.membership"?: Membership;
81
+ }
82
+
83
+ export interface IThreadBundledRelationship {
84
+ latest_event: IEvent;
85
+ count: number;
86
+ current_user_participated?: boolean;
87
+ }
88
+
89
+ export interface IEvent {
90
+ event_id: string;
91
+ type: string;
92
+ content: IContent;
93
+ sender: string;
94
+ room_id?: string;
95
+ origin_server_ts: number;
96
+ txn_id?: string;
97
+ state_key?: string;
98
+ membership?: Membership;
99
+ unsigned: IUnsigned;
100
+ redacts?: string;
101
+ msc4354_sticky?: { duration_ms: number };
102
+ }
103
+
104
+ export interface IAggregatedRelation {
105
+ origin_server_ts: number;
106
+ event_id?: string;
107
+ sender?: string;
108
+ type?: string;
109
+ count?: number;
110
+ key?: string;
111
+ }
112
+
113
+ export interface IEventRelation {
114
+ "rel_type"?: RelationType | string;
115
+ "event_id"?: string;
116
+ "is_falling_back"?: boolean;
117
+ "m.in_reply_to"?: {
118
+ event_id?: string;
119
+ };
120
+ "key"?: string;
121
+ }
122
+
123
+ export interface IMentions {
124
+ user_ids?: string[];
125
+ room?: boolean;
126
+ }
127
+
128
+ export interface PushDetails {
129
+ rule?: IAnnotatedPushRule;
130
+ actions?: IActionsObject;
131
+ }
132
+
133
+ /**
134
+ * When an event is a visibility change event, as per MSC3531,
135
+ * the visibility change implied by the event.
136
+ */
137
+ export interface IVisibilityChange {
138
+ /**
139
+ * If `true`, the target event should be made visible.
140
+ * Otherwise, it should be hidden.
141
+ */
142
+ visible: boolean;
143
+
144
+ /**
145
+ * The event id affected.
146
+ */
147
+ eventId: string;
148
+
149
+ /**
150
+ * Optionally, a human-readable reason explaining why
151
+ * the event was hidden. Ignored if the event was made
152
+ * visible.
153
+ */
154
+ reason: string | null;
155
+ }
156
+
157
+ export interface IMarkedUnreadEvent {
158
+ unread: boolean;
159
+ }
160
+
161
+ export interface IClearEvent {
162
+ room_id?: string;
163
+ type: string;
164
+ state_key?: string;
165
+ content: Omit<IContent, "membership" | "avatar_url" | "displayname" | "m.relates_to">;
166
+ unsigned?: IUnsigned;
167
+ }
168
+ /* eslint-enable camelcase */
169
+
170
+ interface IKeyRequestRecipient {
171
+ userId: string;
172
+ deviceId: "*" | string;
173
+ }
174
+
175
+ export interface IDecryptOptions {
176
+ /** Whether to emit {@link BriijEventEvent.Decrypted} events on successful decryption. Defaults to true.
177
+ */
178
+ emit?: boolean;
179
+
180
+ /**
181
+ * True if this is a retry, after receiving an update to the session key. (Enables more logging.)
182
+ *
183
+ * This is only intended for use within the js-sdk.
184
+ *
185
+ * @internal
186
+ */
187
+ isRetry?: boolean;
188
+
189
+ /**
190
+ * @deprecated does nothing
191
+ */
192
+ forceRedecryptIfUntrusted?: boolean;
193
+ }
194
+
195
+ /**
196
+ * Message hiding, as specified by https://github.com/matrix-org/matrix-doc/pull/3531.
197
+ */
198
+ export type MessageVisibility = IMessageVisibilityHidden | IMessageVisibilityVisible;
199
+ /**
200
+ * Variant of `MessageVisibility` for the case in which the message should be displayed.
201
+ */
202
+ export interface IMessageVisibilityVisible {
203
+ readonly visible: true;
204
+ }
205
+ /**
206
+ * Variant of `MessageVisibility` for the case in which the message should be hidden.
207
+ */
208
+ export interface IMessageVisibilityHidden {
209
+ readonly visible: false;
210
+ /**
211
+ * Optionally, a human-readable reason to show to the user indicating why the
212
+ * message has been hidden (e.g. "Message Pending Moderation").
213
+ */
214
+ readonly reason: string | null;
215
+ }
216
+ // A singleton implementing `IMessageVisibilityVisible`.
217
+ const MESSAGE_VISIBLE: IMessageVisibilityVisible = Object.freeze({ visible: true });
218
+ export const MAX_STICKY_DURATION_MS = 3600000;
219
+
220
+ export enum BriijEventEvent {
221
+ /**
222
+ * An event has been decrypted, or we have failed to decrypt it.
223
+ *
224
+ * The payload consists of:
225
+ *
226
+ * * `event` - The {@link BriijEvent} which we attempted to decrypt.
227
+ *
228
+ * * `err` - The error that occurred during decryption, or `undefined` if no error occurred.
229
+ * Avoid use of this: {@link BriijEvent.decryptionFailureReason} is more useful.
230
+ */
231
+ Decrypted = "Event.decrypted",
232
+
233
+ BeforeRedaction = "Event.beforeRedaction",
234
+ VisibilityChange = "Event.visibilityChange",
235
+ LocalEventIdReplaced = "Event.localEventIdReplaced",
236
+ Status = "Event.status",
237
+ Replaced = "Event.replaced",
238
+ RelationsCreated = "Event.relationsCreated",
239
+ SentinelUpdated = "Event.sentinelUpdated",
240
+ }
241
+
242
+ export type BriijEventEmittedEvents = BriijEventEvent | ThreadEvent.Update;
243
+
244
+ export type BriijEventHandlerMap = {
245
+ [BriijEventEvent.Decrypted]: (event: BriijEvent, err?: Error) => void;
246
+ [BriijEventEvent.BeforeRedaction]: (event: BriijEvent, redactionEvent: BriijEvent) => void;
247
+ [BriijEventEvent.VisibilityChange]: (event: BriijEvent, visible: boolean) => void;
248
+ [BriijEventEvent.LocalEventIdReplaced]: (event: BriijEvent) => void;
249
+ [BriijEventEvent.Status]: (event: BriijEvent, status: EventStatus | null) => void;
250
+ [BriijEventEvent.Replaced]: (event: BriijEvent) => void;
251
+ [BriijEventEvent.RelationsCreated]: (relationType: string, eventType: string) => void;
252
+ [BriijEventEvent.SentinelUpdated]: () => void;
253
+ } & Pick<ThreadEventHandlerMap, ThreadEvent.Update>;
254
+
255
+ export class BriijEvent extends TypedEventEmitter<BriijEventEmittedEvents, BriijEventHandlerMap> {
256
+ // applied push rule and action for this event
257
+ private pushDetails: PushDetails = {};
258
+ private _replacingEvent: BriijEvent | null = null;
259
+ private _localRedactionEvent: BriijEvent | null = null;
260
+ private _isCancelled = false;
261
+ private clearEvent?: IClearEvent;
262
+
263
+ /* Message hiding, as specified by https://github.com/matrix-org/matrix-doc/pull/3531.
264
+
265
+ Note: We're returning this object, so any value stored here MUST be frozen.
266
+ */
267
+ private visibility: MessageVisibility = MESSAGE_VISIBLE;
268
+
269
+ // Not all events will be extensible-event compatible, so cache a flag in
270
+ // addition to a falsy cached event value. We check the flag later on in
271
+ // a public getter to decide if the cache is valid.
272
+ private _hasCachedExtEv = false;
273
+ private _cachedExtEv?: ExtensibleEvent = undefined;
274
+
275
+ /** If we failed to decrypt this event, the reason for the failure. Otherwise, `null`. */
276
+ private _decryptionFailureReason: DecryptionFailureCode | null = null;
277
+
278
+ /* curve25519 key which we believe belongs to the sender of the event. See
279
+ * getSenderKey()
280
+ */
281
+ private senderCurve25519Key: string | null = null;
282
+
283
+ /* ed25519 key which the sender of this event (for olm) or the creator of
284
+ * the megolm session (for megolm) claims to own. See getClaimedEd25519Key()
285
+ */
286
+ private claimedEd25519Key: string | null = null;
287
+
288
+ /**
289
+ * If another user forwarded the key to this message
290
+ * (eg via [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)),
291
+ * the ID of that user.
292
+ */
293
+ private keyForwardedBy?: string;
294
+
295
+ /* if we have a process decrypting this event, a Promise which resolves
296
+ * when it is finished. Normally null.
297
+ */
298
+ private decryptionPromise: Promise<void> | null = null;
299
+
300
+ /* flag to indicate if we should retry decrypting this event after the
301
+ * first attempt (eg, we have received new data which means that a second
302
+ * attempt may succeed)
303
+ */
304
+ private retryDecryption = false;
305
+
306
+ /* The txnId with which this event was sent if it was during this session,
307
+ * allows for a unique ID which does not change when the event comes back down sync.
308
+ */
309
+ private txnId?: string;
310
+
311
+ /**
312
+ * A reference to the thread this event belongs to
313
+ */
314
+ private thread?: Thread;
315
+ private threadId?: string;
316
+
317
+ /* Set an approximate timestamp for the event relative the local clock.
318
+ * This will inherently be approximate because it doesn't take into account
319
+ * the time between the server putting the 'age' field on the event as it sent
320
+ * it to us and the time we're now constructing this event, but that's better
321
+ * than assuming the local clock is in sync with the origin HS's clock.
322
+ */
323
+ public localTimestamp: number;
324
+
325
+ /**
326
+ * The room member who sent this event, or null e.g.
327
+ * this is a presence event. This is only guaranteed to be set for events that
328
+ * appear in a timeline, ie. do not guarantee that it will be set on state
329
+ * events.
330
+ * @privateRemarks
331
+ * Should be read-only
332
+ */
333
+ public sender: RoomMember | null = null;
334
+
335
+ /**
336
+ * The room member who is the target of this event, e.g.
337
+ * the invitee, the person being banned, etc.
338
+ * @privateRemarks
339
+ * Should be read-only
340
+ */
341
+ public target: RoomMember | null = null;
342
+
343
+ /**
344
+ * Update the sentinels and forwardLooking flag for this event.
345
+ * @param stateContext - the room state to be queried
346
+ * @param toStartOfTimeline - if true the event's forwardLooking flag is set false
347
+ * @internal
348
+ */
349
+ public setMetadata(stateContext: RoomState, toStartOfTimeline: boolean): void {
350
+ // If an event is an m.room.member state event then we should set the sentinels again in case setEventMetadata
351
+ // was already called before the state was applied and thus the sentinel points at the member from before this event.
352
+ const affectsSelf =
353
+ this.isState() && this.getType() === EventType.RoomMember && this.getSender() === this.getStateKey();
354
+
355
+ let changed = false;
356
+ // When we try to generate a sentinel member before we have that member
357
+ // in the members object, we still generate a sentinel but it doesn't
358
+ // have a membership event, so test to see if events.member is set. We
359
+ // check this to avoid overriding non-sentinel members by sentinel ones
360
+ // when adding the event to a filtered timeline
361
+ if (affectsSelf || !this.sender?.events?.member) {
362
+ const newSender = stateContext.getSentinelMember(this.getSender()!);
363
+ if (newSender !== this.sender) changed = true;
364
+ this.sender = newSender;
365
+ }
366
+ if (affectsSelf || (!this.target?.events?.member && this.getType() === EventType.RoomMember)) {
367
+ const newTarget = stateContext.getSentinelMember(this.getStateKey()!);
368
+ if (newTarget !== this.target) changed = true;
369
+ this.target = newTarget;
370
+ }
371
+
372
+ if (this.isState()) {
373
+ // room state has no concept of 'old' or 'current', but we want the
374
+ // room state to regress back to previous values if toStartOfTimeline
375
+ // is set, which means inspecting prev_content if it exists. This
376
+ // is done by toggling the forwardLooking flag.
377
+ if (toStartOfTimeline) {
378
+ this.forwardLooking = false;
379
+ }
380
+ }
381
+
382
+ if (changed) {
383
+ this.emit(BriijEventEvent.SentinelUpdated);
384
+ }
385
+ }
386
+
387
+ /**
388
+ * The sending status of the event.
389
+ * @privateRemarks
390
+ * Should be read-only
391
+ */
392
+ public status: EventStatus | null = null;
393
+ /**
394
+ * most recent error associated with sending the event, if any
395
+ * @privateRemarks
396
+ * Should be read-only. May not be a BriijError.
397
+ */
398
+ public error: BriijError | null = null;
399
+ /**
400
+ * True if this event is 'forward looking', meaning
401
+ * that getDirectionalContent() will return event.content and not event.prev_content.
402
+ * Only state events may be backwards looking
403
+ * Default: true. <strong>This property is experimental and may change.</strong>
404
+ * @privateRemarks
405
+ * Should be read-only
406
+ */
407
+ public forwardLooking = true;
408
+
409
+ private readonly reEmitter: TypedReEmitter<BriijEventEmittedEvents, BriijEventHandlerMap>;
410
+
411
+ /**
412
+ * The timestamp for when this event should expire, in milliseconds.
413
+ * Prefers using the server-provided value, but will fall back to local calculation.
414
+ *
415
+ * This value is **safe** to use, as malicious start time and duration are appropriately capped.
416
+ *
417
+ * If the event is not a sticky event (or not supported by the server),
418
+ * then this returns `undefined`.
419
+ */
420
+ public readonly unstableStickyExpiresAt: number | undefined;
421
+
422
+ /**
423
+ * Construct a Matrix Event object
424
+ *
425
+ * @param event - The raw (possibly encrypted) event. <b>Do not access
426
+ * this property</b> directly unless you absolutely have to. Prefer the getter
427
+ * methods defined on this class. Using the getter methods shields your app
428
+ * from changes to event JSON between Matrix versions.
429
+ */
430
+ public constructor(public event: Partial<IEvent> = {}) {
431
+ super();
432
+
433
+ // intern the values of matrix events to force share strings and reduce the
434
+ // amount of needless string duplication. This can save moderate amounts of
435
+ // memory (~10% on a 350MB heap).
436
+ // 'membership' at the event level (rather than the content level) is a legacy
437
+ // field that Element never otherwise looks at, but it will still take up a lot
438
+ // of space if we don't intern it.
439
+ (["state_key", "type", "sender", "room_id", "membership"] as const).forEach((prop) => {
440
+ if (typeof event[prop] !== "string") return;
441
+ event[prop] = internaliseString(event[prop]!);
442
+ });
443
+
444
+ (["membership", "avatar_url", "displayname"] as const).forEach((prop) => {
445
+ if (typeof event.content?.[prop] !== "string") return;
446
+ event.content[prop] = internaliseString(event.content[prop]!);
447
+ });
448
+
449
+ (["rel_type"] as const).forEach((prop) => {
450
+ if (typeof event.content?.["m.relates_to"]?.[prop] !== "string") return;
451
+ event.content["m.relates_to"][prop] = internaliseString(event.content["m.relates_to"][prop]!);
452
+ });
453
+
454
+ this.txnId = event.txn_id;
455
+ // The localTimestamp is calculated using the age.
456
+ // Some events lack an `age` property, either because they are EDUs such as typing events,
457
+ // or due to server-side bugs such as https://github.com/matrix-org/synapse/issues/8429.
458
+ // The fallback in these cases will be to use the origin_server_ts.
459
+ // For EDUs, the origin_server_ts also is not defined so we use Date.now().
460
+ const age = this.getAge();
461
+ const now = Date.now();
462
+ this.localTimestamp = age !== undefined ? now - age : (this.getTs() ?? now);
463
+ this.reEmitter = new TypedReEmitter(this);
464
+ if (this.unstableStickyInfo) {
465
+ if (this.unstableStickyInfo.duration_ttl_ms) {
466
+ this.unstableStickyExpiresAt = now + this.unstableStickyInfo.duration_ttl_ms;
467
+ } else {
468
+ // Bound the timestamp so it doesn't come from the future.
469
+ this.unstableStickyExpiresAt = Math.min(now, this.getTs()) + this.unstableStickyInfo.duration_ms;
470
+ }
471
+ }
472
+ }
473
+
474
+ /**
475
+ * Unstable getter to try and get an extensible event. Note that this might
476
+ * return a falsy value if the event could not be parsed as an extensible
477
+ * event.
478
+ *
479
+ * @deprecated Use stable functions where possible.
480
+ */
481
+ public get unstableExtensibleEvent(): ExtensibleEvent | undefined {
482
+ if (!this._hasCachedExtEv) {
483
+ this._cachedExtEv = ExtensibleEvents.parse(this.getEffectiveEvent()) ?? undefined;
484
+ }
485
+ return this._cachedExtEv;
486
+ }
487
+
488
+ private invalidateExtensibleEvent(): void {
489
+ // just reset the flag - that'll trick the getter into parsing a new event
490
+ this._hasCachedExtEv = false;
491
+ }
492
+
493
+ /**
494
+ * Gets the event as it would appear if it had been sent unencrypted.
495
+ *
496
+ * If the event is encrypted, we attempt to mock up an event as it would have looked had the sender not encrypted it.
497
+ * If the event is not encrypted, a copy of it is simply returned as-is.
498
+ *
499
+ * @returns A shallow copy of the event, in wire format, as it would have been had it not been encrypted.
500
+ */
501
+ public getEffectiveEvent(): IEvent {
502
+ const content = Object.assign({}, this.getContent()); // clone for mutation
503
+
504
+ if (this.getWireType() === EventType.RoomMessageEncrypted) {
505
+ // Encrypted events sometimes aren't symmetrical on the `content` so we'll copy
506
+ // that over too, but only for missing properties. We don't copy over mismatches
507
+ // between the plain and decrypted copies of `content` because we assume that the
508
+ // app is relying on the decrypted version, so we want to expose that as a source
509
+ // of truth here too.
510
+ for (const [key, value] of Object.entries(this.getWireContent())) {
511
+ // Skip fields from the encrypted event schema though - we don't want to leak
512
+ // these.
513
+ if (["algorithm", "ciphertext", "device_id", "sender_key", "session_id"].includes(key)) {
514
+ continue;
515
+ }
516
+
517
+ if (content[key] === undefined) content[key] = value;
518
+ }
519
+ }
520
+
521
+ // clearEvent doesn't have all the fields, so we'll copy what we can from this.event.
522
+ // We also copy over our "fixed" content key.
523
+ return Object.assign({}, this.event, this.clearEvent, { content }) as IEvent;
524
+ }
525
+
526
+ /**
527
+ * Get the event_id for this event.
528
+ * @returns The event ID, e.g. <code>$143350589368169JsLZx:localhost
529
+ * </code>
530
+ */
531
+ public getId(): string | undefined {
532
+ return this.event.event_id;
533
+ }
534
+
535
+ /**
536
+ * Get the user_id for this event.
537
+ * @returns The user ID, e.g. `@alice:matrix.org`
538
+ */
539
+ public getSender(): string | undefined {
540
+ return this.event.sender; // v2 / v1
541
+ }
542
+
543
+ /**
544
+ * Get the (decrypted, if necessary) type of event.
545
+ *
546
+ * @returns The event type, e.g. `m.room.message`
547
+ */
548
+ public getType(): EventType | string {
549
+ if (this.clearEvent) {
550
+ return this.clearEvent.type;
551
+ }
552
+ return this.event.type!;
553
+ }
554
+
555
+ /**
556
+ * Get the (possibly encrypted) type of the event that will be sent to the
557
+ * homeserver.
558
+ *
559
+ * @returns The event type.
560
+ */
561
+ public getWireType(): EventType | string {
562
+ return this.event.type!;
563
+ }
564
+
565
+ /**
566
+ * Get the room_id for this event. This will return `undefined`
567
+ * for `m.presence` events.
568
+ * @returns The room ID, e.g. <code>!cURbafjkfsMDVwdRDQ:matrix.org
569
+ * </code>
570
+ */
571
+ public getRoomId(): string | undefined {
572
+ return this.event.room_id;
573
+ }
574
+
575
+ /**
576
+ * Get the timestamp of this event.
577
+ * @returns The event timestamp, e.g. `1433502692297`
578
+ */
579
+ public getTs(): number {
580
+ return this.event.origin_server_ts!;
581
+ }
582
+
583
+ /**
584
+ * Get the timestamp of this event, as a Date object.
585
+ * @returns The event date, e.g. `new Date(1433502692297)`
586
+ */
587
+ public getDate(): Date | null {
588
+ return this.event.origin_server_ts ? new Date(this.event.origin_server_ts) : null;
589
+ }
590
+
591
+ /**
592
+ * Get a string containing details of this event
593
+ *
594
+ * This is intended for logging, to help trace errors. Example output:
595
+ *
596
+ * @example
597
+ * ```
598
+ * id=$HjnOHV646n0SjLDAqFrgIjim7RCpB7cdMXFrekWYAn type=m.room.encrypted
599
+ * sender=@user:example.com room=!room:example.com ts=2022-10-25T17:30:28.404Z
600
+ * ```
601
+ */
602
+ public getDetails(): string {
603
+ const room = this.getRoomId();
604
+ if (room) {
605
+ // in-room event
606
+ return `id=${this.getId()} type=${this.getWireType()} sender=${this.getSender()} room=${room} ts=${this.getDate()?.toISOString()}`;
607
+ } else {
608
+ // to-device event
609
+ const msgid = this.getContent()[ToDeviceMessageId];
610
+ return `msgid=${msgid} type=${this.getWireType()} sender=${this.getSender()}`;
611
+ }
612
+ }
613
+
614
+ /**
615
+ * Get the (decrypted, if necessary) event content JSON, even if the event
616
+ * was replaced by another event.
617
+ *
618
+ * @returns The event content JSON, or an empty object.
619
+ */
620
+ public getOriginalContent<T = IContent>(): T {
621
+ if (this._localRedactionEvent) {
622
+ return {} as T;
623
+ }
624
+ if (this.clearEvent) {
625
+ return (this.clearEvent.content ?? {}) as T;
626
+ }
627
+ return (this.event.content ?? {}) as T;
628
+ }
629
+
630
+ /**
631
+ * Get the (decrypted, if necessary) event content JSON,
632
+ * or the content from the replacing event, if any.
633
+ * See `makeReplaced`.
634
+ *
635
+ * @returns The event content JSON, or an empty object.
636
+ */
637
+ public getContent<T extends IContent = IContent>(): T {
638
+ if (this._localRedactionEvent) {
639
+ return {} as T;
640
+ } else if (this._replacingEvent) {
641
+ return this._replacingEvent.getContent()["m.new_content"] ?? {};
642
+ } else {
643
+ return this.getOriginalContent();
644
+ }
645
+ }
646
+
647
+ /**
648
+ * Get the (possibly encrypted) event content JSON that will be sent to the
649
+ * homeserver.
650
+ *
651
+ * @returns The event content JSON, or an empty object.
652
+ */
653
+ public getWireContent(): IContent {
654
+ return this.event.content || {};
655
+ }
656
+
657
+ /**
658
+ * Get the event ID of the thread head
659
+ */
660
+ public get threadRootId(): string | undefined {
661
+ // don't allow state events to be threaded as per the spec
662
+ if (this.isState()) {
663
+ return undefined;
664
+ }
665
+ const relatesTo = this.getWireContent()?.["m.relates_to"];
666
+ if (relatesTo?.rel_type === THREAD_RELATION_TYPE.name) {
667
+ return relatesTo.event_id;
668
+ }
669
+ if (this.thread) {
670
+ return this.thread.id;
671
+ }
672
+ if (this.threadId !== undefined) {
673
+ return this.threadId;
674
+ }
675
+ const unsigned = this.getUnsigned();
676
+ if (typeof unsigned[UNSIGNED_THREAD_ID_FIELD.name] === "string") {
677
+ return unsigned[UNSIGNED_THREAD_ID_FIELD.name];
678
+ }
679
+ return undefined;
680
+ }
681
+
682
+ /**
683
+ * A helper to check if an event is a thread's head or not
684
+ */
685
+ public get isThreadRoot(): boolean {
686
+ // don't allow state events to be threaded as per the spec
687
+ if (this.isState()) {
688
+ return false;
689
+ }
690
+
691
+ const threadDetails = this.getServerAggregatedRelation<IThreadBundledRelationship>(THREAD_RELATION_TYPE.name);
692
+
693
+ // Bundled relationships only returned when the sync response is limited
694
+ // hence us having to check both bundled relation and inspect the thread
695
+ // model
696
+ return !!threadDetails || this.threadRootId === this.getId();
697
+ }
698
+
699
+ public get replyEventId(): string | undefined {
700
+ return this.getWireContent()["m.relates_to"]?.["m.in_reply_to"]?.event_id;
701
+ }
702
+
703
+ public get relationEventId(): string | undefined {
704
+ return this.getWireContent()?.["m.relates_to"]?.event_id;
705
+ }
706
+
707
+ /**
708
+ * Get the previous event content JSON. This will only return something for
709
+ * state events which exist in the timeline.
710
+ * @returns The previous event content JSON, or an empty object.
711
+ */
712
+ public getPrevContent(): IContent {
713
+ // v2 then v1 then default
714
+ return this.getUnsigned().prev_content || {};
715
+ }
716
+
717
+ /**
718
+ * Get either 'content' or 'prev_content' depending on if this event is
719
+ * 'forward-looking' or not. This can be modified via event.forwardLooking.
720
+ * In practice, this means we get the chronologically earlier content value
721
+ * for this event (this method should surely be called getEarlierContent)
722
+ * <strong>This method is experimental and may change.</strong>
723
+ * @returns event.content if this event is forward-looking, else
724
+ * event.prev_content.
725
+ */
726
+ public getDirectionalContent(): IContent {
727
+ return this.forwardLooking ? this.getContent() : this.getPrevContent();
728
+ }
729
+
730
+ /**
731
+ * Get the age of this event. This represents the age of the event when the
732
+ * event arrived at the device, and not the age of the event when this
733
+ * function was called.
734
+ * Can only be returned once the server has echo'ed back
735
+ * @returns The age of this event in milliseconds.
736
+ */
737
+ public getAge(): number | undefined {
738
+ return this.getUnsigned().age;
739
+ }
740
+
741
+ /**
742
+ * Get the age of the event when this function was called.
743
+ * This is the 'age' field adjusted according to how long this client has
744
+ * had the event.
745
+ * @returns The age of this event in milliseconds.
746
+ */
747
+ public getLocalAge(): number {
748
+ return Date.now() - this.localTimestamp;
749
+ }
750
+
751
+ /**
752
+ * Get the event state_key if it has one. If necessary, this will perform
753
+ * string-unpacking on the state key, as per MSC4362. This will return
754
+ * <code>undefined</code> for message events.
755
+ * @returns The event's `state_key`.
756
+ */
757
+ public getStateKey(): string | undefined {
758
+ if (this.clearEvent) {
759
+ return this.clearEvent.state_key;
760
+ }
761
+ return this.event.state_key;
762
+ }
763
+
764
+ /**
765
+ * Get the raw event state_key if it has one. This may be string-packed as per
766
+ * MSC4362 if the state event is encrypted. This will return <code>undefined
767
+ * </code> for message events.
768
+ * @returns The event's `state_key`.
769
+ */
770
+ public getWireStateKey(): string | undefined {
771
+ return this.event.state_key;
772
+ }
773
+
774
+ /**
775
+ * Check if this event is a state event.
776
+ * @returns True if this is a state event.
777
+ */
778
+ public isState(): boolean {
779
+ return this.event.state_key !== undefined;
780
+ }
781
+
782
+ /**
783
+ * Get the user's room membership at the time the event was sent, as reported
784
+ * by the server. This uses MSC4115.
785
+ *
786
+ * @returns The user's room membership, or `undefined` if the server does
787
+ * not report it.
788
+ */
789
+ public getMembershipAtEvent(): Membership | string | undefined {
790
+ const unsigned = this.getUnsigned();
791
+ return UNSIGNED_MEMBERSHIP_FIELD.findIn<Membership>(unsigned);
792
+ }
793
+
794
+ /**
795
+ * Replace the content of this event with encrypted versions.
796
+ * (This is used when sending an event; it should not be used by applications).
797
+ *
798
+ * @internal
799
+ *
800
+ * @param cryptoType - type of the encrypted event - typically
801
+ * <tt>"m.room.encrypted"</tt>
802
+ *
803
+ * @param cryptoContent - raw 'content' for the encrypted event.
804
+ *
805
+ * @param senderCurve25519Key - curve25519 key to record for the
806
+ * sender of this event.
807
+ * See {@link BriijEvent#getSenderKey}.
808
+ *
809
+ * @param claimedEd25519Key - claimed ed25519 key to record for the
810
+ * sender if this event.
811
+ * See {@link BriijEvent#getClaimedEd25519Key}
812
+ */
813
+ public makeEncrypted(
814
+ cryptoType: string,
815
+ cryptoContent: object,
816
+ senderCurve25519Key: string,
817
+ claimedEd25519Key: string,
818
+ ): void {
819
+ // keep the plain-text data for 'view source'
820
+ this.clearEvent = {
821
+ type: this.event.type!,
822
+ content: this.event.content!,
823
+ state_key: this.event.state_key,
824
+ };
825
+ this.event.type = cryptoType;
826
+ this.event.content = cryptoContent;
827
+ this.senderCurve25519Key = senderCurve25519Key;
828
+ this.claimedEd25519Key = claimedEd25519Key;
829
+
830
+ // if this is a state event, pack cleartext type and statekey
831
+ if (this.isState()) {
832
+ this.event.state_key = `${this.clearEvent!.type}:${this.clearEvent!.state_key}`;
833
+ }
834
+ }
835
+
836
+ /**
837
+ * Check if this event is currently being decrypted.
838
+ *
839
+ * @returns True if this event is currently being decrypted, else false.
840
+ */
841
+ public isBeingDecrypted(): boolean {
842
+ return this.decryptionPromise != null;
843
+ }
844
+
845
+ public getDecryptionPromise(): Promise<void> | null {
846
+ return this.decryptionPromise;
847
+ }
848
+
849
+ /**
850
+ * Check if this event is an encrypted event which we failed to decrypt
851
+ *
852
+ * (This implies that we might retry decryption at some point in the future)
853
+ *
854
+ * @returns True if this event is an encrypted event which we
855
+ * couldn't decrypt.
856
+ */
857
+ public isDecryptionFailure(): boolean {
858
+ return this._decryptionFailureReason !== null;
859
+ }
860
+
861
+ /** If we failed to decrypt this event, the reason for the failure. Otherwise, `null`. */
862
+ public get decryptionFailureReason(): DecryptionFailureCode | null {
863
+ return this._decryptionFailureReason;
864
+ }
865
+
866
+ public shouldAttemptDecryption(): boolean {
867
+ if (this.isRedacted()) return false;
868
+ if (this.isBeingDecrypted()) return false;
869
+ if (this.clearEvent) return false;
870
+ if (!this.isEncrypted()) return false;
871
+
872
+ return true;
873
+ }
874
+
875
+ /**
876
+ * Start the process of trying to decrypt this event.
877
+ *
878
+ * (This is used within the SDK: it isn't intended for use by applications)
879
+ *
880
+ * @internal
881
+ *
882
+ * @param crypto - crypto module
883
+ *
884
+ * @returns promise which resolves (to undefined) when the decryption
885
+ * attempt is completed.
886
+ */
887
+ public async attemptDecryption(crypto: CryptoBackend, options: IDecryptOptions = {}): Promise<void> {
888
+ // start with a couple of sanity checks.
889
+ if (!this.isEncrypted()) {
890
+ throw new Error("Attempt to decrypt event which isn't encrypted");
891
+ }
892
+
893
+ const alreadyDecrypted = this.clearEvent && !this.isDecryptionFailure();
894
+ if (alreadyDecrypted) {
895
+ // we may want to just ignore this? let's start with rejecting it.
896
+ throw new Error("Attempt to decrypt event which has already been decrypted");
897
+ }
898
+
899
+ // if we already have a decryption attempt in progress, then it may
900
+ // fail because it was using outdated info. We now have reason to
901
+ // succeed where it failed before, but we don't want to have multiple
902
+ // attempts going at the same time, so just set a flag that says we have
903
+ // new info.
904
+ //
905
+ if (this.decryptionPromise) {
906
+ logger.log(`Event ${this.getId()} already being decrypted; queueing a retry`);
907
+ this.retryDecryption = true;
908
+ return this.decryptionPromise;
909
+ }
910
+
911
+ this.decryptionPromise = this.decryptionLoop(crypto, options);
912
+ return this.decryptionPromise;
913
+ }
914
+
915
+ /**
916
+ * Calculate the recipients for keyshare requests.
917
+ *
918
+ * @param userId - the user who received this event.
919
+ *
920
+ * @returns array of recipients
921
+ */
922
+ public getKeyRequestRecipients(userId: string): IKeyRequestRecipient[] {
923
+ // send the request to all of our own devices
924
+ const recipients = [
925
+ {
926
+ userId,
927
+ deviceId: "*",
928
+ },
929
+ ];
930
+
931
+ return recipients;
932
+ }
933
+
934
+ private async decryptionLoop(crypto: CryptoBackend, options: IDecryptOptions = {}): Promise<void> {
935
+ // make sure that this method never runs completely synchronously.
936
+ // (doing so would mean that we would clear decryptionPromise *before*
937
+ // it is set in attemptDecryption - and hence end up with a stuck
938
+ // `decryptionPromise`).
939
+ await Promise.resolve();
940
+
941
+ // eslint-disable-next-line no-constant-condition
942
+ while (true) {
943
+ this.retryDecryption = false;
944
+
945
+ let err: Error | undefined = undefined;
946
+ try {
947
+ const res = await crypto.decryptEvent(this);
948
+ if (options.isRetry === true) {
949
+ logger.info(`Decrypted event on retry (${this.getDetails()})`);
950
+ }
951
+ this.setClearData(res);
952
+ this._decryptionFailureReason = null;
953
+ } catch (e) {
954
+ const detailedError = e instanceof DecryptionError ? (<DecryptionError>e).detailedString : String(e);
955
+
956
+ err = e as Error;
957
+
958
+ // see if we have a retry queued.
959
+ //
960
+ // NB: make sure to keep this check in the same tick of the
961
+ // event loop as `decryptionPromise = null` below - otherwise we
962
+ // risk a race:
963
+ //
964
+ // * A: we check retryDecryption here and see that it is
965
+ // false
966
+ // * B: we get a second call to attemptDecryption, which sees
967
+ // that decryptionPromise is set so sets
968
+ // retryDecryption
969
+ // * A: we continue below, clear decryptionPromise, and
970
+ // never do the retry.
971
+ //
972
+ if (this.retryDecryption) {
973
+ // decryption error, but we have a retry queued.
974
+ logger.log(`Error decrypting event (${this.getDetails()}), but retrying: ${detailedError}`);
975
+ continue;
976
+ }
977
+
978
+ // decryption error, no retries queued. Warn about the error and
979
+ // set it to m.bad.encrypted.
980
+ //
981
+ // the detailedString already includes the name and message of the error, and the stack isn't much use,
982
+ // so we don't bother to log `e` separately.
983
+ logger.warn(`Error decrypting event (${this.getDetails()}): ${detailedError}`);
984
+
985
+ this.setClearDataForDecryptionFailure(String(e));
986
+ this._decryptionFailureReason =
987
+ e instanceof DecryptionError ? (<DecryptionError>e).code : DecryptionFailureCode.UNKNOWN_ERROR;
988
+ }
989
+
990
+ // Make sure we clear 'decryptionPromise' before sending the 'Event.decrypted' event,
991
+ // otherwise the app will be confused to see `isBeingDecrypted` still set when
992
+ // there isn't an `Event.decrypted` on the way.
993
+ //
994
+ // see also notes on retryDecryption above.
995
+ //
996
+ this.decryptionPromise = null;
997
+ this.retryDecryption = false;
998
+
999
+ // Before we emit the event, clear the push actions so that they can be recalculated
1000
+ // by relevant code. We do this because the clear event has now changed, making it
1001
+ // so that existing rules can be re-run over the applicable properties. Stuff like
1002
+ // highlighting when the user's name is mentioned rely on this happening. We also want
1003
+ // to set the push actions before emitting so that any notification listeners don't
1004
+ // pick up the wrong contents.
1005
+ this.setPushDetails();
1006
+
1007
+ if (options.emit !== false) {
1008
+ this.emit(BriijEventEvent.Decrypted, this, err);
1009
+ }
1010
+
1011
+ return;
1012
+ }
1013
+ }
1014
+
1015
+ /**
1016
+ * Update the cleartext data on this event.
1017
+ *
1018
+ * (This is used after decrypting an event; it should not be used by applications).
1019
+ *
1020
+ * @internal
1021
+ *
1022
+ * @param decryptionResult - the decryption result, including the plaintext and some key info
1023
+ */
1024
+ private setClearData(decryptionResult: EventDecryptionResult): void {
1025
+ this.clearEvent = decryptionResult.clearEvent;
1026
+ this.senderCurve25519Key = decryptionResult.senderCurve25519Key ?? null;
1027
+ this.claimedEd25519Key = decryptionResult.claimedEd25519Key ?? null;
1028
+ this.keyForwardedBy = decryptionResult.keyForwardedBy;
1029
+ this.invalidateExtensibleEvent();
1030
+ }
1031
+
1032
+ /**
1033
+ * Update the cleartext data on this event after a decryption failure.
1034
+ *
1035
+ * @param reason - the textual reason for the failure
1036
+ */
1037
+ private setClearDataForDecryptionFailure(reason: string): void {
1038
+ this.clearEvent = {
1039
+ type: EventType.RoomMessage,
1040
+ content: {
1041
+ msgtype: "m.bad.encrypted",
1042
+ body: `** Unable to decrypt: ${reason} **`,
1043
+ },
1044
+ };
1045
+ this.senderCurve25519Key = null;
1046
+ this.claimedEd25519Key = null;
1047
+ this.invalidateExtensibleEvent();
1048
+ }
1049
+
1050
+ /**
1051
+ * Gets the cleartext content for this event. If the event is not encrypted,
1052
+ * or encryption has not been completed, this will return null.
1053
+ *
1054
+ * @returns The cleartext (decrypted) content for the event
1055
+ */
1056
+ public getClearContent(): IContent | null {
1057
+ return this.clearEvent ? this.clearEvent.content : null;
1058
+ }
1059
+
1060
+ /**
1061
+ * Check if the event is encrypted.
1062
+ * @returns True if this event is encrypted.
1063
+ */
1064
+ public isEncrypted(): boolean {
1065
+ return this.event.type === EventType.RoomMessageEncrypted;
1066
+ }
1067
+
1068
+ /**
1069
+ * The curve25519 key for the device that we think sent this event
1070
+ *
1071
+ * For an Olm-encrypted event, this is inferred directly from the DH
1072
+ * exchange at the start of the session: the curve25519 key is involved in
1073
+ * the DH exchange, so only a device which holds the private part of that
1074
+ * key can establish such a session.
1075
+ *
1076
+ * For a megolm-encrypted event, it is inferred from the Olm message which
1077
+ * established the megolm session
1078
+ */
1079
+ public getSenderKey(): string | null {
1080
+ return this.senderCurve25519Key;
1081
+ }
1082
+
1083
+ /**
1084
+ * The additional keys the sender of this encrypted event claims to possess.
1085
+ *
1086
+ * Just a wrapper for #getClaimedEd25519Key (q.v.)
1087
+ */
1088
+ public getKeysClaimed(): Partial<Record<"ed25519", string>> {
1089
+ if (!this.claimedEd25519Key) return {};
1090
+
1091
+ return {
1092
+ ed25519: this.claimedEd25519Key,
1093
+ };
1094
+ }
1095
+
1096
+ /**
1097
+ * Get the ed25519 the sender of this event claims to own.
1098
+ *
1099
+ * For Olm messages, this claim is encoded directly in the plaintext of the
1100
+ * event itself. For megolm messages, it is implied by the m.room_key event
1101
+ * which established the megolm session.
1102
+ *
1103
+ * Until we download the device list of the sender, it's just a claim: the
1104
+ * device list gives a proof that the owner of the curve25519 key used for
1105
+ * this event (and returned by #getSenderKey) also owns the ed25519 key by
1106
+ * signing the public curve25519 key with the ed25519 key.
1107
+ *
1108
+ * In general, applications should not use this method directly, but should
1109
+ * instead use {@link crypto-api!CryptoApi#getEncryptionInfoForEvent}.
1110
+ */
1111
+ public getClaimedEd25519Key(): string | null {
1112
+ return this.claimedEd25519Key;
1113
+ }
1114
+
1115
+ /**
1116
+ * Returns an empty array.
1117
+ *
1118
+ * Previously, this returned the chain of Curve25519 keys through which
1119
+ * this session was forwarded, via `m.forwarded_room_key` events.
1120
+ * However, that is not cryptographically reliable, and clients should not
1121
+ * be using it.
1122
+ *
1123
+ * @see https://github.com/matrix-org/matrix-spec/issues/1089
1124
+ * @deprecated
1125
+ */
1126
+ public getForwardingCurve25519KeyChain(): string[] {
1127
+ return [];
1128
+ }
1129
+
1130
+ /**
1131
+ * @deprecated always returns false
1132
+ */
1133
+ public isKeySourceUntrusted(): false {
1134
+ return false;
1135
+ }
1136
+
1137
+ /**
1138
+ * If another user forwarded the key to this message
1139
+ * (eg via [MSC4268](https://github.com/matrix-org/matrix-spec-proposals/pull/4268)),
1140
+ * get the ID of that user.
1141
+ */
1142
+ public getKeyForwardingUser(): string | undefined {
1143
+ return this.keyForwardedBy;
1144
+ }
1145
+
1146
+ public getUnsigned(): IUnsigned {
1147
+ return this.event.unsigned || {};
1148
+ }
1149
+
1150
+ public setUnsigned(unsigned: IUnsigned): void {
1151
+ this.event.unsigned = unsigned;
1152
+ }
1153
+
1154
+ public unmarkLocallyRedacted(): boolean {
1155
+ const value = this._localRedactionEvent;
1156
+ this._localRedactionEvent = null;
1157
+ if (this.event.unsigned) {
1158
+ this.event.unsigned.redacted_because = undefined;
1159
+ }
1160
+ return !!value;
1161
+ }
1162
+
1163
+ public markLocallyRedacted(redactionEvent: BriijEvent): void {
1164
+ if (this._localRedactionEvent) return;
1165
+ this.emit(BriijEventEvent.BeforeRedaction, this, redactionEvent);
1166
+ this._localRedactionEvent = redactionEvent;
1167
+ if (!this.event.unsigned) {
1168
+ this.event.unsigned = {};
1169
+ }
1170
+ this.event.unsigned.redacted_because = redactionEvent.event as IEvent;
1171
+ }
1172
+
1173
+ /**
1174
+ * Change the visibility of an event, as per https://github.com/matrix-org/matrix-doc/pull/3531 .
1175
+ *
1176
+ * @param visibilityChange - event holding a hide/unhide payload, or nothing
1177
+ * if the event is being reset to its original visibility (presumably
1178
+ * by a visibility event being redacted).
1179
+ *
1180
+ * @remarks
1181
+ * Fires {@link BriijEventEvent.VisibilityChange} if `visibilityEvent`
1182
+ * caused a change in the actual visibility of this event, either by making it
1183
+ * visible (if it was hidden), by making it hidden (if it was visible) or by
1184
+ * changing the reason (if it was hidden).
1185
+ */
1186
+ public applyVisibilityEvent(visibilityChange?: IVisibilityChange): void {
1187
+ const visible = visibilityChange?.visible ?? true;
1188
+ const reason = visibilityChange?.reason ?? null;
1189
+ let change = false;
1190
+ if (this.visibility.visible !== visible) {
1191
+ change = true;
1192
+ } else if (!this.visibility.visible && this.visibility["reason"] !== reason) {
1193
+ change = true;
1194
+ }
1195
+ if (change) {
1196
+ if (visible) {
1197
+ this.visibility = MESSAGE_VISIBLE;
1198
+ } else {
1199
+ this.visibility = Object.freeze({
1200
+ visible: false,
1201
+ reason,
1202
+ });
1203
+ }
1204
+ this.emit(BriijEventEvent.VisibilityChange, this, visible);
1205
+ }
1206
+ }
1207
+
1208
+ /**
1209
+ * Return instructions to display or hide the message.
1210
+ *
1211
+ * @returns Instructions determining whether the message
1212
+ * should be displayed.
1213
+ */
1214
+ public messageVisibility(): MessageVisibility {
1215
+ // Note: We may return `this.visibility` without fear, as
1216
+ // this is a shallow frozen object.
1217
+ return this.visibility;
1218
+ }
1219
+
1220
+ /**
1221
+ * Update the content of an event in the same way it would be by the server
1222
+ * if it were redacted before it was sent to us
1223
+ *
1224
+ * @param redactionEvent - event causing the redaction
1225
+ * @param room - the room in which the event exists
1226
+ */
1227
+ public makeRedacted(redactionEvent: BriijEvent, room: Room): void {
1228
+ // quick sanity-check
1229
+ if (!redactionEvent.event) {
1230
+ throw new Error("invalid redactionEvent in makeRedacted");
1231
+ }
1232
+
1233
+ this._localRedactionEvent = null;
1234
+
1235
+ this.emit(BriijEventEvent.BeforeRedaction, this, redactionEvent);
1236
+
1237
+ this._replacingEvent = null;
1238
+ // we attempt to replicate what we would see from the server if
1239
+ // the event had been redacted before we saw it.
1240
+ //
1241
+ // The server removes (most of) the content of the event, and adds a
1242
+ // "redacted_because" key to the unsigned section containing the
1243
+ // redacted event.
1244
+ if (!this.event.unsigned) {
1245
+ this.event.unsigned = {};
1246
+ }
1247
+ this.event.unsigned.redacted_because = redactionEvent.event as IEvent;
1248
+
1249
+ for (const key in this.event) {
1250
+ if (this.event.hasOwnProperty(key) && !REDACT_KEEP_KEYS.has(key)) {
1251
+ delete this.event[key as keyof IEvent];
1252
+ }
1253
+ }
1254
+
1255
+ // If the event is encrypted prune the decrypted bits
1256
+ if (this.isEncrypted()) {
1257
+ this.clearEvent = undefined;
1258
+ }
1259
+
1260
+ const keeps =
1261
+ this.getType() in REDACT_KEEP_CONTENT_MAP
1262
+ ? REDACT_KEEP_CONTENT_MAP[this.getType() as keyof typeof REDACT_KEEP_CONTENT_MAP]
1263
+ : {};
1264
+ const content = this.getContent();
1265
+ for (const key in content) {
1266
+ if (content.hasOwnProperty(key) && !keeps[key]) {
1267
+ delete content[key];
1268
+ }
1269
+ }
1270
+
1271
+ // If the redacted event was in a thread (but not thread root), move it
1272
+ // to the main timeline. This will change if MSC3389 is merged.
1273
+ if (!this.isThreadRoot && this.threadRootId && this.threadRootId !== this.getId()) {
1274
+ this.moveAllRelatedToMainTimeline(room);
1275
+ redactionEvent.moveToMainTimeline(room);
1276
+ }
1277
+
1278
+ this.invalidateExtensibleEvent();
1279
+ }
1280
+
1281
+ private moveAllRelatedToMainTimeline(room: Room): void {
1282
+ const thread = this.thread;
1283
+ this.moveToMainTimeline(room);
1284
+
1285
+ // If we dont have access to the thread, we can only move this
1286
+ // event, not things related to it.
1287
+ if (thread) {
1288
+ for (const event of thread.events) {
1289
+ if (event.getRelation()?.event_id === this.getId()) {
1290
+ event.moveAllRelatedToMainTimeline(room);
1291
+ }
1292
+ }
1293
+ }
1294
+ }
1295
+
1296
+ private moveToMainTimeline(room: Room): void {
1297
+ // Remove it from its thread
1298
+ this.thread?.timelineSet.removeEvent(this.getId()!);
1299
+ this.setThread(undefined);
1300
+
1301
+ // And insert it into the main timeline
1302
+ const timeline = room.getLiveTimeline();
1303
+ // We use insertEventIntoTimeline to insert it in timestamp order,
1304
+ // because we don't know where it should go (until we have MSC4033).
1305
+ timeline
1306
+ .getTimelineSet()
1307
+ .insertEventIntoTimeline(this, timeline, timeline.getState(EventTimeline.FORWARDS)!, false);
1308
+ }
1309
+
1310
+ /**
1311
+ * Check if this event has been redacted
1312
+ *
1313
+ * @returns True if this event has been redacted
1314
+ */
1315
+ public isRedacted(): boolean {
1316
+ return Boolean(this.getUnsigned().redacted_because);
1317
+ }
1318
+
1319
+ /**
1320
+ * Check if this event is a redaction of another event
1321
+ *
1322
+ * @returns True if this event is a redaction
1323
+ */
1324
+ public isRedaction(): boolean {
1325
+ return this.getType() === EventType.RoomRedaction;
1326
+ }
1327
+
1328
+ /**
1329
+ * Return the visibility change caused by this event,
1330
+ * as per https://github.com/matrix-org/matrix-doc/pull/3531.
1331
+ *
1332
+ * @returns If the event is a well-formed visibility change event,
1333
+ * an instance of `IVisibilityChange`, otherwise `null`.
1334
+ */
1335
+ public asVisibilityChange(): IVisibilityChange | null {
1336
+ if (!EVENT_VISIBILITY_CHANGE_TYPE.matches(this.getType())) {
1337
+ // Not a visibility change event.
1338
+ return null;
1339
+ }
1340
+ const relation = this.getRelation();
1341
+ if (!relation || relation.rel_type != "m.reference") {
1342
+ // Ill-formed, ignore this event.
1343
+ return null;
1344
+ }
1345
+ const eventId = relation.event_id;
1346
+ if (!eventId) {
1347
+ // Ill-formed, ignore this event.
1348
+ return null;
1349
+ }
1350
+ const content = this.getWireContent();
1351
+ const visible = !!content.visible;
1352
+ const reason = content.reason;
1353
+ if (reason && typeof reason != "string") {
1354
+ // Ill-formed, ignore this event.
1355
+ return null;
1356
+ }
1357
+ // Well-formed visibility change event.
1358
+ return {
1359
+ visible,
1360
+ reason,
1361
+ eventId,
1362
+ };
1363
+ }
1364
+
1365
+ /**
1366
+ * Check if this event alters the visibility of another event,
1367
+ * as per https://github.com/matrix-org/matrix-doc/pull/3531.
1368
+ *
1369
+ * @returns True if this event alters the visibility
1370
+ * of another event.
1371
+ */
1372
+ public isVisibilityEvent(): boolean {
1373
+ return EVENT_VISIBILITY_CHANGE_TYPE.matches(this.getType());
1374
+ }
1375
+
1376
+ /**
1377
+ * Get the (decrypted, if necessary) redaction event JSON
1378
+ * if event was redacted
1379
+ *
1380
+ * @returns The redaction event JSON, or an empty object
1381
+ */
1382
+ public getRedactionEvent(): IEvent | EmptyObject | null {
1383
+ if (!this.isRedacted()) return null;
1384
+
1385
+ if (this.clearEvent?.unsigned) {
1386
+ return this.clearEvent?.unsigned.redacted_because ?? null;
1387
+ } else if (this.event.unsigned?.redacted_because) {
1388
+ return this.event.unsigned.redacted_because;
1389
+ } else {
1390
+ return {};
1391
+ }
1392
+ }
1393
+
1394
+ /**
1395
+ * Get the push actions, if known, for this event
1396
+ *
1397
+ * @returns push actions
1398
+ */
1399
+ public getPushActions(): IActionsObject | null {
1400
+ return this.pushDetails.actions || null;
1401
+ }
1402
+
1403
+ /**
1404
+ * Get the push details, if known, for this event
1405
+ *
1406
+ * @returns push actions
1407
+ */
1408
+ public getPushDetails(): PushDetails {
1409
+ return this.pushDetails;
1410
+ }
1411
+
1412
+ /**
1413
+ * Set the push details for this event.
1414
+ *
1415
+ * @param pushActions - push actions
1416
+ * @param rule - the executed push rule
1417
+ */
1418
+ public setPushDetails(pushActions?: IActionsObject, rule?: IAnnotatedPushRule): void {
1419
+ this.pushDetails = {
1420
+ actions: pushActions,
1421
+ rule,
1422
+ };
1423
+ }
1424
+
1425
+ /**
1426
+ * Replace the `event` property and recalculate any properties based on it.
1427
+ * @param event - the object to assign to the `event` property
1428
+ */
1429
+ public handleRemoteEcho(event: object): void {
1430
+ const oldUnsigned = this.getUnsigned();
1431
+ const oldId = this.getId();
1432
+ this.event = event;
1433
+ // if this event was redacted before it was sent, it's locally marked as redacted.
1434
+ // At this point, we've received the remote echo for the event, but not yet for
1435
+ // the redaction that we are sending ourselves. Preserve the locally redacted
1436
+ // state by copying over redacted_because so we don't get a flash of
1437
+ // redacted, not-redacted, redacted as remote echos come in
1438
+ if (oldUnsigned.redacted_because) {
1439
+ if (!this.event.unsigned) {
1440
+ this.event.unsigned = {};
1441
+ }
1442
+ this.event.unsigned.redacted_because = oldUnsigned.redacted_because;
1443
+ }
1444
+ // successfully sent.
1445
+ this.setStatus(null);
1446
+ if (this.getId() !== oldId) {
1447
+ // emit the event if it changed
1448
+ this.emit(BriijEventEvent.LocalEventIdReplaced, this);
1449
+ }
1450
+
1451
+ this.localTimestamp = Date.now() - (this.getAge() ?? 0);
1452
+ }
1453
+
1454
+ /**
1455
+ * Whether the event is in any phase of sending, send failure, waiting for
1456
+ * remote echo, etc.
1457
+ */
1458
+ public isSending(): boolean {
1459
+ return !!this.status;
1460
+ }
1461
+
1462
+ /**
1463
+ * Update the event's sending status and emit an event as well.
1464
+ *
1465
+ * @param status - The new status
1466
+ */
1467
+ public setStatus(status: EventStatus | null): void {
1468
+ this.status = status;
1469
+ this.emit(BriijEventEvent.Status, this, status);
1470
+ }
1471
+
1472
+ public replaceLocalEventId(eventId: string): void {
1473
+ this.event.event_id = eventId;
1474
+ this.emit(BriijEventEvent.LocalEventIdReplaced, this);
1475
+ }
1476
+
1477
+ /**
1478
+ * Get whether the event is a relation event, and of a given type if
1479
+ * `relType` is passed in. State events cannot be relation events
1480
+ *
1481
+ * @param relType - if given, checks that the relation is of the
1482
+ * given type
1483
+ */
1484
+ public isRelation(relType?: string): boolean {
1485
+ // Relation info is lifted out of the encrypted content when sent to
1486
+ // encrypted rooms, so we have to check `getWireContent` for this.
1487
+ const relation = this.getWireContent()?.["m.relates_to"];
1488
+ if (
1489
+ this.isState() &&
1490
+ !!relation?.rel_type &&
1491
+ ([RelationType.Replace, RelationType.Thread] as string[]).includes(relation.rel_type)
1492
+ ) {
1493
+ // State events cannot be m.replace or m.thread relations
1494
+ return false;
1495
+ }
1496
+ return !!(relation?.rel_type && relation.event_id && (relType ? relation.rel_type === relType : true));
1497
+ }
1498
+
1499
+ /**
1500
+ * Get relation info for the event, if any.
1501
+ */
1502
+ public getRelation(): IEventRelation | null {
1503
+ if (!this.isRelation()) {
1504
+ return null;
1505
+ }
1506
+ return this.getWireContent()["m.relates_to"] ?? null;
1507
+ }
1508
+
1509
+ /**
1510
+ * Set an event that replaces the content of this event, through an m.replace relation.
1511
+ *
1512
+ * @param newEvent - the event with the replacing content, if any.
1513
+ *
1514
+ * @remarks
1515
+ * Fires {@link BriijEventEvent.Replaced}
1516
+ */
1517
+ public makeReplaced(newEvent?: BriijEvent): void {
1518
+ // don't allow redacted events to be replaced.
1519
+ // if newEvent is null we allow to go through though,
1520
+ // as with local redaction, the replacing event might get
1521
+ // cancelled, which should be reflected on the target event.
1522
+ if (this.isRedacted() && newEvent) {
1523
+ return;
1524
+ }
1525
+ // don't allow state events to be replaced using this mechanism as per MSC2676
1526
+ if (this.isState()) {
1527
+ return;
1528
+ }
1529
+ if (this._replacingEvent !== newEvent) {
1530
+ this._replacingEvent = newEvent ?? null;
1531
+ this.emit(BriijEventEvent.Replaced, this);
1532
+ this.invalidateExtensibleEvent();
1533
+ }
1534
+ }
1535
+
1536
+ /**
1537
+ * Returns the status of any associated edit or redaction
1538
+ * (not for reactions/annotations as their local echo doesn't affect the original event),
1539
+ * or else the status of the event.
1540
+ */
1541
+ public getAssociatedStatus(): EventStatus | null {
1542
+ if (this._replacingEvent) {
1543
+ return this._replacingEvent.status;
1544
+ } else if (this._localRedactionEvent) {
1545
+ return this._localRedactionEvent.status;
1546
+ }
1547
+ return this.status;
1548
+ }
1549
+
1550
+ public getServerAggregatedRelation<T>(relType: RelationType | string): T | undefined {
1551
+ return this.getUnsigned()["m.relations"]?.[relType];
1552
+ }
1553
+
1554
+ /**
1555
+ * Returns the event ID of the event replacing the content of this event, if any.
1556
+ */
1557
+ public replacingEventId(): string | undefined {
1558
+ const replaceRelation = this.getServerAggregatedRelation<IAggregatedRelation>(RelationType.Replace);
1559
+ if (replaceRelation) {
1560
+ return replaceRelation.event_id;
1561
+ } else if (this._replacingEvent) {
1562
+ return this._replacingEvent.getId();
1563
+ }
1564
+ }
1565
+
1566
+ /**
1567
+ * Returns the event replacing the content of this event, if any.
1568
+ * Replacements are aggregated on the server, so this would only
1569
+ * return an event in case it came down the sync, or for local echo of edits.
1570
+ */
1571
+ public replacingEvent(): BriijEvent | null {
1572
+ return this._replacingEvent;
1573
+ }
1574
+
1575
+ /**
1576
+ * Returns the origin_server_ts of the event replacing the content of this event, if any.
1577
+ */
1578
+ public replacingEventDate(): Date | undefined {
1579
+ const replaceRelation = this.getServerAggregatedRelation<IAggregatedRelation>(RelationType.Replace);
1580
+ if (replaceRelation) {
1581
+ const ts = replaceRelation.origin_server_ts;
1582
+ if (Number.isFinite(ts)) {
1583
+ return new Date(ts);
1584
+ }
1585
+ } else if (this._replacingEvent) {
1586
+ return this._replacingEvent.getDate() ?? undefined;
1587
+ }
1588
+ }
1589
+
1590
+ /**
1591
+ * Returns the event that wants to redact this event, but hasn't been sent yet.
1592
+ * @returns the event
1593
+ */
1594
+ public localRedactionEvent(): BriijEvent | null {
1595
+ return this._localRedactionEvent;
1596
+ }
1597
+
1598
+ /**
1599
+ * For relations and redactions, returns the event_id this event is referring to.
1600
+ */
1601
+ public getAssociatedId(): string | undefined {
1602
+ const relation = this.getRelation();
1603
+ if (this.replyEventId) {
1604
+ return this.replyEventId;
1605
+ } else if (relation) {
1606
+ return relation.event_id;
1607
+ } else if (this.isRedaction()) {
1608
+ return this.event.redacts;
1609
+ }
1610
+ }
1611
+
1612
+ /**
1613
+ * Checks if this event is associated with another event. See `getAssociatedId`.
1614
+ */
1615
+ public hasAssociation(): boolean {
1616
+ return !!this.getAssociatedId();
1617
+ }
1618
+
1619
+ /**
1620
+ * Update the related id with a new one.
1621
+ *
1622
+ * Used to replace a local id with remote one before sending
1623
+ * an event with a related id.
1624
+ *
1625
+ * @param eventId - the new event id
1626
+ */
1627
+ public updateAssociatedId(eventId: string): void {
1628
+ const relation = this.getRelation();
1629
+ if (relation) {
1630
+ relation.event_id = eventId;
1631
+ } else if (this.isRedaction()) {
1632
+ this.event.redacts = eventId;
1633
+ }
1634
+ }
1635
+
1636
+ /**
1637
+ * Flags an event as cancelled due to future conditions. For example, a verification
1638
+ * request event in the same sync transaction may be flagged as cancelled to warn
1639
+ * listeners that a cancellation event is coming down the same pipe shortly.
1640
+ * @param cancelled - Whether the event is to be cancelled or not.
1641
+ */
1642
+ public flagCancelled(cancelled = true): void {
1643
+ this._isCancelled = cancelled;
1644
+ }
1645
+
1646
+ /**
1647
+ * Gets whether or not the event is flagged as cancelled. See flagCancelled() for
1648
+ * more information.
1649
+ * @returns True if the event is cancelled, false otherwise.
1650
+ */
1651
+ public isCancelled(): boolean {
1652
+ return this._isCancelled;
1653
+ }
1654
+
1655
+ /**
1656
+ * Get a copy/snapshot of this event. The returned copy will be loosely linked
1657
+ * back to this instance, though will have "frozen" event information. Other
1658
+ * properties of this BriijEvent instance will be copied verbatim, which can
1659
+ * mean they are in reference to this instance despite being on the copy too.
1660
+ * The reference the snapshot uses does not change, however members aside from
1661
+ * the underlying event will not be deeply cloned, thus may be mutated internally.
1662
+ * For example, the sender profile will be copied over at snapshot time, and
1663
+ * the sender profile internally may mutate without notice to the consumer.
1664
+ *
1665
+ * This is meant to be used to snapshot the event details themselves, not the
1666
+ * features (such as sender) surrounding the event.
1667
+ * @returns A snapshot of this event.
1668
+ */
1669
+ public toSnapshot(): BriijEvent {
1670
+ const ev = new BriijEvent(JSON.parse(JSON.stringify(this.event)));
1671
+ for (const [p, v] of Object.entries(this)) {
1672
+ if (p !== "event") {
1673
+ // exclude the thing we just cloned
1674
+ // @ts-ignore - XXX: this is just nasty
1675
+ ev[p as keyof BriijEvent] = v;
1676
+ }
1677
+ }
1678
+ return ev;
1679
+ }
1680
+
1681
+ /**
1682
+ * Determines if this event is equivalent to the given event. This only checks
1683
+ * the event object itself, not the other properties of the event. Intended for
1684
+ * use with toSnapshot() to identify events changing.
1685
+ * @param otherEvent - The other event to check against.
1686
+ * @returns True if the events are the same, false otherwise.
1687
+ */
1688
+ public isEquivalentTo(otherEvent?: BriijEvent): boolean {
1689
+ if (!otherEvent) return false;
1690
+ if (otherEvent === this) return true;
1691
+ const myProps = deepSortedObjectEntries(this.event);
1692
+ const theirProps = deepSortedObjectEntries(otherEvent.event);
1693
+ return JSON.stringify(myProps) === JSON.stringify(theirProps);
1694
+ }
1695
+
1696
+ /**
1697
+ * Summarise the event as JSON.
1698
+ *
1699
+ * If encrypted, include both the decrypted and encrypted view of the event.
1700
+ *
1701
+ * This is named `toJSON` for use with `JSON.stringify` which checks objects
1702
+ * for functions named `toJSON` and will call them to customise the output
1703
+ * if they are defined.
1704
+ *
1705
+ * **WARNING** Do not log the result of this method; otherwise, it will end up
1706
+ * in rageshakes, leading to a privacy violation.
1707
+ *
1708
+ * @deprecated Prefer to use {@link BriijEvent#getEffectiveEvent} or similar.
1709
+ * This method will be removed soon; it is too easy to use it accidentally
1710
+ * and cause a privacy violation (cf https://github.com/vector-im/element-web/issues/26380).
1711
+ * In any case, the value it returns is not a faithful serialization of the object.
1712
+ */
1713
+ public toJSON(): object {
1714
+ const event = this.getEffectiveEvent();
1715
+
1716
+ if (!this.isEncrypted()) {
1717
+ return event;
1718
+ }
1719
+
1720
+ return {
1721
+ decrypted: event,
1722
+ encrypted: this.event,
1723
+ };
1724
+ }
1725
+
1726
+ public setTxnId(txnId: string): void {
1727
+ this.txnId = txnId;
1728
+ }
1729
+
1730
+ public getTxnId(): string | undefined {
1731
+ return this.txnId;
1732
+ }
1733
+
1734
+ /**
1735
+ * Set the instance of a thread associated with the current event
1736
+ * @param thread - the thread
1737
+ */
1738
+ public setThread(thread?: Thread): void {
1739
+ // don't allow state events to be threaded as per the spec
1740
+ if (this.isState()) {
1741
+ return;
1742
+ }
1743
+ if (this.thread) {
1744
+ this.reEmitter.stopReEmitting(this.thread, [ThreadEvent.Update]);
1745
+ }
1746
+ this.thread = thread;
1747
+ this.setThreadId(thread?.id);
1748
+ if (thread) {
1749
+ this.reEmitter.reEmit(thread, [ThreadEvent.Update]);
1750
+ }
1751
+ }
1752
+
1753
+ /**
1754
+ * Get the instance of the thread associated with the current event
1755
+ */
1756
+ public getThread(): Thread | undefined {
1757
+ return this.thread;
1758
+ }
1759
+
1760
+ public setThreadId(threadId?: string): void {
1761
+ this.threadId = threadId;
1762
+ }
1763
+
1764
+ /**
1765
+ * Unstable getter to try and get the sticky information for the event.
1766
+ * If the event is not a sticky event (or not supported by the server),
1767
+ * then this returns `undefined`.
1768
+ *
1769
+ * `duration_ms` is safely bounded to a hour.
1770
+ */
1771
+ public get unstableStickyInfo(): { duration_ms: number; duration_ttl_ms?: number } | undefined {
1772
+ if (!this.event.msc4354_sticky?.duration_ms) {
1773
+ return undefined;
1774
+ }
1775
+ return {
1776
+ duration_ms: Math.min(MAX_STICKY_DURATION_MS, this.event.msc4354_sticky.duration_ms),
1777
+ // This is assumed to be bounded server-side.
1778
+ duration_ttl_ms: this.event.unsigned?.msc4354_sticky_duration_ttl_ms,
1779
+ };
1780
+ }
1781
+ }
1782
+
1783
+ /* REDACT_KEEP_KEYS gives the keys we keep when an event is redacted
1784
+ *
1785
+ * This is specified here:
1786
+ * http://matrix.org/speculator/spec/HEAD/client_server/latest.html#redactions
1787
+ *
1788
+ * Also:
1789
+ * - We keep 'unsigned' since that is created by the local server
1790
+ * - We keep user_id for backwards-compat with v1
1791
+ */
1792
+ const REDACT_KEEP_KEYS = new Set([
1793
+ "event_id",
1794
+ "type",
1795
+ "room_id",
1796
+ "user_id",
1797
+ "sender",
1798
+ "state_key",
1799
+ "prev_state",
1800
+ "content",
1801
+ "unsigned",
1802
+ "origin_server_ts",
1803
+ ]);
1804
+
1805
+ // a map from state event type to the .content keys we keep when an event is redacted
1806
+ const REDACT_KEEP_CONTENT_MAP: Record<string, Record<string, 1>> = {
1807
+ [EventType.RoomMember]: { membership: 1 },
1808
+ [EventType.RoomJoinRules]: { join_rule: 1 },
1809
+ [EventType.RoomPowerLevels]: {
1810
+ ban: 1,
1811
+ events: 1,
1812
+ events_default: 1,
1813
+ kick: 1,
1814
+ redact: 1,
1815
+ state_default: 1,
1816
+ users: 1,
1817
+ users_default: 1,
1818
+ },
1819
+ } as const;