@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,3548 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ /*
6
+ Copyright 2015 - 2023 The Matrix.org Foundation C.I.C.
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+ */
20
+
21
+ import { M_POLL_START } from "matrix-events-sdk";
22
+ import { DuplicateStrategy, EventTimelineSet } from "./event-timeline-set.js";
23
+ import { Direction, EventTimeline } from "./event-timeline.js";
24
+ import { getHttpUriForMxc } from "../content-repo.js";
25
+ import * as utils from "../utils.js";
26
+ import { normalize, noUnsafeEventProps, removeElement } from "../utils.js";
27
+ import { BriijEvent, BriijEventEvent } from "./event.js";
28
+ import { EventStatus } from "./event-status.js";
29
+ import { RoomMember } from "./room-member.js";
30
+ import { RoomSummary } from "./room-summary.js";
31
+ import { logger } from "../logger.js";
32
+ import { TypedReEmitter } from "../ReEmitter.js";
33
+ import { EVENT_VISIBILITY_CHANGE_TYPE, EventType, RelationType, RoomCreateTypeField, RoomType, UNSIGNED_THREAD_ID_FIELD, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "../@types/event.js";
34
+ import { PendingEventOrdering } from "../client.js";
35
+ import { Filter } from "../filter.js";
36
+ import { RoomStateEvent } from "./room-state.js";
37
+ import { BeaconEvent } from "./beacon.js";
38
+ import { FILTER_RELATED_BY_REL_TYPES, FILTER_RELATED_BY_SENDERS, Thread, THREAD_RELATION_TYPE, ThreadEvent, ThreadFilterType } from "./thread.js";
39
+ import { MAIN_ROOM_TIMELINE, ReceiptType } from "../@types/read_receipts.js";
40
+ import { RelationsContainer } from "./relations-container.js";
41
+ import { ReadReceipt, synthesizeReceipt } from "./read-receipt.js";
42
+ import { isPollEvent, Poll, PollEvent } from "./poll.js";
43
+ import { RoomReceipts } from "./room-receipts.js";
44
+ import { compareEventOrdering } from "./compare-event-ordering.js";
45
+ import { KnownMembership } from "../@types/membership.js";
46
+ import { RoomVersionStability } from "../serverCapabilities.js";
47
+ import { RoomStickyEventsStore, RoomStickyEventsEvent } from "./room-sticky-events.js";
48
+
49
+ // These constants are used as sane defaults when the homeserver doesn't support
50
+ // the m.room_versions capability. In practice, KNOWN_SAFE_ROOM_VERSION should be
51
+ // the same as the common default room version whereas SAFE_ROOM_VERSIONS are the
52
+ // room versions which are considered okay for people to run without being asked
53
+ // to upgrade (ie: "stable"). Eventually, we should remove these when all homeservers
54
+ // return an m.room_versions capability.
55
+ export var KNOWN_SAFE_ROOM_VERSION = "10";
56
+ var SAFE_ROOM_VERSIONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
57
+ // When inserting a visibility event affecting event `eventId`, we
58
+ // need to scan through existing visibility events for `eventId`.
59
+ // In theory, this could take an unlimited amount of time if:
60
+ //
61
+ // - the visibility event was sent by a moderator; and
62
+ // - `eventId` already has many visibility changes (usually, it should
63
+ // be 2 or less); and
64
+ // - for some reason, the visibility changes are received out of order
65
+ // (usually, this shouldn't happen at all).
66
+ //
67
+ // For this reason, we limit the number of events to scan through,
68
+ // expecting that a broken visibility change for a single event in
69
+ // an extremely uncommon case (possibly a DoS) is a small
70
+ // price to pay to keep matrix-js-sdk responsive.
71
+ var MAX_NUMBER_OF_VISIBILITY_EVENTS_TO_SCAN_THROUGH = 30;
72
+ export var NotificationCountType = /*#__PURE__*/function (NotificationCountType) {
73
+ NotificationCountType["Highlight"] = "highlight";
74
+ NotificationCountType["Total"] = "total";
75
+ return NotificationCountType;
76
+ }({});
77
+ export var RoomEvent = /*#__PURE__*/function (RoomEvent) {
78
+ RoomEvent["MyMembership"] = "Room.myMembership";
79
+ RoomEvent["Tags"] = "Room.tags";
80
+ RoomEvent["AccountData"] = "Room.accountData";
81
+ RoomEvent["Receipt"] = "Room.receipt";
82
+ RoomEvent["Name"] = "Room.name";
83
+ RoomEvent["Redaction"] = "Room.redaction";
84
+ RoomEvent["RedactionCancelled"] = "Room.redactionCancelled";
85
+ RoomEvent["LocalEchoUpdated"] = "Room.localEchoUpdated";
86
+ RoomEvent["Timeline"] = "Room.timeline";
87
+ RoomEvent["TimelineReset"] = "Room.timelineReset";
88
+ RoomEvent["TimelineRefresh"] = "Room.TimelineRefresh";
89
+ RoomEvent["OldStateUpdated"] = "Room.OldStateUpdated";
90
+ RoomEvent["CurrentStateUpdated"] = "Room.CurrentStateUpdated";
91
+ RoomEvent["HistoryImportedWithinTimeline"] = "Room.historyImportedWithinTimeline";
92
+ RoomEvent["UnreadNotifications"] = "Room.UnreadNotifications";
93
+ RoomEvent["Summary"] = "Room.Summary";
94
+ return RoomEvent;
95
+ }({});
96
+ export class Room extends ReadReceipt {
97
+ /**
98
+ * Construct a new Room.
99
+ *
100
+ * <p>For a room, we store an ordered sequence of timelines, which may or may not
101
+ * be continuous. Each timeline lists a series of events, as well as tracking
102
+ * the room state at the start and the end of the timeline. It also tracks
103
+ * forward and backward pagination tokens, as well as containing links to the
104
+ * next timeline in the sequence.
105
+ *
106
+ * <p>There is one special timeline - the 'live' timeline, which represents the
107
+ * timeline to which events are being added in real-time as they are received
108
+ * from the /sync API. Note that you should not retain references to this
109
+ * timeline - even if it is the current timeline right now, it may not remain
110
+ * so if the server gives us a timeline gap in /sync.
111
+ *
112
+ * <p>In order that we can find events from their ids later, we also maintain a
113
+ * map from event_id to timeline and index.
114
+ *
115
+ * @param roomId - Required. The ID of this room.
116
+ * @param client - Required. The client, used to lazy load members.
117
+ * @param myUserId - Required. The ID of the syncing user.
118
+ * @param opts - Configuration options
119
+ */
120
+ constructor(roomId, client, myUserId) {
121
+ var _this;
122
+ var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
123
+ // In some cases, we add listeners for every displayed Matrix event, so it's
124
+ // common to have quite a few more than the default limit.
125
+ super();
126
+ _this = this;
127
+ this.roomId = roomId;
128
+ this.client = client;
129
+ this.myUserId = myUserId;
130
+ this.opts = opts;
131
+ _defineProperty(this, "reEmitter", void 0);
132
+ _defineProperty(this, "txnToEvent", new Map());
133
+ // Pending in-flight requests { string: BriijEvent }
134
+ _defineProperty(this, "notificationCounts", {});
135
+ _defineProperty(this, "bumpStamp", undefined);
136
+ _defineProperty(this, "threadNotifications", new Map());
137
+ _defineProperty(this, "cachedThreadReadReceipts", new Map());
138
+ // Useful to know at what point the current user has started using threads in this room
139
+ _defineProperty(this, "oldestThreadedReceiptTs", Infinity);
140
+ /**
141
+ * A record of the latest unthread receipts per user
142
+ * This is useful in determining whether a user has read a thread or not
143
+ */
144
+ _defineProperty(this, "unthreadedReceipts", new Map());
145
+ _defineProperty(this, "timelineSets", void 0);
146
+ _defineProperty(this, "polls", new Map());
147
+ /**
148
+ * Empty array if the timeline sets have not been initialised. After initialisation:
149
+ * 0: All threads
150
+ * 1: Threads the current user has participated in
151
+ */
152
+ _defineProperty(this, "threadsTimelineSets", []);
153
+ // any filtered timeline sets we're maintaining for this room
154
+ _defineProperty(this, "filteredTimelineSets", {});
155
+ // filter_id: timelineSet
156
+ _defineProperty(this, "timelineNeedsRefresh", false);
157
+ _defineProperty(this, "pendingEventList", void 0);
158
+ // read by megolm via getter; boolean value - null indicates "use global value"
159
+ _defineProperty(this, "blacklistUnverifiedDevices", void 0);
160
+ _defineProperty(this, "selfMembership", void 0);
161
+ /**
162
+ * A `Hero` is a stripped `m.room.member` event which contains the important renderable fields from the event.
163
+ *
164
+ * It is used in MSC4186 (Simplified Sliding Sync) as a replacement for the old `summary` field.
165
+ *
166
+ * When we are doing old-style (`/v3/sync`) sync, we simulate the SSS behaviour by constructing
167
+ * a `Hero` object based on the user id we get from the summary. Obviously, in that case,
168
+ * the `Hero` will lack a `displayName` or `avatarUrl`.
169
+ */
170
+ _defineProperty(this, "heroes", null);
171
+ // flags to stop logspam about missing m.room.create events
172
+ _defineProperty(this, "getTypeWarning", false);
173
+ _defineProperty(this, "membersPromise", void 0);
174
+ // XXX: These should be read-only
175
+ /**
176
+ * The human-readable display name for this room.
177
+ */
178
+ _defineProperty(this, "name", void 0);
179
+ /**
180
+ * The un-homoglyphed name for this room.
181
+ */
182
+ _defineProperty(this, "normalizedName", void 0);
183
+ /**
184
+ * Dict of room tags; the keys are the tag name and the values
185
+ * are any metadata associated with the tag - e.g. `{ "fav" : { order: 1 } }`
186
+ */
187
+ _defineProperty(this, "tags", {});
188
+ // $tagName: { $metadata: $value }
189
+ /**
190
+ * accountData Dict of per-room account_data events; the keys are the
191
+ * event type and the values are the events.
192
+ */
193
+ _defineProperty(this, "accountData", new Map());
194
+ // $eventType: $event
195
+ /**
196
+ * The room summary.
197
+ */
198
+ _defineProperty(this, "summary", null);
199
+ /**
200
+ * oldState The state of the room at the time of the oldest event in the live timeline.
201
+ *
202
+ * @deprecated Present for backwards compatibility.
203
+ * Use getLiveTimeline().getState(EventTimeline.BACKWARDS) instead
204
+ */
205
+ _defineProperty(this, "oldState", void 0);
206
+ /**
207
+ * currentState The state of the room at the time of the newest event in the timeline.
208
+ *
209
+ * @deprecated Present for backwards compatibility.
210
+ * Use getLiveTimeline().getState(EventTimeline.FORWARDS) instead.
211
+ */
212
+ _defineProperty(this, "currentState", void 0);
213
+ _defineProperty(this, "relations", void 0);
214
+ /**
215
+ * A collection of events known by the client
216
+ * This is not a comprehensive list of the threads that exist in this room
217
+ */
218
+ _defineProperty(this, "threads", new Map());
219
+ /**
220
+ * A mapping of eventId to all visibility changes to apply
221
+ * to the event, by chronological order, as per
222
+ * https://github.com/matrix-org/matrix-doc/pull/3531
223
+ *
224
+ * # Invariants
225
+ *
226
+ * - within each list, all events are classed by
227
+ * chronological order;
228
+ * - all events are events such that
229
+ * `asVisibilityEvent()` returns a non-null `IVisibilityChange`;
230
+ * - within each list with key `eventId`, all events
231
+ * are in relation to `eventId`.
232
+ *
233
+ * @experimental
234
+ */
235
+ _defineProperty(this, "visibilityEvents", new Map());
236
+ /**
237
+ * The latest receipts (synthetic and real) for each user in each thread
238
+ * (and unthreaded).
239
+ */
240
+ _defineProperty(this, "roomReceipts", new RoomReceipts(this));
241
+ /**
242
+ * Stores and tracks sticky events
243
+ */
244
+ _defineProperty(this, "stickyEvents", new RoomStickyEventsStore());
245
+ _defineProperty(this, "threadTimelineSetsPromise", null);
246
+ _defineProperty(this, "threadsReady", false);
247
+ _defineProperty(this, "updateThreadRootEvents", (thread, toStartOfTimeline, recreateEvent) => {
248
+ if (thread.length) {
249
+ var _this$threadsTimeline;
250
+ this.updateThreadRootEvent((_this$threadsTimeline = this.threadsTimelineSets) === null || _this$threadsTimeline === void 0 ? void 0 : _this$threadsTimeline[0], thread, toStartOfTimeline, recreateEvent);
251
+ if (thread.hasCurrentUserParticipated) {
252
+ var _this$threadsTimeline2;
253
+ this.updateThreadRootEvent((_this$threadsTimeline2 = this.threadsTimelineSets) === null || _this$threadsTimeline2 === void 0 ? void 0 : _this$threadsTimeline2[1], thread, toStartOfTimeline, recreateEvent);
254
+ }
255
+ }
256
+ });
257
+ _defineProperty(this, "updateThreadRootEvent", (timelineSet, thread, toStartOfTimeline, recreateEvent) => {
258
+ if (timelineSet && thread.rootEvent) {
259
+ if (recreateEvent) {
260
+ timelineSet.removeEvent(thread.id);
261
+ }
262
+ if (Thread.hasServerSideSupport) {
263
+ timelineSet.addLiveEvent(thread.rootEvent, {
264
+ duplicateStrategy: DuplicateStrategy.Replace,
265
+ fromCache: false,
266
+ roomState: this.currentState,
267
+ addToState: false
268
+ });
269
+ } else {
270
+ timelineSet.addEventToTimeline(thread.rootEvent, timelineSet.getLiveTimeline(), {
271
+ toStartOfTimeline,
272
+ addToState: false
273
+ });
274
+ }
275
+ }
276
+ });
277
+ _defineProperty(this, "tryApplyRedaction", event => {
278
+ // FIXME: apply redactions to notification list
279
+
280
+ // NB: We continue to add the redaction event to the timeline at the
281
+ // end of this function so clients can say "so and so redacted an event"
282
+ // if they wish to. Also this may be needed to trigger an update.
283
+
284
+ if (event.isRedaction()) {
285
+ var redactId = event.event.redacts;
286
+
287
+ // if we know about this event, redact its contents now.
288
+ var redactedEvent = redactId ? this.findEventById(redactId) : undefined;
289
+ if (redactId) {
290
+ try {
291
+ this.stickyEvents.handleRedaction(redactedEvent || redactId);
292
+ } catch (ex) {
293
+ // Non-critical failure, but we should warn.
294
+ logger.error("Failed to handle redaction for sticky event", ex);
295
+ }
296
+ }
297
+ if (redactedEvent) {
298
+ this.applyEventAsRedaction(event, redactedEvent);
299
+ }
300
+ } else if (event.getType() === EventType.RoomMember) {
301
+ var membership = event.getContent()["membership"];
302
+ if (membership !== KnownMembership.Ban && !(membership === KnownMembership.Leave && event.getStateKey() !== event.getSender())) {
303
+ // Not a ban or kick, therefore not a membership event we care about here.
304
+ return;
305
+ }
306
+ var redactEvents = event.getContent()["org.matrix.msc4293.redact_events"];
307
+ if (redactEvents !== true) {
308
+ // Invalid or not set - nothing to redact.
309
+ return;
310
+ }
311
+ var state = this.getLiveTimeline().getState(Direction.Forward);
312
+ if (!state.maySendRedactionForEvent(event, event.getSender())) {
313
+ // If the sender can't redact the membership event, then they won't be able to
314
+ // redact any of the target's events either, so skip.
315
+ return;
316
+ }
317
+
318
+ // The redaction is possible, so let's find all the events and apply it.
319
+ var events = this.getTimelineSets().map(s => s.getTimelines()).reduce((p, c) => {
320
+ p.push(...c);
321
+ return p;
322
+ }, []).map(t => t.getEvents().filter(e => e.getSender() === event.getStateKey())).reduce((p, c) => {
323
+ p.push(...c);
324
+ return c;
325
+ }, []);
326
+ for (var toRedact of events) {
327
+ this.applyEventAsRedaction(event, toRedact);
328
+ }
329
+ }
330
+ });
331
+ this.setMaxListeners(100);
332
+ this.reEmitter = new TypedReEmitter(this);
333
+ opts.pendingEventOrdering = opts.pendingEventOrdering || PendingEventOrdering.Chronological;
334
+ this.name = roomId;
335
+ this.normalizedName = roomId;
336
+ this.relations = new RelationsContainer(this.client, this);
337
+
338
+ // Listen to our own receipt event as a more modular way of processing our own
339
+ // receipts. No need to remove the listener: it's on ourself anyway.
340
+ this.on(RoomEvent.Receipt, this.onReceipt);
341
+ this.reEmitter.reEmit(this.stickyEvents, [RoomStickyEventsEvent.Update]);
342
+
343
+ // all our per-room timeline sets. the first one is the unfiltered ones;
344
+ // the subsequent ones are the filtered ones in no particular order.
345
+ this.timelineSets = [new EventTimelineSet(this, opts)];
346
+ this.reEmitter.reEmit(this.getUnfilteredTimelineSet(), [RoomEvent.Timeline, RoomEvent.TimelineReset]);
347
+ this.fixUpLegacyTimelineFields();
348
+ if (this.opts.pendingEventOrdering === PendingEventOrdering.Detached) {
349
+ this.pendingEventList = [];
350
+ this.client.store.getPendingEvents(this.roomId).then(events => {
351
+ var mapper = this.client.getEventMapper({
352
+ decrypt: false
353
+ });
354
+ events.forEach(/*#__PURE__*/function () {
355
+ var _ref = _asyncToGenerator(function* (serializedEvent) {
356
+ var event = mapper(serializedEvent);
357
+ yield client.decryptEventIfNeeded(event);
358
+ event.setStatus(EventStatus.NOT_SENT);
359
+ _this.addPendingEvent(event, event.getTxnId());
360
+ });
361
+ return function (_x) {
362
+ return _ref.apply(this, arguments);
363
+ };
364
+ }());
365
+ });
366
+ }
367
+
368
+ // awaited by getEncryptionTargetMembers while room members are loading
369
+ if (!this.opts.lazyLoadMembers) {
370
+ this.membersPromise = Promise.resolve(false);
371
+ } else {
372
+ this.membersPromise = undefined;
373
+ }
374
+ }
375
+ createThreadsTimelineSets() {
376
+ var _this2 = this;
377
+ return _asyncToGenerator(function* () {
378
+ var _this2$client;
379
+ if (_this2.threadTimelineSetsPromise) {
380
+ return _this2.threadTimelineSetsPromise;
381
+ }
382
+ if ((_this2$client = _this2.client) !== null && _this2$client !== void 0 && _this2$client.supportsThreads()) {
383
+ try {
384
+ _this2.threadTimelineSetsPromise = Promise.all([_this2.createThreadTimelineSet(), _this2.createThreadTimelineSet(ThreadFilterType.My)]);
385
+ var timelineSets = yield _this2.threadTimelineSetsPromise;
386
+ _this2.threadsTimelineSets[0] = timelineSets[0];
387
+ _this2.threadsTimelineSets[1] = timelineSets[1];
388
+ return timelineSets;
389
+ } catch (_unused) {
390
+ _this2.threadTimelineSetsPromise = null;
391
+ return null;
392
+ }
393
+ }
394
+ return null;
395
+ })();
396
+ }
397
+
398
+ /**
399
+ * Bulk decrypt critical events in a room
400
+ *
401
+ * Critical events represents the minimal set of events to decrypt
402
+ * for a typical UI to function properly
403
+ *
404
+ * - Last event of every room (to generate likely message preview)
405
+ * - All events up to the read receipt (to calculate an accurate notification count)
406
+ *
407
+ * @returns Signals when all events have been decrypted
408
+ */
409
+ decryptCriticalEvents() {
410
+ var _this3 = this;
411
+ return _asyncToGenerator(function* () {
412
+ if (!_this3.client.getCrypto()) return;
413
+ var readReceiptEventId = _this3.getEventReadUpTo(_this3.client.getUserId(), true);
414
+ var events = _this3.getLiveTimeline().getEvents();
415
+ var readReceiptTimelineIndex = events.findIndex(matrixEvent => {
416
+ return matrixEvent.event.event_id === readReceiptEventId;
417
+ });
418
+ var decryptionPromises = events.slice(readReceiptTimelineIndex).reverse().map(event => _this3.client.decryptEventIfNeeded(event));
419
+ yield Promise.allSettled(decryptionPromises);
420
+ })();
421
+ }
422
+
423
+ /**
424
+ * Bulk decrypt events in a room
425
+ *
426
+ * @returns Signals when all events have been decrypted
427
+ */
428
+ decryptAllEvents() {
429
+ var _this4 = this;
430
+ return _asyncToGenerator(function* () {
431
+ if (!_this4.client.getCrypto()) return;
432
+ var decryptionPromises = _this4.getUnfilteredTimelineSet().getLiveTimeline().getEvents().slice(0) // copy before reversing
433
+ .reverse().map(event => _this4.client.decryptEventIfNeeded(event));
434
+ yield Promise.allSettled(decryptionPromises);
435
+ })();
436
+ }
437
+
438
+ /**
439
+ * Gets the creator of the room
440
+ * @returns The creator of the room, or null if it could not be determined
441
+ */
442
+ getCreator() {
443
+ var _createEvent$getSende;
444
+ var createEvent = this.currentState.getStateEvents(EventType.RoomCreate, "");
445
+ return (_createEvent$getSende = createEvent === null || createEvent === void 0 ? void 0 : createEvent.getSender()) !== null && _createEvent$getSende !== void 0 ? _createEvent$getSende : null;
446
+ }
447
+
448
+ /**
449
+ * Gets the version of the room
450
+ * @returns The version of the room
451
+ */
452
+ getVersion() {
453
+ return this.currentState.getRoomVersion();
454
+ }
455
+
456
+ /**
457
+ * Determines the recommended room version for the room. This returns an
458
+ * object with 3 properties: `version` as the new version the
459
+ * room should be upgraded to (may be the same as the current version);
460
+ * `needsUpgrade` to indicate if the room actually can be
461
+ * upgraded (ie: does the current version not match?); and `urgent`
462
+ * to indicate if the new version patches a vulnerability in a previous
463
+ * version.
464
+ * @returns
465
+ * Resolves to the version the room should be upgraded to.
466
+ */
467
+ getRecommendedVersion() {
468
+ var _this5 = this;
469
+ return _asyncToGenerator(function* () {
470
+ var capabilities = {};
471
+ try {
472
+ capabilities = yield _this5.client.getCapabilities();
473
+ } catch (_unused2) {}
474
+ var versionCap = capabilities["m.room_versions"];
475
+ if (!versionCap) {
476
+ versionCap = {
477
+ default: KNOWN_SAFE_ROOM_VERSION,
478
+ available: {}
479
+ };
480
+ for (var safeVer of SAFE_ROOM_VERSIONS) {
481
+ versionCap.available[safeVer] = RoomVersionStability.Stable;
482
+ }
483
+ }
484
+ var result = _this5.checkVersionAgainstCapability(versionCap);
485
+ if (result.urgent && result.needsUpgrade) {
486
+ // Something doesn't feel right: we shouldn't need to update
487
+ // because the version we're on should be in the protocol's
488
+ // namespace. This usually means that the server was updated
489
+ // before the client was, making us think the newest possible
490
+ // room version is not stable. As a solution, we'll refresh
491
+ // the capability we're using to determine this.
492
+ logger.warn("Refreshing room version capability because the server looks " + "to be supporting a newer room version we don't know about.");
493
+ try {
494
+ capabilities = yield _this5.client.fetchCapabilities();
495
+ } catch (e) {
496
+ logger.warn("Failed to refresh room version capabilities", e);
497
+ }
498
+ versionCap = capabilities["m.room_versions"];
499
+ if (!versionCap) {
500
+ logger.warn("No room version capability - assuming upgrade required.");
501
+ return result;
502
+ } else {
503
+ result = _this5.checkVersionAgainstCapability(versionCap);
504
+ }
505
+ }
506
+ return result;
507
+ })();
508
+ }
509
+ checkVersionAgainstCapability(versionCap) {
510
+ var currentVersion = this.getVersion();
511
+ logger.log("[".concat(this.roomId, "] Current version: ").concat(currentVersion));
512
+ logger.log("[".concat(this.roomId, "] Version capability: "), versionCap);
513
+ var result = {
514
+ version: currentVersion,
515
+ needsUpgrade: false,
516
+ urgent: false
517
+ };
518
+
519
+ // If the room is on the default version then nothing needs to change
520
+ if (currentVersion === versionCap.default) return result;
521
+ var stableVersions = Object.keys(versionCap.available).filter(v => versionCap.available[v] === "stable");
522
+
523
+ // Check if the room is on an unstable version. We determine urgency based
524
+ // off the version being in the Matrix spec namespace or not (if the version
525
+ // is in the current namespace and unstable, the room is probably vulnerable).
526
+ if (!stableVersions.includes(currentVersion)) {
527
+ result.version = versionCap.default;
528
+ result.needsUpgrade = true;
529
+ result.urgent = !!this.getVersion().match(/^[0-9]+[0-9.]*$/g);
530
+ if (result.urgent) {
531
+ logger.warn("URGENT upgrade required on ".concat(this.roomId));
532
+ } else {
533
+ logger.warn("Non-urgent upgrade required on ".concat(this.roomId));
534
+ }
535
+ return result;
536
+ }
537
+
538
+ // The room is on a stable, but non-default, version by this point.
539
+ // No upgrade needed.
540
+ return result;
541
+ }
542
+
543
+ /**
544
+ * Determines whether the given user is permitted to perform a room upgrade
545
+ * @param userId - The ID of the user to test against
546
+ * @returns True if the given user is permitted to upgrade the room
547
+ */
548
+ userMayUpgradeRoom(userId) {
549
+ return this.currentState.maySendStateEvent(EventType.RoomTombstone, userId);
550
+ }
551
+
552
+ /**
553
+ * Get the list of pending sent events for this room
554
+ *
555
+ * @returns A list of the sent events
556
+ * waiting for remote echo.
557
+ *
558
+ * @throws If `opts.pendingEventOrdering` was not 'detached'
559
+ */
560
+ getPendingEvents() {
561
+ if (!this.pendingEventList) {
562
+ throw new Error("Cannot call getPendingEvents with pendingEventOrdering == " + this.opts.pendingEventOrdering);
563
+ }
564
+ return this.pendingEventList;
565
+ }
566
+
567
+ /**
568
+ * Removes a pending event for this room
569
+ *
570
+ * @returns True if an element was removed.
571
+ */
572
+ removePendingEvent(eventId) {
573
+ if (!this.pendingEventList) {
574
+ throw new Error("Cannot call removePendingEvent with pendingEventOrdering == " + this.opts.pendingEventOrdering);
575
+ }
576
+ var removed = removeElement(this.pendingEventList, function (ev) {
577
+ return ev.getId() == eventId;
578
+ }, false);
579
+ this.savePendingEvents();
580
+ return removed;
581
+ }
582
+
583
+ /**
584
+ * Check whether the pending event list contains a given event by ID.
585
+ * If pending event ordering is not "detached" then this returns false.
586
+ *
587
+ * @param eventId - The event ID to check for.
588
+ */
589
+ hasPendingEvent(eventId) {
590
+ var _this$pendingEventLis, _this$pendingEventLis2;
591
+ return (_this$pendingEventLis = (_this$pendingEventLis2 = this.pendingEventList) === null || _this$pendingEventLis2 === void 0 ? void 0 : _this$pendingEventLis2.some(event => event.getId() === eventId)) !== null && _this$pendingEventLis !== void 0 ? _this$pendingEventLis : false;
592
+ }
593
+
594
+ /**
595
+ * Get a specific event from the pending event list, if configured, null otherwise.
596
+ *
597
+ * @param eventId - The event ID to check for.
598
+ */
599
+ getPendingEvent(eventId) {
600
+ var _this$pendingEventLis3, _this$pendingEventLis4;
601
+ return (_this$pendingEventLis3 = (_this$pendingEventLis4 = this.pendingEventList) === null || _this$pendingEventLis4 === void 0 ? void 0 : _this$pendingEventLis4.find(event => event.getId() === eventId)) !== null && _this$pendingEventLis3 !== void 0 ? _this$pendingEventLis3 : null;
602
+ }
603
+
604
+ /**
605
+ * Get the live unfiltered timeline for this room.
606
+ *
607
+ * @returns live timeline
608
+ */
609
+ getLiveTimeline() {
610
+ return this.getUnfilteredTimelineSet().getLiveTimeline();
611
+ }
612
+
613
+ /**
614
+ * The live event timeline for this room, with the oldest event at index 0.
615
+ *
616
+ * @deprecated Present for backwards compatibility.
617
+ * Use getLiveTimeline().getEvents() instead
618
+ */
619
+ get timeline() {
620
+ return this.getLiveTimeline().getEvents();
621
+ }
622
+
623
+ /**
624
+ * Get the timestamp of the last message in the room
625
+ *
626
+ * @returns the timestamp of the last message in the room
627
+ */
628
+ getLastActiveTimestamp() {
629
+ var timeline = this.getLiveTimeline();
630
+ var events = timeline.getEvents();
631
+ if (events.length) {
632
+ var lastEvent = events[events.length - 1];
633
+ return lastEvent.getTs();
634
+ } else {
635
+ return Number.MIN_SAFE_INTEGER;
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Returns the last live event of this room.
641
+ * "last" means latest timestamp.
642
+ * Instead of using timestamps, it would be better to do the comparison based on the order of the homeserver DAG.
643
+ * Unfortunately, this information is currently not available in the client.
644
+ * See {@link https://github.com/matrix-org/matrix-js-sdk/issues/3325}.
645
+ * "live of this room" means from all live timelines: the room and the threads.
646
+ *
647
+ * @returns BriijEvent if there is a last event; else undefined.
648
+ */
649
+ getLastLiveEvent() {
650
+ var _lastRoomEvent$getTs, _lastThreadEvent$getT;
651
+ var roomEvents = this.getLiveTimeline().getEvents();
652
+ var lastRoomEvent = roomEvents[roomEvents.length - 1];
653
+ var lastThread = this.getLastThread();
654
+ if (!lastThread) return lastRoomEvent;
655
+ var lastThreadEvent = lastThread.events[lastThread.events.length - 1];
656
+ return ((_lastRoomEvent$getTs = lastRoomEvent === null || lastRoomEvent === void 0 ? void 0 : lastRoomEvent.getTs()) !== null && _lastRoomEvent$getTs !== void 0 ? _lastRoomEvent$getTs : 0) > ((_lastThreadEvent$getT = lastThreadEvent === null || lastThreadEvent === void 0 ? void 0 : lastThreadEvent.getTs()) !== null && _lastThreadEvent$getT !== void 0 ? _lastThreadEvent$getT : 0) ? lastRoomEvent : lastThreadEvent;
657
+ }
658
+
659
+ /**
660
+ * Returns the last thread of this room.
661
+ * "last" means latest timestamp of the last thread event.
662
+ * Instead of using timestamps, it would be better to do the comparison based on the order of the homeserver DAG.
663
+ * Unfortunately, this information is currently not available in the client.
664
+ * See {@link https://github.com/matrix-org/matrix-js-sdk/issues/3325}.
665
+ *
666
+ * @returns the thread with the most recent event in its live time line. undefined if there is no thread.
667
+ */
668
+ getLastThread() {
669
+ return this.getThreads().reduce((lastThread, thread) => {
670
+ var _threadEvent$getTs, _lastThreadEvent$getT2;
671
+ if (!lastThread) return thread;
672
+ var threadEvent = thread.events[thread.events.length - 1];
673
+ var lastThreadEvent = lastThread.events[lastThread.events.length - 1];
674
+ if (((_threadEvent$getTs = threadEvent === null || threadEvent === void 0 ? void 0 : threadEvent.getTs()) !== null && _threadEvent$getTs !== void 0 ? _threadEvent$getTs : 0) >= ((_lastThreadEvent$getT2 = lastThreadEvent === null || lastThreadEvent === void 0 ? void 0 : lastThreadEvent.getTs()) !== null && _lastThreadEvent$getT2 !== void 0 ? _lastThreadEvent$getT2 : 0)) {
675
+ // Last message of current thread is newer → new last thread.
676
+ // Equal also means newer, because it was added to the thread map later.
677
+ return thread;
678
+ }
679
+ return lastThread;
680
+ }, undefined);
681
+ }
682
+
683
+ /**
684
+ * @returns the membership type (join | leave | invite | knock) for the logged in user
685
+ */
686
+ getMyMembership() {
687
+ var _this$selfMembership;
688
+ return (_this$selfMembership = this.selfMembership) !== null && _this$selfMembership !== void 0 ? _this$selfMembership : KnownMembership.Leave;
689
+ }
690
+
691
+ /**
692
+ * If this room is a DM we're invited to,
693
+ * try to find out who invited us
694
+ * @returns user id of the inviter
695
+ */
696
+ getDMInviter() {
697
+ var me = this.getMember(this.myUserId);
698
+ if (me) {
699
+ return me.getDMInviter();
700
+ }
701
+ if (this.selfMembership === KnownMembership.Invite) {
702
+ // fall back to summary information
703
+ var memberCount = this.getInvitedAndJoinedMemberCount();
704
+ if (memberCount === 2) {
705
+ var _this$heroes;
706
+ return (_this$heroes = this.heroes) === null || _this$heroes === void 0 || (_this$heroes = _this$heroes[0]) === null || _this$heroes === void 0 ? void 0 : _this$heroes.userId;
707
+ }
708
+ }
709
+ }
710
+
711
+ /**
712
+ * Assuming this room is a DM room, tries to guess with which user.
713
+ * @returns user id of the other member (could be syncing user)
714
+ */
715
+ guessDMUserId() {
716
+ var me = this.getMember(this.myUserId);
717
+ if (me) {
718
+ var inviterId = me.getDMInviter();
719
+ if (inviterId) {
720
+ return inviterId;
721
+ }
722
+ }
723
+ // Remember, we're assuming this room is a DM, so returning the first member we find should be fine
724
+ if (Array.isArray(this.heroes) && this.heroes.length) {
725
+ return this.heroes[0].userId;
726
+ }
727
+ var members = this.currentState.getMembers();
728
+ var anyMember = members.find(m => m.userId !== this.myUserId);
729
+ if (anyMember) {
730
+ return anyMember.userId;
731
+ }
732
+ // it really seems like I'm the only user in the room
733
+ // so I probably created a room with just me in it
734
+ // and marked it as a DM. Ok then
735
+ return this.myUserId;
736
+ }
737
+
738
+ /**
739
+ * Gets the "functional members" in this room.
740
+ *
741
+ * Returns the list of userIDs from the `io.element.functional_members` event. Does not consider the
742
+ * current membership states of those users.
743
+ *
744
+ * @see https://github.com/element-hq/element-meta/blob/develop/spec/functional_members.md.
745
+ */
746
+ getFunctionalMembers() {
747
+ var mFunctionalMembers = this.currentState.getStateEvents(UNSTABLE_ELEMENT_FUNCTIONAL_USERS.name, "");
748
+ if (Array.isArray(mFunctionalMembers === null || mFunctionalMembers === void 0 ? void 0 : mFunctionalMembers.getContent().service_members)) {
749
+ return mFunctionalMembers.getContent().service_members;
750
+ }
751
+ return [];
752
+ }
753
+ getAvatarFallbackMember() {
754
+ var _this$heroes2;
755
+ var functionalMembers = this.getFunctionalMembers();
756
+
757
+ // Only generate a fallback avatar if the conversation is with a single specific other user (a "DM").
758
+ var nonFunctionalMemberCount = 0;
759
+ this.getMembers().forEach(m => {
760
+ if (m.membership !== "join" && m.membership !== "invite") return;
761
+ if (functionalMembers.includes(m.userId)) return;
762
+ nonFunctionalMemberCount++;
763
+ });
764
+ if (nonFunctionalMemberCount > 2) return;
765
+
766
+ // Prefer the list of heroes, if present. It should only include the single other user in the DM.
767
+ var nonFunctionalHeroes = (_this$heroes2 = this.heroes) === null || _this$heroes2 === void 0 ? void 0 : _this$heroes2.filter(h => !functionalMembers.includes(h.userId));
768
+ var hasHeroes = Array.isArray(nonFunctionalHeroes) && nonFunctionalHeroes.length;
769
+ if (hasHeroes) {
770
+ // use first hero that has a display name or avatar url, or whose user ID
771
+ // can be looked up as a member of the room
772
+ for (var hero of nonFunctionalHeroes) {
773
+ // If the hero was from a legacy sync (`/v3/sync`), we will need to look the user ID up in the room
774
+ // the display name and avatar URL will not be set.
775
+ if (!hero.fromMSC4186) {
776
+ // attempt to look up renderable fields from the m.room.member event if it exists
777
+ var member = this.getMember(hero.userId);
778
+ if (member) {
779
+ return member;
780
+ }
781
+ } else {
782
+ // use the Hero supplied values for the room member.
783
+ // TODO: It's unfortunate that this function, which clearly only cares about the
784
+ // avatar url, returns the entire RoomMember event. We need to fake an event
785
+ // to meet this API shape.
786
+ var heroMember = new RoomMember(this.roomId, hero.userId);
787
+ // set the display name and avatar url
788
+ heroMember.setMembershipEvent(new BriijEvent({
789
+ // ensure it's unique even if we hit the same millisecond
790
+ event_id: "$" + this.roomId + hero.userId + new Date().getTime(),
791
+ type: EventType.RoomMember,
792
+ state_key: hero.userId,
793
+ content: {
794
+ displayname: hero.displayName,
795
+ avatar_url: hero.avatarUrl
796
+ }
797
+ }));
798
+ return heroMember;
799
+ }
800
+ }
801
+ var availableMember = nonFunctionalHeroes.map(hero => {
802
+ return this.getMember(hero.userId);
803
+ }).find(member => !!member);
804
+ if (availableMember) {
805
+ return availableMember;
806
+ }
807
+ }
808
+
809
+ // Consider *all*, including previous, members, to generate the avatar for DMs where the other user left.
810
+ // Needed to generate a matching avatar for rooms named "Empty Room (was Alice)".
811
+ var members = this.getMembers();
812
+ var nonFunctionalMembers = members === null || members === void 0 ? void 0 : members.filter(m => !functionalMembers.includes(m.userId));
813
+ if (nonFunctionalMembers.length <= 2) {
814
+ var _availableMember = nonFunctionalMembers.find(m => {
815
+ return m.userId !== this.myUserId;
816
+ });
817
+ if (_availableMember) {
818
+ return _availableMember;
819
+ }
820
+ }
821
+
822
+ // If all else failed, but the homeserver gave us heroes that previously could not be found in the room members,
823
+ // trust and try falling back to a hero, creating a one-off member for it
824
+ if (hasHeroes) {
825
+ var availableUser = nonFunctionalHeroes.map(hero => {
826
+ return this.client.getUser(hero.userId);
827
+ }).find(user => !!user);
828
+ if (availableUser) {
829
+ var _member = new RoomMember(this.roomId, availableUser.userId);
830
+ _member.user = availableUser;
831
+ return _member;
832
+ }
833
+ }
834
+ }
835
+
836
+ /**
837
+ * Sets the membership this room was received as during sync
838
+ * @param membership - join | leave | invite
839
+ */
840
+ updateMyMembership(membership) {
841
+ var prevMembership = this.selfMembership;
842
+ this.selfMembership = membership;
843
+ if (prevMembership !== membership) {
844
+ if (membership === KnownMembership.Leave) {
845
+ this.cleanupAfterLeaving();
846
+ }
847
+ this.emit(RoomEvent.MyMembership, this, membership, prevMembership);
848
+ }
849
+ }
850
+ loadMembersFromServer() {
851
+ var _this6 = this;
852
+ return _asyncToGenerator(function* () {
853
+ var lastSyncToken = _this6.client.store.getSyncToken();
854
+ var response = yield _this6.client.members(_this6.roomId, undefined, KnownMembership.Leave, lastSyncToken !== null && lastSyncToken !== void 0 ? lastSyncToken : undefined);
855
+ return response.chunk;
856
+ })();
857
+ }
858
+ loadMembers() {
859
+ var _this7 = this;
860
+ return _asyncToGenerator(function* () {
861
+ // were the members loaded from the server?
862
+ var fromServer = false;
863
+ var rawMembersEvents = yield _this7.client.store.getOutOfBandMembers(_this7.roomId);
864
+ // If the room is encrypted, we always fetch members from the server at
865
+ // least once, in case the latest state wasn't persisted properly. Note
866
+ // that this function is only called once (unless loading the members
867
+ // fails), since loadMembersIfNeeded always returns this.membersPromise
868
+ // if set, which will be the result of the first (successful) call.
869
+ if (rawMembersEvents === null || _this7.hasEncryptionStateEvent()) {
870
+ fromServer = true;
871
+ rawMembersEvents = yield _this7.loadMembersFromServer();
872
+ logger.log("LL: got ".concat(rawMembersEvents.length, " ") + "members from server for room ".concat(_this7.roomId));
873
+ }
874
+ var memberEvents = rawMembersEvents.filter(noUnsafeEventProps).map(_this7.client.getEventMapper());
875
+ return {
876
+ memberEvents,
877
+ fromServer
878
+ };
879
+ })();
880
+ }
881
+
882
+ /**
883
+ * Check if loading of out-of-band-members has completed
884
+ *
885
+ * @returns true if the full membership list of this room has been loaded (including if lazy-loading is disabled).
886
+ * False if the load is not started or is in progress.
887
+ */
888
+ membersLoaded() {
889
+ if (!this.opts.lazyLoadMembers) {
890
+ return true;
891
+ }
892
+ return this.currentState.outOfBandMembersReady();
893
+ }
894
+
895
+ /**
896
+ * Preloads the member list in case lazy loading
897
+ * of memberships is in use. Can be called multiple times,
898
+ * it will only preload once.
899
+ * @returns when preloading is done and
900
+ * accessing the members on the room will take
901
+ * all members in the room into account
902
+ */
903
+ loadMembersIfNeeded() {
904
+ if (this.membersPromise) {
905
+ return this.membersPromise;
906
+ }
907
+
908
+ // mark the state so that incoming messages while
909
+ // the request is in flight get marked as superseding
910
+ // the OOB members
911
+ this.currentState.markOutOfBandMembersStarted();
912
+ var inMemoryUpdate = this.loadMembers().then(result => {
913
+ this.currentState.setOutOfBandMembers(result.memberEvents);
914
+ // recalculate the room name: it may have been based on members, so may have changed
915
+ this.recalculate();
916
+ return result.fromServer;
917
+ }).catch(err => {
918
+ // allow retries on fail
919
+ this.membersPromise = undefined;
920
+ this.currentState.markOutOfBandMembersFailed();
921
+ throw err;
922
+ });
923
+ // update members in storage, but don't wait for it
924
+ inMemoryUpdate.then(fromServer => {
925
+ if (fromServer) {
926
+ var oobMembers = this.currentState.getMembers().filter(m => m.isOutOfBand()).map(m => {
927
+ var _m$events$member;
928
+ return (_m$events$member = m.events.member) === null || _m$events$member === void 0 ? void 0 : _m$events$member.event;
929
+ });
930
+ logger.log("LL: telling store to write ".concat(oobMembers.length) + " members for room ".concat(this.roomId));
931
+ var store = this.client.store;
932
+ return store.setOutOfBandMembers(this.roomId, oobMembers)
933
+ // swallow any IDB error as we don't want to fail
934
+ // because of this
935
+ .catch(err => {
936
+ logger.log("LL: storing OOB room members failed, oh well", err);
937
+ });
938
+ }
939
+ }).catch(err => {
940
+ // as this is not awaited anywhere,
941
+ // at least show the error in the console
942
+ logger.error(err);
943
+ });
944
+ this.membersPromise = inMemoryUpdate;
945
+ return this.membersPromise;
946
+ }
947
+
948
+ /**
949
+ * Removes the lazily loaded members from storage if needed
950
+ */
951
+ clearLoadedMembersIfNeeded() {
952
+ var _this8 = this;
953
+ return _asyncToGenerator(function* () {
954
+ if (_this8.opts.lazyLoadMembers && _this8.membersPromise) {
955
+ yield _this8.loadMembersIfNeeded();
956
+ yield _this8.client.store.clearOutOfBandMembers(_this8.roomId);
957
+ _this8.currentState.clearOutOfBandMembers();
958
+ _this8.membersPromise = undefined;
959
+ }
960
+ })();
961
+ }
962
+
963
+ /**
964
+ * called when sync receives this room in the leave section
965
+ * to do cleanup after leaving a room. Possibly called multiple times.
966
+ */
967
+ cleanupAfterLeaving() {
968
+ this.clearLoadedMembersIfNeeded().catch(err => {
969
+ logger.error("error after clearing loaded members from " + "room ".concat(this.roomId, " after leaving"));
970
+ logger.log(err);
971
+ });
972
+ }
973
+
974
+ /**
975
+ * Empty out the current live timeline and re-request it. This is used when
976
+ * historical messages are imported into the room via MSC2716 `/batch_send`
977
+ * because the client may already have that section of the timeline loaded.
978
+ * We need to force the client to throw away their current timeline so that
979
+ * when they back paginate over the area again with the historical messages
980
+ * in between, it grabs the newly imported messages. We can listen for
981
+ * `UNSTABLE_MSC2716_MARKER`, in order to tell when historical messages are ready
982
+ * to be discovered in the room and the timeline needs a refresh. The SDK
983
+ * emits a `RoomEvent.HistoryImportedWithinTimeline` event when we detect a
984
+ * valid marker and can check the needs refresh status via
985
+ * `room.getTimelineNeedsRefresh()`.
986
+ */
987
+ refreshLiveTimeline() {
988
+ var _this9 = this;
989
+ return _asyncToGenerator(function* () {
990
+ var liveTimelineBefore = _this9.getLiveTimeline();
991
+ var forwardPaginationToken = liveTimelineBefore.getPaginationToken(EventTimeline.FORWARDS);
992
+ var backwardPaginationToken = liveTimelineBefore.getPaginationToken(EventTimeline.BACKWARDS);
993
+ var eventsBefore = liveTimelineBefore.getEvents();
994
+ var mostRecentEventInTimeline = eventsBefore[eventsBefore.length - 1];
995
+ logger.log("[refreshLiveTimeline for ".concat(_this9.roomId, "] at ") + "mostRecentEventInTimeline=".concat(mostRecentEventInTimeline && mostRecentEventInTimeline.getId(), " ") + "liveTimelineBefore=".concat(liveTimelineBefore.toString(), " ") + "forwardPaginationToken=".concat(forwardPaginationToken, " ") + "backwardPaginationToken=".concat(backwardPaginationToken));
996
+
997
+ // Get the main TimelineSet
998
+ var timelineSet = _this9.getUnfilteredTimelineSet();
999
+ var newTimeline = null;
1000
+ // If there isn't any event in the timeline, let's go fetch the latest
1001
+ // event and construct a timeline from it.
1002
+ //
1003
+ // This should only really happen if the user ran into an error
1004
+ // with refreshing the timeline before which left them in a blank
1005
+ // timeline from `resetLiveTimeline`.
1006
+ if (!mostRecentEventInTimeline) {
1007
+ newTimeline = yield _this9.client.getLatestTimeline(timelineSet);
1008
+ } else {
1009
+ // Empty out all of `this.timelineSets`. But we also need to keep the
1010
+ // same `timelineSet` references around so the React code updates
1011
+ // properly and doesn't ignore the room events we emit because it checks
1012
+ // that the `timelineSet` references are the same. We need the
1013
+ // `timelineSet` empty so that the `client.getEventTimeline(...)` call
1014
+ // later, will call `/context` and create a new timeline instead of
1015
+ // returning the same one.
1016
+ _this9.resetLiveTimeline(null, null);
1017
+
1018
+ // Make the UI timeline show the new blank live timeline we just
1019
+ // reset so that if the network fails below it's showing the
1020
+ // accurate state of what we're working with instead of the
1021
+ // disconnected one in the TimelineWindow which is just hanging
1022
+ // around by reference.
1023
+ _this9.emit(RoomEvent.TimelineRefresh, _this9, timelineSet);
1024
+
1025
+ // Use `client.getEventTimeline(...)` to construct a new timeline from a
1026
+ // `/context` response state and events for the most recent event before
1027
+ // we reset everything. The `timelineSet` we pass in needs to be empty
1028
+ // in order for this function to call `/context` and generate a new
1029
+ // timeline.
1030
+ newTimeline = yield _this9.client.getEventTimeline(timelineSet, mostRecentEventInTimeline.getId());
1031
+ }
1032
+
1033
+ // If a racing `/sync` beat us to creating a new timeline, use that
1034
+ // instead because it's the latest in the room and any new messages in
1035
+ // the scrollback will include the history.
1036
+ var liveTimeline = timelineSet.getLiveTimeline();
1037
+ if (!liveTimeline || liveTimeline.getPaginationToken(Direction.Forward) === null && liveTimeline.getPaginationToken(Direction.Backward) === null && liveTimeline.getEvents().length === 0) {
1038
+ logger.log("[refreshLiveTimeline for ".concat(_this9.roomId, "] using our new live timeline"));
1039
+ // Set the pagination token back to the live sync token (`null`) instead
1040
+ // of using the `/context` historical token (ex. `t12-13_0_0_0_0_0_0_0_0`)
1041
+ // so that it matches the next response from `/sync` and we can properly
1042
+ // continue the timeline.
1043
+ newTimeline.setPaginationToken(forwardPaginationToken, EventTimeline.FORWARDS);
1044
+
1045
+ // Set our new fresh timeline as the live timeline to continue syncing
1046
+ // forwards and back paginating from.
1047
+ timelineSet.setLiveTimeline(newTimeline);
1048
+ // Fixup `this.oldstate` so that `scrollback` has the pagination tokens
1049
+ // available
1050
+ _this9.fixUpLegacyTimelineFields();
1051
+ } else {
1052
+ logger.log("[refreshLiveTimeline for ".concat(_this9.roomId, "] `/sync` or some other request beat us to creating a new ") + "live timeline after we reset it. We'll use that instead since any events in the scrollback from " + "this timeline will include the history.");
1053
+ }
1054
+
1055
+ // The timeline has now been refreshed ✅
1056
+ _this9.setTimelineNeedsRefresh(false);
1057
+
1058
+ // Emit an event which clients can react to and re-load the timeline
1059
+ // from the SDK
1060
+ _this9.emit(RoomEvent.TimelineRefresh, _this9, timelineSet);
1061
+ })();
1062
+ }
1063
+
1064
+ /**
1065
+ * Reset the live timeline of all timelineSets, and start new ones.
1066
+ *
1067
+ * <p>This is used when /sync returns a 'limited' timeline.
1068
+ *
1069
+ * @param backPaginationToken - token for back-paginating the new timeline
1070
+ * @param forwardPaginationToken - token for forward-paginating the old live timeline,
1071
+ * if absent or null, all timelines are reset, removing old ones (including the previous live
1072
+ * timeline which would otherwise be unable to paginate forwards without this token).
1073
+ * Removing just the old live timeline whilst preserving previous ones is not supported.
1074
+ */
1075
+ resetLiveTimeline(backPaginationToken, forwardPaginationToken) {
1076
+ for (var timelineSet of this.timelineSets) {
1077
+ timelineSet.resetLiveTimeline(backPaginationToken !== null && backPaginationToken !== void 0 ? backPaginationToken : undefined, forwardPaginationToken !== null && forwardPaginationToken !== void 0 ? forwardPaginationToken : undefined);
1078
+ }
1079
+ for (var thread of this.threads.values()) {
1080
+ thread.resetLiveTimeline(backPaginationToken, forwardPaginationToken);
1081
+ }
1082
+ this.fixUpLegacyTimelineFields();
1083
+ }
1084
+
1085
+ /**
1086
+ * Fix up this.timeline, this.oldState and this.currentState
1087
+ *
1088
+ * @internal
1089
+ */
1090
+ fixUpLegacyTimelineFields() {
1091
+ var previousOldState = this.oldState;
1092
+ var previousCurrentState = this.currentState;
1093
+
1094
+ // maintain this.oldState and this.currentState as references to the
1095
+ // state at the start and end of that timeline. These are more
1096
+ // for backwards-compatibility than anything else.
1097
+ this.oldState = this.getLiveTimeline().getState(EventTimeline.BACKWARDS);
1098
+ this.currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS);
1099
+
1100
+ // Let people know to register new listeners for the new state
1101
+ // references. The reference won't necessarily change every time so only
1102
+ // emit when we see a change.
1103
+ if (previousOldState !== this.oldState) {
1104
+ this.emit(RoomEvent.OldStateUpdated, this, previousOldState, this.oldState);
1105
+ }
1106
+ if (previousCurrentState !== this.currentState) {
1107
+ this.emit(RoomEvent.CurrentStateUpdated, this, previousCurrentState, this.currentState);
1108
+
1109
+ // Re-emit various events on the current room state
1110
+ // TODO: If currentState really only exists for backwards
1111
+ // compatibility, shouldn't we be doing this some other way?
1112
+ this.reEmitter.stopReEmitting(previousCurrentState, [RoomStateEvent.Events, RoomStateEvent.Members, RoomStateEvent.NewMember, RoomStateEvent.Update, RoomStateEvent.Marker, BeaconEvent.New, BeaconEvent.Update, BeaconEvent.Destroy, BeaconEvent.LivenessChange]);
1113
+ this.reEmitter.reEmit(this.currentState, [RoomStateEvent.Events, RoomStateEvent.Members, RoomStateEvent.NewMember, RoomStateEvent.Update, RoomStateEvent.Marker, BeaconEvent.New, BeaconEvent.Update, BeaconEvent.Destroy, BeaconEvent.LivenessChange]);
1114
+ }
1115
+ }
1116
+ onReceipt(event) {
1117
+ if (this.hasEncryptionStateEvent()) {
1118
+ this.clearNotificationsOnReceipt(event);
1119
+ }
1120
+ }
1121
+ clearNotificationsOnReceipt(event) {
1122
+ // Like above, we have to listen for read receipts from ourselves in order to
1123
+ // correctly handle notification counts on encrypted rooms.
1124
+ // This fixes https://github.com/vector-im/element-web/issues/9421
1125
+
1126
+ // Figure out if we've read something or if it's just informational
1127
+ // We need to work out what threads we've just recieved receipts for, so we
1128
+ // know which ones to update. If we've received an unthreaded receipt, we'll
1129
+ // need to update all threads.
1130
+ var threadIds = [];
1131
+ var hasUnthreadedReceipt = false;
1132
+ var content = event.getContent();
1133
+ for (var receiptGroup of Object.values(content)) {
1134
+ for (var [receiptType, userReceipt] of Object.entries(receiptGroup)) {
1135
+ if (!utils.isSupportedReceiptType(receiptType)) continue;
1136
+ if (!userReceipt) continue;
1137
+ for (var [userId, singleReceipt] of Object.entries(userReceipt)) {
1138
+ if (!singleReceipt || typeof singleReceipt !== "object") continue;
1139
+ var typedSingleReceipt = singleReceipt;
1140
+ if (userId !== this.client.getUserId()) continue;
1141
+ if (typedSingleReceipt.thread_id === undefined) {
1142
+ hasUnthreadedReceipt = true;
1143
+ } else if (typeof typedSingleReceipt.thread_id === "string") {
1144
+ threadIds.push(typedSingleReceipt.thread_id);
1145
+ }
1146
+ }
1147
+ }
1148
+ }
1149
+ if (hasUnthreadedReceipt) {
1150
+ // If we have an unthreaded receipt, we need to update any threads that have a notification
1151
+ // in them (because we know the receipt can't go backwards so we don't need to check any with
1152
+ // no notifications: the number can only decrease from a receipt).
1153
+ threadIds = this.getThreads().filter(thread => this.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Total) > 0 || this.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Highlight) > 0).map(thread => thread.id);
1154
+ threadIds.push("main");
1155
+ }
1156
+ for (var threadId of threadIds) {
1157
+ var _this$getThread;
1158
+ // Work backwards to determine how many events are unread. We also set
1159
+ // a limit for how back we'll look to avoid spinning CPU for too long.
1160
+ // If we hit the limit, we assume the count is unchanged.
1161
+ var maxHistory = 20;
1162
+ var timeline = threadId === "main" ? this.getLiveTimeline() : (_this$getThread = this.getThread(threadId)) === null || _this$getThread === void 0 ? void 0 : _this$getThread.liveTimeline;
1163
+ if (!timeline) {
1164
+ logger.warn("Couldn't find timeline for thread ID ".concat(threadId, " in room ").concat(this.roomId));
1165
+ continue;
1166
+ }
1167
+ var events = timeline.getEvents();
1168
+ var highlightCount = 0;
1169
+ for (var i = events.length - 1; i >= 0; i--) {
1170
+ var _pushActions$tweaks;
1171
+ if (i === events.length - maxHistory) return; // limit reached
1172
+
1173
+ var _event = events[i];
1174
+ if (this.hasUserReadEvent(this.client.getUserId(), _event.getId())) {
1175
+ // If the user has read the event, then the counting is done.
1176
+ break;
1177
+ }
1178
+ var pushActions = this.client.getPushActionsForEvent(_event);
1179
+ highlightCount += pushActions !== null && pushActions !== void 0 && (_pushActions$tweaks = pushActions.tweaks) !== null && _pushActions$tweaks !== void 0 && _pushActions$tweaks.highlight ? 1 : 0;
1180
+ }
1181
+
1182
+ // Note: we don't need to handle 'total' notifications because the counts
1183
+ // will come from the server.
1184
+ if (threadId === "main") {
1185
+ this.setUnreadNotificationCount(NotificationCountType.Highlight, highlightCount);
1186
+ } else {
1187
+ this.setThreadUnreadNotificationCount(threadId, NotificationCountType.Highlight, highlightCount);
1188
+ }
1189
+ }
1190
+ }
1191
+
1192
+ /**
1193
+ * Return the timeline sets for this room.
1194
+ * @returns array of timeline sets for this room
1195
+ */
1196
+ getTimelineSets() {
1197
+ return this.timelineSets;
1198
+ }
1199
+
1200
+ /**
1201
+ * Helper to return the main unfiltered timeline set for this room
1202
+ * @returns room's unfiltered timeline set
1203
+ */
1204
+ getUnfilteredTimelineSet() {
1205
+ return this.timelineSets[0];
1206
+ }
1207
+
1208
+ /**
1209
+ * Get the timeline which contains the given event from the unfiltered set, if any
1210
+ *
1211
+ * @param eventId - event ID to look for
1212
+ * @returns timeline containing
1213
+ * the given event, or null if unknown
1214
+ */
1215
+ getTimelineForEvent(eventId) {
1216
+ var event = this.findEventById(eventId);
1217
+ var thread = this.findThreadForEvent(event);
1218
+ if (thread) {
1219
+ return thread.timelineSet.getTimelineForEvent(eventId);
1220
+ } else {
1221
+ return this.getUnfilteredTimelineSet().getTimelineForEvent(eventId);
1222
+ }
1223
+ }
1224
+
1225
+ /**
1226
+ * Add a new timeline to this room's unfiltered timeline set
1227
+ *
1228
+ * @returns newly-created timeline
1229
+ */
1230
+ addTimeline() {
1231
+ return this.getUnfilteredTimelineSet().addTimeline();
1232
+ }
1233
+
1234
+ /**
1235
+ * Whether the timeline needs to be refreshed in order to pull in new
1236
+ * historical messages that were imported.
1237
+ * @param value - The value to set
1238
+ */
1239
+ setTimelineNeedsRefresh(value) {
1240
+ this.timelineNeedsRefresh = value;
1241
+ }
1242
+
1243
+ /**
1244
+ * Whether the timeline needs to be refreshed in order to pull in new
1245
+ * historical messages that were imported.
1246
+ * @returns .
1247
+ */
1248
+ getTimelineNeedsRefresh() {
1249
+ return this.timelineNeedsRefresh;
1250
+ }
1251
+
1252
+ /**
1253
+ * Get an event which is stored in our unfiltered timeline set, or in a thread
1254
+ *
1255
+ * @param eventId - event ID to look for
1256
+ * @returns the given event, or undefined if unknown
1257
+ */
1258
+ findEventById(eventId) {
1259
+ var event = this.getUnfilteredTimelineSet().findEventById(eventId);
1260
+ if (!event) {
1261
+ var threads = this.getThreads();
1262
+ for (var i = 0; i < threads.length; i++) {
1263
+ var thread = threads[i];
1264
+ event = thread.findEventById(eventId);
1265
+ if (event) {
1266
+ return event;
1267
+ }
1268
+ }
1269
+ }
1270
+ return event;
1271
+ }
1272
+
1273
+ /**
1274
+ * Get one of the notification counts for this room
1275
+ * @param type - The type of notification count to get. default: 'total'
1276
+ * @returns The notification count, or undefined if there is no count
1277
+ * for this type.
1278
+ */
1279
+ getUnreadNotificationCount() {
1280
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NotificationCountType.Total;
1281
+ var count = this.getRoomUnreadNotificationCount(type);
1282
+ for (var threadNotification of this.threadNotifications.values()) {
1283
+ var _threadNotification$t;
1284
+ count += (_threadNotification$t = threadNotification[type]) !== null && _threadNotification$t !== void 0 ? _threadNotification$t : 0;
1285
+ }
1286
+ return count;
1287
+ }
1288
+
1289
+ /**
1290
+ * Get the notification for the event context (room or thread timeline)
1291
+ */
1292
+ getUnreadCountForEventContext() {
1293
+ var _ref2;
1294
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NotificationCountType.Total;
1295
+ var event = arguments.length > 1 ? arguments[1] : undefined;
1296
+ var isThreadEvent = !!event.threadRootId && !event.isThreadRoot;
1297
+ return (_ref2 = isThreadEvent ? this.getThreadUnreadNotificationCount(event.threadRootId, type) : this.getRoomUnreadNotificationCount(type)) !== null && _ref2 !== void 0 ? _ref2 : 0;
1298
+ }
1299
+
1300
+ /**
1301
+ * Get one of the notification counts for this room
1302
+ * @param type - The type of notification count to get. default: 'total'
1303
+ * @returns The notification count, or undefined if there is no count
1304
+ * for this type.
1305
+ */
1306
+ getRoomUnreadNotificationCount() {
1307
+ var _this$notificationCou;
1308
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NotificationCountType.Total;
1309
+ return (_this$notificationCou = this.notificationCounts[type]) !== null && _this$notificationCou !== void 0 ? _this$notificationCou : 0;
1310
+ }
1311
+
1312
+ /**
1313
+ * Get one of the notification counts for a thread
1314
+ * @param threadId - the root event ID
1315
+ * @param type - The type of notification count to get. default: 'total'
1316
+ * @returns The notification count, or undefined if there is no count
1317
+ * for this type.
1318
+ */
1319
+ getThreadUnreadNotificationCount(threadId) {
1320
+ var _this$threadNotificat, _this$threadNotificat2;
1321
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NotificationCountType.Total;
1322
+ return (_this$threadNotificat = (_this$threadNotificat2 = this.threadNotifications.get(threadId)) === null || _this$threadNotificat2 === void 0 ? void 0 : _this$threadNotificat2[type]) !== null && _this$threadNotificat !== void 0 ? _this$threadNotificat : 0;
1323
+ }
1324
+
1325
+ /**
1326
+ * Checks if the current room has unread thread notifications
1327
+ * @returns
1328
+ */
1329
+ hasThreadUnreadNotification() {
1330
+ for (var notification of this.threadNotifications.values()) {
1331
+ var _notification$highlig, _notification$total;
1332
+ if (((_notification$highlig = notification.highlight) !== null && _notification$highlig !== void 0 ? _notification$highlig : 0) > 0 || ((_notification$total = notification.total) !== null && _notification$total !== void 0 ? _notification$total : 0) > 0) {
1333
+ return true;
1334
+ }
1335
+ }
1336
+ return false;
1337
+ }
1338
+
1339
+ /**
1340
+ * Swet one of the notification count for a thread
1341
+ * @param threadId - the root event ID
1342
+ * @param type - The type of notification count to get. default: 'total'
1343
+ * @returns
1344
+ */
1345
+ setThreadUnreadNotificationCount(threadId, type, count) {
1346
+ var _this$threadNotificat3, _this$threadNotificat4;
1347
+ var notification = _objectSpread({
1348
+ highlight: (_this$threadNotificat3 = this.threadNotifications.get(threadId)) === null || _this$threadNotificat3 === void 0 ? void 0 : _this$threadNotificat3.highlight,
1349
+ total: (_this$threadNotificat4 = this.threadNotifications.get(threadId)) === null || _this$threadNotificat4 === void 0 ? void 0 : _this$threadNotificat4.total
1350
+ }, {
1351
+ [type]: count
1352
+ });
1353
+ this.threadNotifications.set(threadId, notification);
1354
+ this.emit(RoomEvent.UnreadNotifications, notification, threadId);
1355
+ }
1356
+
1357
+ /**
1358
+ * @returns the notification count type for all the threads in the room
1359
+ */
1360
+ get threadsAggregateNotificationType() {
1361
+ var type = null;
1362
+ for (var threadNotification of this.threadNotifications.values()) {
1363
+ var _threadNotification$h, _threadNotification$t2;
1364
+ if (((_threadNotification$h = threadNotification.highlight) !== null && _threadNotification$h !== void 0 ? _threadNotification$h : 0) > 0) {
1365
+ return NotificationCountType.Highlight;
1366
+ } else if (((_threadNotification$t2 = threadNotification.total) !== null && _threadNotification$t2 !== void 0 ? _threadNotification$t2 : 0) > 0 && !type) {
1367
+ type = NotificationCountType.Total;
1368
+ }
1369
+ }
1370
+ return type;
1371
+ }
1372
+
1373
+ /**
1374
+ * Resets the total thread notifications for all threads in this room to zero,
1375
+ * excluding any threads whose IDs are given in `exceptThreadIds`.
1376
+ *
1377
+ * If the room is not encrypted, also resets the highlight notification count to zero
1378
+ * for the same set of threads.
1379
+ *
1380
+ * This is intended for use from the sync code since we calculate highlight notification
1381
+ * counts locally from decrypted messages. We want to partially trust the total from the
1382
+ * server such that we clear notifications when read receipts arrive. The weird name is
1383
+ * intended to reflect this. You probably do not want to use this.
1384
+ *
1385
+ * @param exceptThreadIds - The thread IDs to exclude from the reset.
1386
+ */
1387
+ resetThreadUnreadNotificationCountFromSync() {
1388
+ var exceptThreadIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1389
+ var isEncrypted = this.hasEncryptionStateEvent();
1390
+ for (var [threadId, notifs] of this.threadNotifications) {
1391
+ if (!exceptThreadIds.includes(threadId)) {
1392
+ notifs.total = 0;
1393
+ if (!isEncrypted) {
1394
+ notifs.highlight = 0;
1395
+ }
1396
+ }
1397
+ }
1398
+ this.emit(RoomEvent.UnreadNotifications);
1399
+ }
1400
+
1401
+ /**
1402
+ * Set the bump stamp for this room. This can be used for sorting rooms when the timeline
1403
+ * entries are unknown. Used in MSC4186: Simplified Sliding Sync.
1404
+ * @param bumpStamp The bump_stamp value from the server
1405
+ */
1406
+ setBumpStamp(bumpStamp) {
1407
+ this.bumpStamp = bumpStamp;
1408
+ }
1409
+
1410
+ /**
1411
+ * Get the bump stamp for this room. This can be used for sorting rooms when the timeline
1412
+ * entries are unknown. Used in MSC4186: Simplified Sliding Sync.
1413
+ * @returns The bump stamp for the room, if it exists.
1414
+ */
1415
+ getBumpStamp() {
1416
+ return this.bumpStamp;
1417
+ }
1418
+
1419
+ /**
1420
+ * Set one of the notification counts for this room
1421
+ * @param type - The type of notification count to set.
1422
+ * @param count - The new count
1423
+ */
1424
+ setUnreadNotificationCount(type, count) {
1425
+ this.notificationCounts[type] = count;
1426
+ this.emit(RoomEvent.UnreadNotifications, this.notificationCounts);
1427
+ }
1428
+ setUnread(type, count) {
1429
+ return this.setUnreadNotificationCount(type, count);
1430
+ }
1431
+
1432
+ /**
1433
+ * Takes a legacy room summary (/v3/sync as opposed to MSC4186) and updates the room with it.
1434
+ *
1435
+ * @param summary - The room summary to update the room with
1436
+ */
1437
+ setSummary(summary) {
1438
+ var _summary$mHeroes;
1439
+ var heroes = (_summary$mHeroes = summary["m.heroes"]) === null || _summary$mHeroes === void 0 ? void 0 : _summary$mHeroes.map(h => ({
1440
+ userId: h,
1441
+ fromMSC4186: false
1442
+ }));
1443
+ var joinedCount = summary["m.joined_member_count"];
1444
+ var invitedCount = summary["m.invited_member_count"];
1445
+ if (Number.isInteger(joinedCount)) {
1446
+ this.currentState.setJoinedMemberCount(joinedCount);
1447
+ }
1448
+ if (Number.isInteger(invitedCount)) {
1449
+ this.currentState.setInvitedMemberCount(invitedCount);
1450
+ }
1451
+ if (Array.isArray(heroes)) {
1452
+ // filter out ourselves just in case
1453
+ this.heroes = heroes.filter(h => {
1454
+ return h.userId != this.myUserId;
1455
+ });
1456
+ }
1457
+ this.emit(RoomEvent.Summary, summary);
1458
+ }
1459
+
1460
+ /**
1461
+ * Takes information from the MSC4186 room summary and updates the room with it.
1462
+ *
1463
+ * @param heroes - The room's hero members
1464
+ * @param joinedCount - The number of joined members
1465
+ * @param invitedCount - The number of invited members
1466
+ */
1467
+ setMSC4186SummaryData(heroes, joinedCount, invitedCount) {
1468
+ if (heroes) {
1469
+ this.heroes = heroes.filter(h => h.user_id !== this.myUserId).map(h => ({
1470
+ userId: h.user_id,
1471
+ displayName: h.displayname,
1472
+ avatarUrl: h.avatar_url,
1473
+ fromMSC4186: true
1474
+ }));
1475
+ }
1476
+ if (joinedCount !== undefined && Number.isInteger(joinedCount)) {
1477
+ this.currentState.setJoinedMemberCount(joinedCount);
1478
+ }
1479
+ if (invitedCount !== undefined && Number.isInteger(invitedCount)) {
1480
+ this.currentState.setInvitedMemberCount(invitedCount);
1481
+ }
1482
+
1483
+ // Construct a summary object to emit as the event wants the info in a single object
1484
+ // more like old-style (/v3/sync) summaries.
1485
+ this.emit(RoomEvent.Summary, {
1486
+ "m.heroes": this.heroes ? this.heroes.map(h => h.userId) : [],
1487
+ "m.joined_member_count": joinedCount,
1488
+ "m.invited_member_count": invitedCount
1489
+ });
1490
+ }
1491
+
1492
+ /**
1493
+ * Whether to send encrypted messages to devices within this room.
1494
+ * @param value - true to blacklist unverified devices, null
1495
+ * to use the global value for this room.
1496
+ */
1497
+ setBlacklistUnverifiedDevices(value) {
1498
+ this.blacklistUnverifiedDevices = value;
1499
+ }
1500
+
1501
+ /**
1502
+ * Whether to send encrypted messages to devices within this room.
1503
+ * @returns true if blacklisting unverified devices, null
1504
+ * if the global value should be used for this room.
1505
+ */
1506
+ getBlacklistUnverifiedDevices() {
1507
+ if (this.blacklistUnverifiedDevices === undefined) return null;
1508
+ return this.blacklistUnverifiedDevices;
1509
+ }
1510
+
1511
+ /**
1512
+ * Get the avatar URL for a room if one was set.
1513
+ * @param baseUrl - The homeserver base URL. See
1514
+ * {@link BriijClient#getHomeserverUrl}.
1515
+ * @param width - The desired width of the thumbnail.
1516
+ * @param height - The desired height of the thumbnail.
1517
+ * @param resizeMethod - The thumbnail resize method to use, either
1518
+ * "crop" or "scale".
1519
+ * @param allowDefault - True to allow an identicon for this room if an
1520
+ * avatar URL wasn't explicitly set. Default: true. (Deprecated)
1521
+ * @param useAuthentication - (optional) If true, the caller supports authenticated
1522
+ * media and wants an authentication-required URL. Note that server support for
1523
+ * authenticated media will not be checked - it is the caller's responsibility
1524
+ * to do so before calling this function. Note also that useAuthentication
1525
+ * implies allowRedirects. Defaults to false (unauthenticated endpoints).
1526
+ * @returns the avatar URL or null.
1527
+ */
1528
+ getAvatarUrl(baseUrl, width, height, resizeMethod) {
1529
+ var allowDefault = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1530
+ var useAuthentication = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
1531
+ var mainUrl = this.getMxcAvatarUrl();
1532
+ if (!mainUrl && !allowDefault) {
1533
+ return null;
1534
+ }
1535
+ if (mainUrl) {
1536
+ return getHttpUriForMxc(baseUrl, mainUrl, width, height, resizeMethod, undefined, undefined, useAuthentication);
1537
+ }
1538
+ return null;
1539
+ }
1540
+
1541
+ /**
1542
+ * Get the mxc avatar url for the room, if one was set.
1543
+ * @returns the mxc avatar url or falsy
1544
+ */
1545
+ getMxcAvatarUrl() {
1546
+ var _this$currentState$ge;
1547
+ var url = (_this$currentState$ge = this.currentState.getStateEvents(EventType.RoomAvatar, "")) === null || _this$currentState$ge === void 0 ? void 0 : _this$currentState$ge.getContent().url;
1548
+ return url && typeof url === "string" ? url : null;
1549
+ }
1550
+
1551
+ /**
1552
+ * Get this room's canonical alias
1553
+ * The alias returned by this function may not necessarily
1554
+ * still point to this room.
1555
+ * @returns The room's canonical alias, or null if there is none
1556
+ */
1557
+ getCanonicalAlias() {
1558
+ var _this$currentState$ge2;
1559
+ var canonicalAlias = (_this$currentState$ge2 = this.currentState.getStateEvents(EventType.RoomCanonicalAlias, "")) === null || _this$currentState$ge2 === void 0 ? void 0 : _this$currentState$ge2.getContent().alias;
1560
+ return canonicalAlias && typeof canonicalAlias === "string" ? canonicalAlias : null;
1561
+ }
1562
+
1563
+ /**
1564
+ * Get this room's alternative aliases
1565
+ * @returns The room's alternative aliases, or an empty array
1566
+ */
1567
+ getAltAliases() {
1568
+ var _this$currentState$ge3;
1569
+ var altAliases = (_this$currentState$ge3 = this.currentState.getStateEvents(EventType.RoomCanonicalAlias, "")) === null || _this$currentState$ge3 === void 0 ? void 0 : _this$currentState$ge3.getContent().alt_aliases;
1570
+ if (Array.isArray(altAliases)) {
1571
+ return altAliases.filter(alias => typeof alias === "string");
1572
+ }
1573
+ return [];
1574
+ }
1575
+
1576
+ /**
1577
+ * Add events to a timeline
1578
+ *
1579
+ * <p>Will fire "Room.timeline" for each event added.
1580
+ *
1581
+ * @param events - A list of events to add.
1582
+ *
1583
+ * @param toStartOfTimeline - True to add these events to the start
1584
+ * (oldest) instead of the end (newest) of the timeline. If true, the oldest
1585
+ * event will be the <b>last</b> element of 'events'.
1586
+ *
1587
+ * @param timeline - timeline to
1588
+ * add events to.
1589
+ *
1590
+ * @param paginationToken - token for the next batch of events
1591
+ *
1592
+ * @remarks
1593
+ * Fires {@link RoomEvent.Timeline}
1594
+ */
1595
+ addEventsToTimeline(events, toStartOfTimeline, addToState, timeline, paginationToken) {
1596
+ timeline.getTimelineSet().addEventsToTimeline(events, toStartOfTimeline, addToState, timeline, paginationToken);
1597
+ }
1598
+
1599
+ /**
1600
+ * Get the instance of the thread associated with the current event
1601
+ * @param eventId - the ID of the current event
1602
+ * @returns a thread instance if known
1603
+ */
1604
+ getThread(eventId) {
1605
+ var _this$threads$get;
1606
+ return (_this$threads$get = this.threads.get(eventId)) !== null && _this$threads$get !== void 0 ? _this$threads$get : null;
1607
+ }
1608
+
1609
+ /**
1610
+ * Get all the known threads in the room
1611
+ */
1612
+ getThreads() {
1613
+ return Array.from(this.threads.values());
1614
+ }
1615
+
1616
+ /**
1617
+ * Get a member from the current room state.
1618
+ * @param userId - The user ID of the member.
1619
+ * @returns The member or `null`.
1620
+ */
1621
+ getMember(userId) {
1622
+ return this.currentState.getMember(userId);
1623
+ }
1624
+
1625
+ /**
1626
+ * Get all currently loaded members from the current
1627
+ * room state.
1628
+ * @returns Room members
1629
+ */
1630
+ getMembers() {
1631
+ return this.currentState.getMembers();
1632
+ }
1633
+
1634
+ /**
1635
+ * Get a list of members whose membership state is "join".
1636
+ * @returns A list of currently joined members.
1637
+ */
1638
+ getJoinedMembers() {
1639
+ return this.getMembersWithMembership(KnownMembership.Join);
1640
+ }
1641
+
1642
+ /**
1643
+ * Returns the number of joined members in this room
1644
+ * This method caches the result.
1645
+ * This is a wrapper around the method of the same name in roomState, returning
1646
+ * its result for the room's current state.
1647
+ * @returns The number of members in this room whose membership is 'join'
1648
+ */
1649
+ getJoinedMemberCount() {
1650
+ return this.currentState.getJoinedMemberCount();
1651
+ }
1652
+
1653
+ /**
1654
+ * Returns the number of invited members in this room
1655
+ * @returns The number of members in this room whose membership is 'invite'
1656
+ */
1657
+ getInvitedMemberCount() {
1658
+ return this.currentState.getInvitedMemberCount();
1659
+ }
1660
+
1661
+ /**
1662
+ * Returns the number of invited + joined members in this room
1663
+ * @returns The number of members in this room whose membership is 'invite' or 'join'
1664
+ */
1665
+ getInvitedAndJoinedMemberCount() {
1666
+ return this.getInvitedMemberCount() + this.getJoinedMemberCount();
1667
+ }
1668
+
1669
+ /**
1670
+ * Get a list of members with given membership state.
1671
+ * @param membership - The membership state.
1672
+ * @returns A list of members with the given membership state.
1673
+ */
1674
+ getMembersWithMembership(membership) {
1675
+ return this.currentState.getMembers().filter(function (m) {
1676
+ return m.membership === membership;
1677
+ });
1678
+ }
1679
+
1680
+ /**
1681
+ * Get a list of members we should be encrypting for in this room
1682
+ * @returns A list of members who
1683
+ * we should encrypt messages for in this room.
1684
+ */
1685
+ getEncryptionTargetMembers() {
1686
+ var _this0 = this;
1687
+ return _asyncToGenerator(function* () {
1688
+ yield _this0.loadMembersIfNeeded();
1689
+ var members = _this0.getMembersWithMembership(KnownMembership.Join);
1690
+ if (_this0.shouldEncryptForInvitedMembers()) {
1691
+ members = members.concat(_this0.getMembersWithMembership(KnownMembership.Invite));
1692
+ }
1693
+ return members;
1694
+ })();
1695
+ }
1696
+
1697
+ /**
1698
+ * Determine whether we should encrypt messages for invited users in this room
1699
+ * @returns if we should encrypt messages for invited users
1700
+ */
1701
+ shouldEncryptForInvitedMembers() {
1702
+ var _ev$getContent;
1703
+ var ev = this.currentState.getStateEvents(EventType.RoomHistoryVisibility, "");
1704
+ return (ev === null || ev === void 0 || (_ev$getContent = ev.getContent()) === null || _ev$getContent === void 0 ? void 0 : _ev$getContent.history_visibility) !== "joined";
1705
+ }
1706
+
1707
+ /**
1708
+ * Get the default room name (i.e. what a given user would see if the
1709
+ * room had no m.room.name)
1710
+ * @param userId - The userId from whose perspective we want
1711
+ * to calculate the default name
1712
+ * @returns The default room name
1713
+ */
1714
+ getDefaultRoomName(userId) {
1715
+ return this.calculateRoomName(userId, true);
1716
+ }
1717
+
1718
+ /**
1719
+ * Check if the given user_id has the given membership state.
1720
+ * @param userId - The user ID to check.
1721
+ * @param membership - The membership e.g. `'join'`
1722
+ * @returns True if this user_id has the given membership state.
1723
+ */
1724
+ hasMembershipState(userId, membership) {
1725
+ var member = this.getMember(userId);
1726
+ if (!member) {
1727
+ return false;
1728
+ }
1729
+ return member.membership === membership;
1730
+ }
1731
+
1732
+ /**
1733
+ * Add a timelineSet for this room with the given filter
1734
+ * @param filter - The filter to be applied to this timelineSet
1735
+ * @param opts - Configuration options
1736
+ * @returns The timelineSet
1737
+ */
1738
+ getOrCreateFilteredTimelineSet(filter) {
1739
+ var {
1740
+ prepopulateTimeline = true,
1741
+ useSyncEvents = true,
1742
+ pendingEvents = true
1743
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1744
+ if (this.filteredTimelineSets[filter.filterId]) {
1745
+ return this.filteredTimelineSets[filter.filterId];
1746
+ }
1747
+ var opts = Object.assign({
1748
+ filter,
1749
+ pendingEvents
1750
+ }, this.opts);
1751
+ var timelineSet = new EventTimelineSet(this, opts);
1752
+ this.reEmitter.reEmit(timelineSet, [RoomEvent.Timeline, RoomEvent.TimelineReset]);
1753
+ if (useSyncEvents) {
1754
+ this.filteredTimelineSets[filter.filterId] = timelineSet;
1755
+ this.timelineSets.push(timelineSet);
1756
+ }
1757
+ var unfilteredLiveTimeline = this.getLiveTimeline();
1758
+ // Not all filter are possible to replicate client-side only
1759
+ // When that's the case we do not want to prepopulate from the live timeline
1760
+ // as we would get incorrect results compared to what the server would send back
1761
+ if (prepopulateTimeline) {
1762
+ // populate up the new timelineSet with filtered events from our live
1763
+ // unfiltered timeline.
1764
+ //
1765
+ // XXX: This is risky as our timeline
1766
+ // may have grown huge and so take a long time to filter.
1767
+ // see https://github.com/vector-im/vector-web/issues/2109
1768
+
1769
+ unfilteredLiveTimeline.getEvents().forEach(function (event) {
1770
+ timelineSet.addLiveEvent(event, {
1771
+ addToState: false
1772
+ }); // Filtered timeline sets should not track state
1773
+ });
1774
+
1775
+ // find the earliest unfiltered timeline
1776
+ var timeline = unfilteredLiveTimeline;
1777
+ while (timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS)) {
1778
+ timeline = timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS);
1779
+ }
1780
+ timelineSet.getLiveTimeline().setPaginationToken(timeline.getPaginationToken(EventTimeline.BACKWARDS), EventTimeline.BACKWARDS);
1781
+ } else if (useSyncEvents) {
1782
+ var livePaginationToken = unfilteredLiveTimeline.getPaginationToken(Direction.Forward);
1783
+ timelineSet.getLiveTimeline().setPaginationToken(livePaginationToken, Direction.Backward);
1784
+ }
1785
+
1786
+ // alternatively, we could try to do something like this to try and re-paginate
1787
+ // in the filtered events from nothing, but Mark says it's an abuse of the API
1788
+ // to do so:
1789
+ //
1790
+ // timelineSet.resetLiveTimeline(
1791
+ // unfilteredLiveTimeline.getPaginationToken(EventTimeline.FORWARDS)
1792
+ // );
1793
+
1794
+ return timelineSet;
1795
+ }
1796
+ getThreadListFilter() {
1797
+ var _arguments = arguments,
1798
+ _this1 = this;
1799
+ return _asyncToGenerator(function* () {
1800
+ var filterType = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : ThreadFilterType.All;
1801
+ var myUserId = _this1.client.getUserId();
1802
+ var filter = new Filter(myUserId);
1803
+ var definition = {
1804
+ room: {
1805
+ timeline: {
1806
+ [FILTER_RELATED_BY_REL_TYPES.name]: [THREAD_RELATION_TYPE.name]
1807
+ }
1808
+ }
1809
+ };
1810
+ if (filterType === ThreadFilterType.My) {
1811
+ definition.room.timeline[FILTER_RELATED_BY_SENDERS.name] = [myUserId];
1812
+ }
1813
+ filter.setDefinition(definition);
1814
+ var filterId = yield _this1.client.getOrCreateFilter("THREAD_PANEL_".concat(_this1.roomId, "_").concat(filterType), filter);
1815
+ filter.filterId = filterId;
1816
+ return filter;
1817
+ })();
1818
+ }
1819
+ createThreadTimelineSet(filterType) {
1820
+ var _this10 = this;
1821
+ return _asyncToGenerator(function* () {
1822
+ var timelineSet;
1823
+ if (Thread.hasServerSideListSupport) {
1824
+ timelineSet = new EventTimelineSet(_this10, _objectSpread(_objectSpread({}, _this10.opts), {}, {
1825
+ pendingEvents: false
1826
+ }), undefined, undefined, filterType !== null && filterType !== void 0 ? filterType : ThreadFilterType.All);
1827
+ _this10.reEmitter.reEmit(timelineSet, [RoomEvent.Timeline, RoomEvent.TimelineReset]);
1828
+ } else if (Thread.hasServerSideSupport) {
1829
+ var filter = yield _this10.getThreadListFilter(filterType);
1830
+ timelineSet = _this10.getOrCreateFilteredTimelineSet(filter, {
1831
+ prepopulateTimeline: false,
1832
+ useSyncEvents: false,
1833
+ pendingEvents: false
1834
+ });
1835
+ } else {
1836
+ timelineSet = new EventTimelineSet(_this10, {
1837
+ pendingEvents: false
1838
+ });
1839
+ Array.from(_this10.threads).forEach(_ref3 => {
1840
+ var [, thread] = _ref3;
1841
+ if (thread.length === 0) return;
1842
+ var currentUserParticipated = thread.timeline.some(event => {
1843
+ return event.getSender() === _this10.client.getUserId();
1844
+ });
1845
+ if (filterType !== ThreadFilterType.My || currentUserParticipated) {
1846
+ timelineSet.getLiveTimeline().addEvent(thread.rootEvent, {
1847
+ toStartOfTimeline: false,
1848
+ addToState: false
1849
+ });
1850
+ }
1851
+ });
1852
+ }
1853
+ return timelineSet;
1854
+ })();
1855
+ }
1856
+ /**
1857
+ * Takes the given thread root events and creates threads for them.
1858
+ */
1859
+ processThreadRoots(events, toStartOfTimeline) {
1860
+ if (!this.client.supportsThreads()) return;
1861
+ for (var rootEvent of events) {
1862
+ EventTimeline.setEventMetadata(rootEvent, this.currentState, toStartOfTimeline);
1863
+ if (!this.getThread(rootEvent.getId())) {
1864
+ this.createThread(rootEvent.getId(), rootEvent, [], toStartOfTimeline);
1865
+ }
1866
+ }
1867
+ }
1868
+
1869
+ /**
1870
+ * Fetch the bare minimum of room threads required for the thread list to work reliably.
1871
+ * With server support that means fetching one page.
1872
+ * Without server support that means fetching as much at once as the server allows us to.
1873
+ */
1874
+ fetchRoomThreads() {
1875
+ var _this11 = this;
1876
+ return _asyncToGenerator(function* () {
1877
+ if (_this11.threadsReady || !_this11.client.supportsThreads()) {
1878
+ return;
1879
+ }
1880
+ if (Thread.hasServerSideListSupport) {
1881
+ yield Promise.all([_this11.fetchRoomThreadList(ThreadFilterType.All), _this11.fetchRoomThreadList(ThreadFilterType.My)]);
1882
+ } else {
1883
+ var allThreadsFilter = yield _this11.getThreadListFilter();
1884
+ var {
1885
+ chunk: events
1886
+ } = yield _this11.client.createMessagesRequest(_this11.roomId, "", Number.MAX_SAFE_INTEGER, Direction.Backward, allThreadsFilter);
1887
+ if (!events.length) return;
1888
+
1889
+ // Sorted by last_reply origin_server_ts
1890
+ var threadRoots = events.map(_this11.client.getEventMapper()).sort((eventA, eventB) => {
1891
+ /**
1892
+ * `origin_server_ts` in a decentralised world is far from ideal
1893
+ * but for lack of any better, we will have to use this
1894
+ * Long term the sorting should be handled by homeservers and this
1895
+ * is only meant as a short term patch
1896
+ */
1897
+ var threadAMetadata = eventA.getServerAggregatedRelation(THREAD_RELATION_TYPE.name);
1898
+ var threadBMetadata = eventB.getServerAggregatedRelation(THREAD_RELATION_TYPE.name);
1899
+ return threadAMetadata.latest_event.origin_server_ts - threadBMetadata.latest_event.origin_server_ts;
1900
+ });
1901
+ var latestMyThreadsRootEvent;
1902
+ var roomState = _this11.getLiveTimeline().getState(EventTimeline.FORWARDS);
1903
+ for (var rootEvent of threadRoots) {
1904
+ var _this11$threadsTimeli;
1905
+ var _opts = {
1906
+ duplicateStrategy: DuplicateStrategy.Ignore,
1907
+ fromCache: false,
1908
+ addToState: false,
1909
+ roomState
1910
+ };
1911
+ (_this11$threadsTimeli = _this11.threadsTimelineSets[0]) === null || _this11$threadsTimeli === void 0 || _this11$threadsTimeli.addLiveEvent(rootEvent, _opts);
1912
+ var threadRelationship = rootEvent.getServerAggregatedRelation(THREAD_RELATION_TYPE.name);
1913
+ if (threadRelationship !== null && threadRelationship !== void 0 && threadRelationship.current_user_participated) {
1914
+ var _this11$threadsTimeli2;
1915
+ (_this11$threadsTimeli2 = _this11.threadsTimelineSets[1]) === null || _this11$threadsTimeli2 === void 0 || _this11$threadsTimeli2.addLiveEvent(rootEvent, _opts);
1916
+ latestMyThreadsRootEvent = rootEvent;
1917
+ }
1918
+ }
1919
+ _this11.processThreadRoots(threadRoots, true);
1920
+ _this11.client.decryptEventIfNeeded(threadRoots[threadRoots.length - 1]);
1921
+ if (latestMyThreadsRootEvent) {
1922
+ _this11.client.decryptEventIfNeeded(latestMyThreadsRootEvent);
1923
+ }
1924
+ }
1925
+ _this11.on(ThreadEvent.NewReply, _this11.onThreadReply);
1926
+ _this11.on(ThreadEvent.Update, _this11.onThreadUpdate);
1927
+ _this11.on(ThreadEvent.Delete, _this11.onThreadDelete);
1928
+ _this11.threadsReady = true;
1929
+ })();
1930
+ }
1931
+
1932
+ /**
1933
+ * Process a list of poll events.
1934
+ *
1935
+ * @param events - List of events
1936
+ */
1937
+ processPollEvents(events) {
1938
+ var _this12 = this;
1939
+ return _asyncToGenerator(function* () {
1940
+ for (var event of events) {
1941
+ try {
1942
+ // Continue if the event is a clear text, non-poll event.
1943
+ if (!event.isEncrypted() && !isPollEvent(event)) continue;
1944
+
1945
+ /**
1946
+ * Try to decrypt the event. Promise resolution does not guarantee a successful decryption.
1947
+ * Retry is handled in {@link processPollEvent}.
1948
+ */
1949
+ yield _this12.client.decryptEventIfNeeded(event);
1950
+ _this12.processPollEvent(event);
1951
+ } catch (err) {
1952
+ logger.warn("Error processing poll event", event.getId(), err);
1953
+ }
1954
+ }
1955
+ })();
1956
+ }
1957
+
1958
+ /**
1959
+ * Processes poll events:
1960
+ * If the event has a decryption failure, it will listen for decryption and tries again.
1961
+ * If it is a poll start event (`m.poll.start`),
1962
+ * it creates and stores a Poll model and emits a PollEvent.New event.
1963
+ * If the event is related to a poll, it will add it to the poll.
1964
+ * Noop for other cases.
1965
+ *
1966
+ * @param event - Event that could be a poll event
1967
+ */
1968
+ processPollEvent(event) {
1969
+ var _this13 = this;
1970
+ return _asyncToGenerator(function* () {
1971
+ if (event.isDecryptionFailure()) {
1972
+ event.once(BriijEventEvent.Decrypted, maybeDecryptedEvent => {
1973
+ _this13.processPollEvent(maybeDecryptedEvent);
1974
+ });
1975
+ return;
1976
+ }
1977
+ if (M_POLL_START.matches(event.getType())) {
1978
+ try {
1979
+ var poll = new Poll(event, _this13.client, _this13);
1980
+ _this13.polls.set(event.getId(), poll);
1981
+ _this13.emit(PollEvent.New, poll);
1982
+
1983
+ // remove the poll when redacted
1984
+ event.once(BriijEventEvent.BeforeRedaction, redactedEvent => {
1985
+ _this13.polls.delete(redactedEvent.getId());
1986
+ });
1987
+ } catch (_unused3) {}
1988
+ // poll creation can fail for malformed poll start events
1989
+ return;
1990
+ }
1991
+ var relationEventId = event.relationEventId;
1992
+ if (relationEventId && _this13.polls.has(relationEventId)) {
1993
+ var _poll = _this13.polls.get(relationEventId);
1994
+ _poll === null || _poll === void 0 || _poll.onNewRelation(event);
1995
+ }
1996
+ })();
1997
+ }
1998
+
1999
+ /**
2000
+ * Fetch a single page of threadlist messages for the specific thread filter
2001
+ * @internal
2002
+ */
2003
+ fetchRoomThreadList(filter) {
2004
+ var _this14 = this;
2005
+ return _asyncToGenerator(function* () {
2006
+ if (!_this14.client.supportsThreads()) return;
2007
+ if (_this14.threadsTimelineSets.length === 0) return;
2008
+ var timelineSet = filter === ThreadFilterType.My ? _this14.threadsTimelineSets[1] : _this14.threadsTimelineSets[0];
2009
+ var {
2010
+ chunk: events,
2011
+ end
2012
+ } = yield _this14.client.createThreadListMessagesRequest(_this14.roomId, null, undefined, Direction.Backward, timelineSet.threadListType, timelineSet.getFilter());
2013
+ timelineSet.getLiveTimeline().setPaginationToken(end !== null && end !== void 0 ? end : null, Direction.Backward);
2014
+ if (!events.length) return;
2015
+ var matrixEvents = events.map(_this14.client.getEventMapper());
2016
+ _this14.processThreadRoots(matrixEvents, true);
2017
+ var roomState = _this14.getLiveTimeline().getState(EventTimeline.FORWARDS);
2018
+ for (var rootEvent of matrixEvents) {
2019
+ timelineSet.addLiveEvent(rootEvent, {
2020
+ duplicateStrategy: DuplicateStrategy.Replace,
2021
+ fromCache: false,
2022
+ roomState,
2023
+ addToState: false
2024
+ });
2025
+ }
2026
+ })();
2027
+ }
2028
+ onThreadUpdate(thread) {
2029
+ this.updateThreadRootEvents(thread, false, false);
2030
+ }
2031
+ onThreadReply(thread) {
2032
+ this.updateThreadRootEvents(thread, false, true);
2033
+ }
2034
+ onThreadDelete(thread) {
2035
+ var _timeline$getEvents;
2036
+ this.threads.delete(thread.id);
2037
+ var timeline = this.getTimelineForEvent(thread.id);
2038
+ var roomEvent = timeline === null || timeline === void 0 || (_timeline$getEvents = timeline.getEvents()) === null || _timeline$getEvents === void 0 ? void 0 : _timeline$getEvents.find(it => it.getId() === thread.id);
2039
+ if (roomEvent) {
2040
+ thread.clearEventMetadata(roomEvent);
2041
+ } else {
2042
+ logger.debug("onThreadDelete: Could not find root event in room timeline");
2043
+ }
2044
+ for (var timelineSet of this.threadsTimelineSets) {
2045
+ timelineSet.removeEvent(thread.id);
2046
+ }
2047
+ }
2048
+
2049
+ /**
2050
+ * Forget the timelineSet for this room with the given filter
2051
+ *
2052
+ * @param filter - the filter whose timelineSet is to be forgotten
2053
+ */
2054
+ removeFilteredTimelineSet(filter) {
2055
+ var timelineSet = this.filteredTimelineSets[filter.filterId];
2056
+ delete this.filteredTimelineSets[filter.filterId];
2057
+ var i = this.timelineSets.indexOf(timelineSet);
2058
+ if (i > -1) {
2059
+ this.timelineSets.splice(i, 1);
2060
+ }
2061
+ }
2062
+
2063
+ /**
2064
+ * Determine which timeline(s) a given event should live in
2065
+ * Thread roots live in both the main timeline and their corresponding thread timeline
2066
+ * Relations, redactions, replies to thread relation events live only in the thread timeline
2067
+ * Relations (other than m.thread), redactions, replies to a thread root live only in the main timeline
2068
+ * Relations, redactions, replies where the parent cannot be found live in no timelines but should be aggregated regardless.
2069
+ * Otherwise, the event lives in the main timeline only.
2070
+ *
2071
+ * Note: when a redaction is applied, the redacted event, events relating
2072
+ * to it, and the redaction event itself, will all move to the main thread.
2073
+ * This method classifies them as inside the thread of the redacted event.
2074
+ * They are moved later as part of makeRedacted.
2075
+ * This will change if MSC3389 is merged.
2076
+ */
2077
+ eventShouldLiveIn(event, events, roots) {
2078
+ var _this$client;
2079
+ if (!((_this$client = this.client) !== null && _this$client !== void 0 && _this$client.supportsThreads())) {
2080
+ return {
2081
+ shouldLiveInRoom: true,
2082
+ shouldLiveInThread: false
2083
+ };
2084
+ }
2085
+
2086
+ // A thread root is the only event shown in both timelines
2087
+ if (event.isThreadRoot || roots !== null && roots !== void 0 && roots.has(event.getId())) {
2088
+ return {
2089
+ shouldLiveInRoom: true,
2090
+ shouldLiveInThread: true,
2091
+ threadId: event.getId()
2092
+ };
2093
+ }
2094
+ var isThreadRelation = event.isRelation(THREAD_RELATION_TYPE.name);
2095
+ var parentEventId = event.getAssociatedId();
2096
+ var threadRootId = event.threadRootId;
2097
+
2098
+ // Where the parent is the thread root and this is a non-thread relation this should live only in the main timeline
2099
+ if (!!parentEventId && !isThreadRelation && (threadRootId === parentEventId || roots !== null && roots !== void 0 && roots.has(parentEventId))) {
2100
+ return {
2101
+ shouldLiveInRoom: true,
2102
+ shouldLiveInThread: false
2103
+ };
2104
+ }
2105
+ var parentEvent;
2106
+ if (parentEventId) {
2107
+ var _this$findEventById;
2108
+ parentEvent = (_this$findEventById = this.findEventById(parentEventId)) !== null && _this$findEventById !== void 0 ? _this$findEventById : events === null || events === void 0 ? void 0 : events.find(e => e.getId() === parentEventId);
2109
+ }
2110
+
2111
+ // Treat non-thread-relations, redactions, and replies as extensions of their parents so evaluate parentEvent instead
2112
+ if (parentEvent && !isThreadRelation) {
2113
+ return this.eventShouldLiveIn(parentEvent, events, roots);
2114
+ }
2115
+
2116
+ // A thread relation (1st and 2nd order) is always only shown in a thread
2117
+ if (threadRootId != undefined) {
2118
+ return {
2119
+ shouldLiveInRoom: false,
2120
+ shouldLiveInThread: true,
2121
+ threadId: threadRootId
2122
+ };
2123
+ }
2124
+
2125
+ // Due to replies not being typical relations and being used as fallbacks for threads relations
2126
+ // If we bypass the if case above then we know we are not a thread, so if we are still a reply
2127
+ // then we know that we must be in the main timeline. Same goes if we have no associated parent event.
2128
+ if (!parentEventId || !!event.replyEventId) {
2129
+ return {
2130
+ shouldLiveInRoom: true,
2131
+ shouldLiveInThread: false
2132
+ };
2133
+ }
2134
+
2135
+ // We've exhausted all scenarios,
2136
+ // we cannot assume that it lives in the main timeline as this may be a relation for an unknown thread
2137
+ // adding the event in the wrong timeline causes stuck notifications and can break ability to send read receipts
2138
+ return {
2139
+ shouldLiveInRoom: false,
2140
+ shouldLiveInThread: false
2141
+ };
2142
+ }
2143
+ findThreadForEvent(event) {
2144
+ if (!event) return null;
2145
+ var {
2146
+ threadId
2147
+ } = this.eventShouldLiveIn(event);
2148
+ return threadId ? this.getThread(threadId) : null;
2149
+ }
2150
+ addThreadedEvents(threadId, events) {
2151
+ var toStartOfTimeline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2152
+ var thread = this.getThread(threadId);
2153
+ if (thread) {
2154
+ thread.addEvents(events, toStartOfTimeline);
2155
+ } else {
2156
+ var _this$findEventById2;
2157
+ var rootEvent = (_this$findEventById2 = this.findEventById(threadId)) !== null && _this$findEventById2 !== void 0 ? _this$findEventById2 : events.find(e => e.getId() === threadId);
2158
+ this.createThread(threadId, rootEvent, events, toStartOfTimeline);
2159
+ }
2160
+ }
2161
+
2162
+ /**
2163
+ * Adds events to a thread's timeline. Will fire "Thread.update"
2164
+ */
2165
+ processThreadedEvents(events, toStartOfTimeline) {
2166
+ events.forEach(this.tryApplyRedaction);
2167
+ var eventsByThread = {};
2168
+ for (var event of events) {
2169
+ var _eventsByThread;
2170
+ var {
2171
+ threadId,
2172
+ shouldLiveInThread
2173
+ } = this.eventShouldLiveIn(event);
2174
+ if (shouldLiveInThread && !eventsByThread[threadId]) {
2175
+ eventsByThread[threadId] = [];
2176
+ }
2177
+ (_eventsByThread = eventsByThread[threadId]) === null || _eventsByThread === void 0 || _eventsByThread.push(event);
2178
+ }
2179
+ Object.entries(eventsByThread).map(_ref4 => {
2180
+ var [threadId, threadEvents] = _ref4;
2181
+ return this.addThreadedEvents(threadId, threadEvents, toStartOfTimeline);
2182
+ });
2183
+ }
2184
+ createThread(threadId, rootEvent) {
2185
+ var _this$cachedThreadRea;
2186
+ var events = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
2187
+ var toStartOfTimeline = arguments.length > 3 ? arguments[3] : undefined;
2188
+ if (this.threads.has(threadId)) {
2189
+ return this.threads.get(threadId);
2190
+ }
2191
+ if (rootEvent) {
2192
+ var relatedEvents = this.relations.getAllChildEventsForEvent(rootEvent.getId());
2193
+ if (relatedEvents !== null && relatedEvents !== void 0 && relatedEvents.length) {
2194
+ // Include all relations of the root event, given it'll be visible in both timelines,
2195
+ // except `m.replace` as that will already be applied atop the event using `BriijEvent::makeReplaced`
2196
+ events = events.concat(relatedEvents.filter(e => !e.isRelation(RelationType.Replace)));
2197
+ }
2198
+ }
2199
+ var thread = new Thread(threadId, rootEvent, {
2200
+ room: this,
2201
+ client: this.client,
2202
+ pendingEventOrdering: this.opts.pendingEventOrdering,
2203
+ receipts: (_this$cachedThreadRea = this.cachedThreadReadReceipts.get(threadId)) !== null && _this$cachedThreadRea !== void 0 ? _this$cachedThreadRea : []
2204
+ });
2205
+
2206
+ // Add the re-emitter before we start adding events to the thread so we don't miss events
2207
+ this.reEmitter.reEmit(thread, [ThreadEvent.Delete, ThreadEvent.Update, ThreadEvent.NewReply, RoomEvent.Timeline, RoomEvent.TimelineReset]);
2208
+
2209
+ // All read receipts should now come down from sync, we do not need to keep
2210
+ // a reference to the cached receipts anymore.
2211
+ this.cachedThreadReadReceipts.delete(threadId);
2212
+
2213
+ // If we managed to create a thread and figure out its `id` then we can use it
2214
+ // This has to happen before thread.addEvents, because that adds events to the eventtimeline, and the
2215
+ // eventtimeline sometimes looks up thread information via the room.
2216
+ this.threads.set(thread.id, thread);
2217
+
2218
+ // This is necessary to be able to jump to events in threads:
2219
+ // If we jump to an event in a thread where neither the event, nor the root,
2220
+ // nor any thread event are loaded yet, we'll load the event as well as the thread root, create the thread,
2221
+ // and pass the event through this.
2222
+ thread.addEvents(events, false);
2223
+
2224
+ // We need to update the thread root events, but the thread may not be ready yet.
2225
+ // If it isn't, it will fire ThreadEvent.Update when it is and we'll call updateThreadRootEvents then.
2226
+ if (this.threadsReady && thread.initialEventsFetched) {
2227
+ this.updateThreadRootEvents(thread, toStartOfTimeline, false);
2228
+ }
2229
+ this.emit(ThreadEvent.New, thread, toStartOfTimeline);
2230
+ return thread;
2231
+ }
2232
+
2233
+ /**
2234
+ * Applies an event as a redaction of another event, regardless of whether the redacting
2235
+ * event is actually a redaction.
2236
+ *
2237
+ * Callers should use tryApplyRedaction instead.
2238
+ *
2239
+ * @param redactionEvent The event which redacts an event.
2240
+ * @param redactedEvent The event being redacted.
2241
+ * @private
2242
+ */
2243
+ applyEventAsRedaction(redactionEvent, redactedEvent) {
2244
+ var threadRootId = redactedEvent.threadRootId;
2245
+ redactedEvent.makeRedacted(redactionEvent, this);
2246
+
2247
+ // If this is in the current state, replace it with the redacted version
2248
+ if (redactedEvent.isState()) {
2249
+ var currentStateEvent = this.currentState.getStateEvents(redactedEvent.getType(), redactedEvent.getStateKey());
2250
+ if ((currentStateEvent === null || currentStateEvent === void 0 ? void 0 : currentStateEvent.getId()) === redactedEvent.getId()) {
2251
+ this.currentState.setStateEvents([redactedEvent]);
2252
+ }
2253
+ }
2254
+ this.emit(RoomEvent.Redaction, redactionEvent, this, threadRootId);
2255
+
2256
+ // TODO: we stash user displaynames (among other things) in
2257
+ // RoomMember objects which are then attached to other events
2258
+ // (in the sender and target fields). We should get those
2259
+ // RoomMember objects to update themselves when the events that
2260
+ // they are based on are changed.
2261
+
2262
+ // Remove any visibility change on this event.
2263
+ this.visibilityEvents.delete(redactedEvent.getId());
2264
+
2265
+ // If this event is a visibility change event, remove it from the
2266
+ // list of visibility changes and update any event affected by it.
2267
+ if (redactedEvent.isVisibilityEvent()) {
2268
+ this.redactVisibilityChangeEvent(redactionEvent);
2269
+ }
2270
+ }
2271
+ processLiveEvent(event) {
2272
+ this.tryApplyRedaction(event);
2273
+
2274
+ // Implement MSC3531: hiding messages.
2275
+ if (event.isVisibilityEvent()) {
2276
+ // This event changes the visibility of another event, record
2277
+ // the visibility change, inform clients if necessary.
2278
+ this.applyNewVisibilityEvent(event);
2279
+ }
2280
+ // If any pending visibility change is waiting for this (older) event,
2281
+ this.applyPendingVisibilityEvents(event);
2282
+
2283
+ // Sliding Sync modifications:
2284
+ // The proxy cannot guarantee every sent event will have a transaction_id field, so we need
2285
+ // to check the event ID against the list of pending events if there is no transaction ID
2286
+ // field. Only do this for events sent by us though as it's potentially expensive to loop
2287
+ // the pending events map.
2288
+ var txnId = event.getUnsigned().transaction_id;
2289
+ if (!txnId && event.getSender() === this.myUserId) {
2290
+ // check the txn map for a matching event ID
2291
+ for (var [tid, localEvent] of this.txnToEvent) {
2292
+ if (localEvent.getId() === event.getId()) {
2293
+ logger.debug("processLiveEvent: found sent event without txn ID: ", tid, event.getId());
2294
+ // update the unsigned field so we can re-use the same codepaths
2295
+ var unsigned = event.getUnsigned();
2296
+ unsigned.transaction_id = tid;
2297
+ event.setUnsigned(unsigned);
2298
+ break;
2299
+ }
2300
+ }
2301
+ }
2302
+ }
2303
+
2304
+ /**
2305
+ * Add an event to the end of this room's live timelines. Will fire
2306
+ * "Room.timeline".
2307
+ *
2308
+ * @param event - Event to be added
2309
+ * @param addLiveEventOptions - addLiveEvent options
2310
+ * @internal
2311
+ *
2312
+ * @remarks
2313
+ * Fires {@link RoomEvent.Timeline}
2314
+ */
2315
+ addLiveEvent(event, addLiveEventOptions) {
2316
+ var {
2317
+ duplicateStrategy,
2318
+ timelineWasEmpty,
2319
+ fromCache,
2320
+ addToState
2321
+ } = addLiveEventOptions;
2322
+
2323
+ // add to our timeline sets
2324
+ for (var timelineSet of this.timelineSets) {
2325
+ timelineSet.addLiveEvent(event, {
2326
+ duplicateStrategy,
2327
+ fromCache,
2328
+ timelineWasEmpty,
2329
+ addToState
2330
+ });
2331
+ }
2332
+
2333
+ // synthesize and inject implicit read receipts
2334
+ // Done after adding the event because otherwise the app would get a read receipt
2335
+ // pointing to an event that wasn't yet in the timeline
2336
+ // Don't synthesize RR for m.room.redaction as this causes the RR to go missing.
2337
+ if (event.sender && event.getType() !== EventType.RoomRedaction) {
2338
+ this.addReceipt(synthesizeReceipt(event.sender.userId, event, ReceiptType.Read), true);
2339
+
2340
+ // Any live events from a user could be taken as implicit
2341
+ // presence information: evidence that they are currently active.
2342
+ // ...except in a world where we use 'user.currentlyActive' to reduce
2343
+ // presence spam, this isn't very useful - we'll get a transition when
2344
+ // they are no longer currently active anyway. So don't bother to
2345
+ // reset the lastActiveAgo and lastPresenceTs from the RoomState's user.
2346
+ }
2347
+ }
2348
+
2349
+ /**
2350
+ * Add a pending outgoing event to this room.
2351
+ *
2352
+ * <p>The event is added to either the pendingEventList, or the live timeline,
2353
+ * depending on the setting of opts.pendingEventOrdering.
2354
+ *
2355
+ * <p>This is an internal method, intended for use by BriijClient.
2356
+ *
2357
+ * @param event - The event to add.
2358
+ *
2359
+ * @param txnId - Transaction id for this outgoing event
2360
+ *
2361
+ * @throws if the event doesn't have status SENDING, or we aren't given a
2362
+ * unique transaction id.
2363
+ *
2364
+ * @remarks
2365
+ * Fires {@link RoomEvent.LocalEchoUpdated}
2366
+ */
2367
+ addPendingEvent(event, txnId) {
2368
+ if (event.status !== EventStatus.SENDING && event.status !== EventStatus.NOT_SENT) {
2369
+ throw new Error("addPendingEvent called on an event with status " + event.status);
2370
+ }
2371
+ if (this.txnToEvent.get(txnId)) {
2372
+ throw new Error("addPendingEvent called on an event with known txnId " + txnId);
2373
+ }
2374
+
2375
+ // call setEventMetadata to set up event.sender etc
2376
+ // as event is shared over all timelineSets, we set up its metadata based
2377
+ // on the unfiltered timelineSet.
2378
+ EventTimeline.setEventMetadata(event, this.getLiveTimeline().getState(EventTimeline.FORWARDS), false);
2379
+ this.txnToEvent.set(txnId, event);
2380
+ if (this.pendingEventList) {
2381
+ if (this.pendingEventList.some(e => e.status === EventStatus.NOT_SENT)) {
2382
+ logger.warn("Setting event as NOT_SENT due to messages in the same state");
2383
+ event.setStatus(EventStatus.NOT_SENT);
2384
+ }
2385
+ this.pendingEventList.push(event);
2386
+ this.savePendingEvents();
2387
+ if (event.isRelation()) {
2388
+ // For pending events, add them to the relations collection immediately.
2389
+ // (The alternate case below already covers this as part of adding to
2390
+ // the timeline set.)
2391
+ this.aggregateNonLiveRelation(event);
2392
+ }
2393
+ if (event.isRedaction()) {
2394
+ var redactId = event.event.redacts;
2395
+ var redactedEvent = this.pendingEventList.find(e => e.getId() === redactId);
2396
+ if (!redactedEvent && redactId) {
2397
+ redactedEvent = this.findEventById(redactId);
2398
+ }
2399
+ if (redactedEvent) {
2400
+ redactedEvent.markLocallyRedacted(event);
2401
+ this.emit(RoomEvent.Redaction, event, this, redactedEvent.threadRootId);
2402
+ }
2403
+ }
2404
+ } else {
2405
+ for (var timelineSet of this.timelineSets) {
2406
+ if (timelineSet.getFilter()) {
2407
+ if (timelineSet.getFilter().filterRoomTimeline([event]).length) {
2408
+ timelineSet.addEventToTimeline(event, timelineSet.getLiveTimeline(), {
2409
+ toStartOfTimeline: false,
2410
+ addToState: false // We don't support localEcho of state events yet
2411
+ });
2412
+ }
2413
+ } else {
2414
+ timelineSet.addEventToTimeline(event, timelineSet.getLiveTimeline(), {
2415
+ toStartOfTimeline: false,
2416
+ addToState: false // We don't support localEcho of state events yet
2417
+ });
2418
+ }
2419
+ }
2420
+ }
2421
+ this.emit(RoomEvent.LocalEchoUpdated, event, this);
2422
+ }
2423
+
2424
+ /**
2425
+ * Persists all pending events to local storage
2426
+ *
2427
+ * If the current room is encrypted only encrypted events will be persisted
2428
+ * all messages that are not yet encrypted will be discarded
2429
+ *
2430
+ * This is because the flow of EVENT_STATUS transition is
2431
+ * `queued => sending => encrypting => sending => sent`
2432
+ *
2433
+ * Steps 3 and 4 are skipped for unencrypted room.
2434
+ * It is better to discard an unencrypted message rather than persisting
2435
+ * it locally for everyone to read
2436
+ */
2437
+ savePendingEvents() {
2438
+ if (this.pendingEventList) {
2439
+ var pendingEvents = this.pendingEventList.map(event => {
2440
+ return _objectSpread(_objectSpread({}, event.event), {}, {
2441
+ txn_id: event.getTxnId()
2442
+ });
2443
+ }).filter(event => {
2444
+ // Filter out the unencrypted messages if the room is encrypted
2445
+ var isEventEncrypted = event.type === EventType.RoomMessageEncrypted;
2446
+ var isRoomEncrypted = this.hasEncryptionStateEvent();
2447
+ return isEventEncrypted || !isRoomEncrypted;
2448
+ });
2449
+ this.client.store.setPendingEvents(this.roomId, pendingEvents);
2450
+ }
2451
+ }
2452
+
2453
+ /**
2454
+ * Used to aggregate the local echo for a relation, and also
2455
+ * for re-applying a relation after it's redaction has been cancelled,
2456
+ * as the local echo for the redaction of the relation would have
2457
+ * un-aggregated the relation. Note that this is different from regular messages,
2458
+ * which are just kept detached for their local echo.
2459
+ *
2460
+ * Also note that live events are aggregated in the live EventTimelineSet.
2461
+ * @param event - the relation event that needs to be aggregated.
2462
+ */
2463
+ aggregateNonLiveRelation(event) {
2464
+ this.relations.aggregateChildEvent(event);
2465
+ }
2466
+ getEventForTxnId(txnId) {
2467
+ return this.txnToEvent.get(txnId);
2468
+ }
2469
+
2470
+ /**
2471
+ * Deal with the echo of a message we sent.
2472
+ *
2473
+ * <p>We move the event to the live timeline if it isn't there already, and
2474
+ * update it.
2475
+ *
2476
+ * @param remoteEvent - The event received from
2477
+ * /sync
2478
+ * @param localEvent - The local echo, which
2479
+ * should be either in the pendingEventList or the timeline.
2480
+ *
2481
+ * @internal
2482
+ *
2483
+ * @remarks
2484
+ * Fires {@link RoomEvent.LocalEchoUpdated}
2485
+ */
2486
+ handleRemoteEcho(remoteEvent, localEvent) {
2487
+ var oldEventId = localEvent.getId();
2488
+ var newEventId = remoteEvent.getId();
2489
+ var oldStatus = localEvent.status;
2490
+ logger.debug("Got remote echo for event ".concat(oldEventId, " -> ").concat(newEventId, " old status ").concat(oldStatus));
2491
+
2492
+ // no longer pending
2493
+ this.txnToEvent.delete(remoteEvent.getUnsigned().transaction_id);
2494
+
2495
+ // if it's in the pending list, remove it
2496
+ if (this.pendingEventList) {
2497
+ this.removePendingEvent(oldEventId);
2498
+ }
2499
+
2500
+ // replace the event source (this will preserve the plaintext payload if
2501
+ // any, which is good, because we don't want to try decoding it again).
2502
+ localEvent.handleRemoteEcho(remoteEvent.event);
2503
+ var {
2504
+ shouldLiveInRoom,
2505
+ threadId
2506
+ } = this.eventShouldLiveIn(remoteEvent);
2507
+ var thread = threadId ? this.getThread(threadId) : null;
2508
+ thread === null || thread === void 0 || thread.setEventMetadata(localEvent);
2509
+ thread === null || thread === void 0 || thread.timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
2510
+ if (shouldLiveInRoom) {
2511
+ for (var timelineSet of this.timelineSets) {
2512
+ // if it's already in the timeline, update the timeline map. If it's not, add it.
2513
+ timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
2514
+ }
2515
+ }
2516
+ this.emit(RoomEvent.LocalEchoUpdated, localEvent, this, oldEventId, oldStatus);
2517
+ }
2518
+
2519
+ /**
2520
+ * Update the status / event id on a pending event, to reflect its transmission
2521
+ * progress.
2522
+ *
2523
+ * <p>This is an internal method.
2524
+ *
2525
+ * @param event - local echo event
2526
+ * @param newStatus - status to assign
2527
+ * @param newEventId - new event id to assign. Ignored unless newStatus == EventStatus.SENT.
2528
+ *
2529
+ * @remarks
2530
+ * Fires {@link RoomEvent.LocalEchoUpdated}
2531
+ */
2532
+ updatePendingEvent(event, newStatus, newEventId) {
2533
+ logger.log("setting pendingEvent status to ".concat(newStatus, " in ").concat(event.getRoomId(), " ") + "event ID ".concat(event.getId(), " -> ").concat(newEventId));
2534
+
2535
+ // if the message was sent, we expect an event id
2536
+ if (newStatus == EventStatus.SENT && !newEventId) {
2537
+ throw new Error("updatePendingEvent called with status=SENT, but no new event id");
2538
+ }
2539
+
2540
+ // SENT races against /sync, so we have to special-case it.
2541
+ if (newStatus == EventStatus.SENT) {
2542
+ var timeline = this.getTimelineForEvent(newEventId);
2543
+ if (timeline) {
2544
+ // we've already received the event via the event stream.
2545
+ // nothing more to do here, assuming the transaction ID was correctly matched.
2546
+ // Let's check that.
2547
+ var remoteEvent = this.findEventById(newEventId);
2548
+ var remoteTxnId = remoteEvent === null || remoteEvent === void 0 ? void 0 : remoteEvent.getUnsigned().transaction_id;
2549
+ if (!remoteTxnId && remoteEvent) {
2550
+ // This code path is mostly relevant for the Sliding Sync proxy.
2551
+ // The remote event did not contain a transaction ID, so we did not handle
2552
+ // the remote echo yet. Handle it now.
2553
+ var unsigned = remoteEvent.getUnsigned();
2554
+ unsigned.transaction_id = event.getTxnId();
2555
+ remoteEvent.setUnsigned(unsigned);
2556
+ // the remote event is _already_ in the timeline, so we need to remove it so
2557
+ // we can convert the local event into the final event.
2558
+ this.removeEvent(remoteEvent.getId());
2559
+ this.handleRemoteEcho(remoteEvent, event);
2560
+ }
2561
+ return;
2562
+ }
2563
+ }
2564
+ var oldStatus = event.status;
2565
+ var oldEventId = event.getId();
2566
+ if (!oldStatus) {
2567
+ throw new Error("updatePendingEventStatus called on an event which is not a local echo.");
2568
+ }
2569
+ var allowed = ALLOWED_TRANSITIONS[oldStatus];
2570
+ if (!(allowed !== null && allowed !== void 0 && allowed.includes(newStatus))) {
2571
+ throw new Error("Invalid EventStatus transition ".concat(oldStatus, "->").concat(newStatus));
2572
+ }
2573
+ event.setStatus(newStatus);
2574
+ if (newStatus == EventStatus.SENT) {
2575
+ // update the event id
2576
+ event.replaceLocalEventId(newEventId);
2577
+ var {
2578
+ shouldLiveInRoom,
2579
+ threadId
2580
+ } = this.eventShouldLiveIn(event);
2581
+ var thread = threadId ? this.getThread(threadId) : undefined;
2582
+ thread === null || thread === void 0 || thread.setEventMetadata(event);
2583
+ thread === null || thread === void 0 || thread.timelineSet.replaceEventId(oldEventId, newEventId);
2584
+ if (shouldLiveInRoom) {
2585
+ // if the event was already in the timeline (which will be the case if
2586
+ // opts.pendingEventOrdering==chronological), we need to update the
2587
+ // timeline map.
2588
+ for (var timelineSet of this.timelineSets) {
2589
+ timelineSet.replaceEventId(oldEventId, newEventId);
2590
+ }
2591
+ }
2592
+ } else if (newStatus == EventStatus.CANCELLED) {
2593
+ // remove it from the pending event list, or the timeline.
2594
+ if (this.pendingEventList) {
2595
+ var removedEvent = this.getPendingEvent(oldEventId);
2596
+ this.removePendingEvent(oldEventId);
2597
+ if (removedEvent !== null && removedEvent !== void 0 && removedEvent.isRedaction()) {
2598
+ this.revertRedactionLocalEcho(removedEvent);
2599
+ }
2600
+ }
2601
+ this.removeEvent(oldEventId);
2602
+ }
2603
+ this.savePendingEvents();
2604
+ this.emit(RoomEvent.LocalEchoUpdated, event, this, oldEventId, oldStatus);
2605
+ }
2606
+ revertRedactionLocalEcho(redactionEvent) {
2607
+ var redactId = redactionEvent.event.redacts;
2608
+ if (!redactId) {
2609
+ return;
2610
+ }
2611
+ var redactedEvent = this.getUnfilteredTimelineSet().findEventById(redactId);
2612
+ if (redactedEvent) {
2613
+ redactedEvent.unmarkLocallyRedacted();
2614
+ // re-render after undoing redaction
2615
+ this.emit(RoomEvent.RedactionCancelled, redactionEvent, this);
2616
+ // reapply relation now redaction failed
2617
+ if (redactedEvent.isRelation()) {
2618
+ this.aggregateNonLiveRelation(redactedEvent);
2619
+ }
2620
+ }
2621
+ }
2622
+ assertTimelineSetsAreLive() {
2623
+ for (var i = 0; i < this.timelineSets.length; i++) {
2624
+ var liveTimeline = this.timelineSets[i].getLiveTimeline();
2625
+ if (liveTimeline.getPaginationToken(EventTimeline.FORWARDS)) {
2626
+ throw new Error("live timeline " + i + " is no longer live - it has a pagination token " + "(" + liveTimeline.getPaginationToken(EventTimeline.FORWARDS) + ")");
2627
+ }
2628
+ if (liveTimeline.getNeighbouringTimeline(EventTimeline.FORWARDS)) {
2629
+ throw new Error("live timeline ".concat(i, " is no longer live - it has a neighbouring timeline"));
2630
+ }
2631
+ }
2632
+ }
2633
+
2634
+ /**
2635
+ * Add some events to this room. This can include state events, message
2636
+ * events and typing notifications. These events are treated as "live" so
2637
+ * they will go to the end of the timeline.
2638
+ *
2639
+ * @param events - A list of events to add.
2640
+ * @param addLiveEventOptions - addLiveEvent options
2641
+ * @throws If `duplicateStrategy` is not falsey, 'replace' or 'ignore'.
2642
+ */
2643
+ addLiveEvents(events, addLiveEventOptions) {
2644
+ var _this15 = this;
2645
+ return _asyncToGenerator(function* () {
2646
+ var {
2647
+ duplicateStrategy,
2648
+ fromCache,
2649
+ timelineWasEmpty = false,
2650
+ addToState
2651
+ } = addLiveEventOptions;
2652
+ if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
2653
+ throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
2654
+ }
2655
+
2656
+ // sanity check that the live timeline is still live
2657
+ _this15.assertTimelineSetsAreLive();
2658
+ var threadRoots = _this15.findThreadRoots(events);
2659
+ var eventsByThread = {};
2660
+ var options = {
2661
+ duplicateStrategy,
2662
+ fromCache,
2663
+ timelineWasEmpty,
2664
+ addToState
2665
+ };
2666
+
2667
+ // List of extra events to check for being parents of any relations encountered
2668
+ var neighbouringEvents = [...events];
2669
+ for (var event of events) {
2670
+ var _eventsByThread$threa;
2671
+ // TODO: We should have a filter to say "only add state event types X Y Z to the timeline".
2672
+ _this15.processLiveEvent(event);
2673
+ if (event.getUnsigned().transaction_id) {
2674
+ var existingEvent = _this15.txnToEvent.get(event.getUnsigned().transaction_id);
2675
+ if (existingEvent) {
2676
+ // remote echo of an event we sent earlier
2677
+ _this15.handleRemoteEcho(event, existingEvent);
2678
+ continue; // we can skip adding the event to the timeline sets, it is already there
2679
+ }
2680
+ }
2681
+ var {
2682
+ shouldLiveInRoom,
2683
+ shouldLiveInThread,
2684
+ threadId = ""
2685
+ } = _this15.eventShouldLiveIn(event, neighbouringEvents, threadRoots);
2686
+ if (!shouldLiveInThread && !shouldLiveInRoom && event.isRelation()) {
2687
+ try {
2688
+ var parentEvent = new BriijEvent(yield _this15.client.fetchRoomEvent(_this15.roomId, event.relationEventId));
2689
+ neighbouringEvents.push(parentEvent);
2690
+ if (parentEvent.threadRootId) {
2691
+ threadRoots.add(parentEvent.threadRootId);
2692
+ var unsigned = event.getUnsigned();
2693
+ unsigned[UNSIGNED_THREAD_ID_FIELD.name] = parentEvent.threadRootId;
2694
+ event.setUnsigned(unsigned);
2695
+ }
2696
+ ({
2697
+ shouldLiveInRoom,
2698
+ shouldLiveInThread,
2699
+ threadId = ""
2700
+ } = _this15.eventShouldLiveIn(event, neighbouringEvents, threadRoots));
2701
+ } catch (e) {
2702
+ logger.error("Failed to load parent event of unhandled relation", e);
2703
+ }
2704
+ }
2705
+ if (shouldLiveInThread && !eventsByThread[threadId]) {
2706
+ eventsByThread[threadId] = [];
2707
+ }
2708
+ (_eventsByThread$threa = eventsByThread[threadId]) === null || _eventsByThread$threa === void 0 || _eventsByThread$threa.push(event);
2709
+ if (shouldLiveInRoom) {
2710
+ _this15.addLiveEvent(event, options);
2711
+ } else if (!shouldLiveInThread && event.isRelation()) {
2712
+ _this15.relations.aggregateChildEvent(event);
2713
+ }
2714
+ }
2715
+ Object.entries(eventsByThread).forEach(_ref5 => {
2716
+ var [threadId, threadEvents] = _ref5;
2717
+ _this15.addThreadedEvents(threadId, threadEvents, false);
2718
+ });
2719
+ })();
2720
+ }
2721
+ partitionThreadedEvents(events) {
2722
+ // Indices to the events array, for readability
2723
+ var ROOM = 0;
2724
+ var THREAD = 1;
2725
+ var UNKNOWN_RELATION = 2;
2726
+ if (this.client.supportsThreads()) {
2727
+ var threadRoots = this.findThreadRoots(events);
2728
+ return events.reduce((memo, event) => {
2729
+ var {
2730
+ shouldLiveInRoom,
2731
+ shouldLiveInThread,
2732
+ threadId
2733
+ } = this.eventShouldLiveIn(event, events, threadRoots);
2734
+ if (shouldLiveInRoom) {
2735
+ memo[ROOM].push(event);
2736
+ }
2737
+ if (shouldLiveInThread) {
2738
+ event.setThreadId(threadId !== null && threadId !== void 0 ? threadId : "");
2739
+ memo[THREAD].push(event);
2740
+ }
2741
+ if (!shouldLiveInThread && !shouldLiveInRoom) {
2742
+ memo[UNKNOWN_RELATION].push(event);
2743
+ }
2744
+ return memo;
2745
+ }, [[], [], []]);
2746
+ } else {
2747
+ // When `threadSupport` is disabled treat all events as timelineEvents
2748
+ return [events, [], []];
2749
+ }
2750
+ }
2751
+
2752
+ /**
2753
+ * Given some events, find the IDs of all the thread roots that are referred to by them.
2754
+ */
2755
+ findThreadRoots(events) {
2756
+ var threadRoots = new Set();
2757
+ for (var event of events) {
2758
+ var threadRootId = event.threadRootId;
2759
+ if (threadRootId != undefined) {
2760
+ threadRoots.add(threadRootId);
2761
+ }
2762
+ }
2763
+ return threadRoots;
2764
+ }
2765
+
2766
+ /**
2767
+ * Add a receipt event to the room.
2768
+ * @param event - The m.receipt event.
2769
+ * @param synthetic - True if this event is implicit.
2770
+ */
2771
+ addReceipt(event) {
2772
+ var synthetic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2773
+ var content = event.getContent();
2774
+ this.roomReceipts.add(content, synthetic);
2775
+
2776
+ // TODO: delete the following code when it has been replaced by RoomReceipts
2777
+ Object.keys(content).forEach(eventId => {
2778
+ Object.keys(content[eventId]).forEach(receiptType => {
2779
+ Object.keys(content[eventId][receiptType]).forEach(userId => {
2780
+ var _receipt$thread_id, _this$unthreadedRecei, _this$unthreadedRecei2;
2781
+ var receipt = content[eventId][receiptType][userId];
2782
+ var receiptForMainTimeline = !receipt.thread_id || receipt.thread_id === MAIN_ROOM_TIMELINE;
2783
+ var receiptDestination = receiptForMainTimeline ? this : this.threads.get((_receipt$thread_id = receipt.thread_id) !== null && _receipt$thread_id !== void 0 ? _receipt$thread_id : "");
2784
+ if (receiptDestination) {
2785
+ receiptDestination.addReceiptToStructure(eventId, receiptType, userId, receipt, synthetic);
2786
+
2787
+ // If the read receipt sent for the logged in user matches
2788
+ // the last event of the live timeline, then we know for a fact
2789
+ // that the user has read that message, so we can mark the room
2790
+ // as read and not wait for the remote echo from synapse.
2791
+ //
2792
+ // This needs to be done after the initial sync as we do not want this
2793
+ // logic to run whilst the room is being initialised
2794
+ //
2795
+ // We only do this for non-synthetic receipts, because
2796
+ // our intention is to do this when the user really did
2797
+ // just read a message, not when we are e.g. receiving
2798
+ // an event during the sync. More explanation at:
2799
+ // https://github.com/matrix-org/matrix-js-sdk/issues/3684
2800
+ if (!synthetic && this.client.isInitialSyncComplete() && userId === this.client.getUserId()) {
2801
+ var lastEvent = receiptDestination.timeline[receiptDestination.timeline.length - 1];
2802
+ if (lastEvent && eventId === lastEvent.getId() && userId === lastEvent.getSender()) {
2803
+ receiptDestination.setUnread(NotificationCountType.Total, 0);
2804
+ receiptDestination.setUnread(NotificationCountType.Highlight, 0);
2805
+ }
2806
+ }
2807
+ } else {
2808
+ var _this$cachedThreadRea2;
2809
+ // The thread does not exist locally, keep the read receipt
2810
+ // in a cache locally, and re-apply the `addReceipt` logic
2811
+ // when the thread is created
2812
+ this.cachedThreadReadReceipts.set(receipt.thread_id, [...((_this$cachedThreadRea2 = this.cachedThreadReadReceipts.get(receipt.thread_id)) !== null && _this$cachedThreadRea2 !== void 0 ? _this$cachedThreadRea2 : []), {
2813
+ eventId,
2814
+ receiptType,
2815
+ userId,
2816
+ receipt,
2817
+ synthetic
2818
+ }]);
2819
+ }
2820
+ var me = this.client.getUserId();
2821
+ // Track the time of the current user's oldest threaded receipt in the room.
2822
+ if (userId === me && !receiptForMainTimeline && receipt.ts < this.oldestThreadedReceiptTs) {
2823
+ this.oldestThreadedReceiptTs = receipt.ts;
2824
+ }
2825
+
2826
+ // Track each user's unthreaded read receipt.
2827
+ if (!receipt.thread_id && receipt.ts > ((_this$unthreadedRecei = (_this$unthreadedRecei2 = this.unthreadedReceipts.get(userId)) === null || _this$unthreadedRecei2 === void 0 ? void 0 : _this$unthreadedRecei2.ts) !== null && _this$unthreadedRecei !== void 0 ? _this$unthreadedRecei : 0)) {
2828
+ this.unthreadedReceipts.set(userId, receipt);
2829
+ }
2830
+ });
2831
+ });
2832
+ });
2833
+ // End of code to delete when replaced by RoomReceipts
2834
+
2835
+ // send events after we've regenerated the structure & cache, otherwise things that
2836
+ // listened for the event would read stale data.
2837
+ this.emit(RoomEvent.Receipt, event, this);
2838
+ }
2839
+
2840
+ /**
2841
+ * Adds/handles ephemeral events such as typing notifications and read receipts.
2842
+ * @param events - A list of events to process
2843
+ */
2844
+ addEphemeralEvents(events) {
2845
+ for (var event of events) {
2846
+ if (event.getType() === EventType.Typing) {
2847
+ this.currentState.setTypingEvent(event);
2848
+ } else if (event.getType() === EventType.Receipt) {
2849
+ this.addReceipt(event);
2850
+ } // else ignore - life is too short for us to care about these events
2851
+ }
2852
+ }
2853
+
2854
+ /**
2855
+ * Removes events from this room.
2856
+ * @param eventIds - A list of eventIds to remove.
2857
+ */
2858
+ removeEvents(eventIds) {
2859
+ for (var eventId of eventIds) {
2860
+ this.removeEvent(eventId);
2861
+ }
2862
+ }
2863
+
2864
+ /**
2865
+ * Removes a single event from this room.
2866
+ *
2867
+ * @param eventId - The id of the event to remove
2868
+ *
2869
+ * @returns true if the event was removed from any of the room's timeline sets
2870
+ */
2871
+ removeEvent(eventId) {
2872
+ var removedAny = false;
2873
+ for (var timelineSet of this.timelineSets) {
2874
+ var removed = timelineSet.removeEvent(eventId);
2875
+ if (removed) {
2876
+ if (removed.isRedaction()) {
2877
+ this.revertRedactionLocalEcho(removed);
2878
+ }
2879
+ removedAny = true;
2880
+ }
2881
+ }
2882
+ return removedAny;
2883
+ }
2884
+
2885
+ /**
2886
+ * Recalculate various aspects of the room, including the room name and
2887
+ * room summary. Call this any time the room's current state is modified.
2888
+ * May fire "Room.name" if the room name is updated.
2889
+ *
2890
+ * @remarks
2891
+ * Fires {@link RoomEvent.Name}
2892
+ */
2893
+ recalculate() {
2894
+ // set fake stripped state events if this is an invite room so logic remains
2895
+ // consistent elsewhere.
2896
+ var membershipEvent = this.currentState.getStateEvents(EventType.RoomMember, this.myUserId);
2897
+ if (membershipEvent) {
2898
+ var membership = membershipEvent.getContent().membership;
2899
+ this.updateMyMembership(membership);
2900
+ if (membership === KnownMembership.Invite) {
2901
+ var strippedStateEvents = membershipEvent.getUnsigned().invite_room_state || [];
2902
+ strippedStateEvents.forEach(strippedEvent => {
2903
+ var existingEvent = this.currentState.getStateEvents(strippedEvent.type, strippedEvent.state_key);
2904
+ if (!existingEvent) {
2905
+ // set the fake stripped event instead
2906
+ this.currentState.setStateEvents([new BriijEvent({
2907
+ type: strippedEvent.type,
2908
+ state_key: strippedEvent.state_key,
2909
+ content: strippedEvent.content,
2910
+ event_id: "$fake" + Date.now(),
2911
+ room_id: this.roomId,
2912
+ sender: this.myUserId // technically a lie
2913
+ })]);
2914
+ }
2915
+ });
2916
+ }
2917
+ }
2918
+ var oldName = this.name;
2919
+ this.name = this.calculateRoomName(this.myUserId);
2920
+ this.normalizedName = normalize(this.name);
2921
+ this.summary = new RoomSummary(this.roomId, {
2922
+ title: this.name
2923
+ });
2924
+ if (oldName !== this.name) {
2925
+ this.emit(RoomEvent.Name, this);
2926
+ }
2927
+ }
2928
+
2929
+ /**
2930
+ * Update the room-tag event for the room. The previous one is overwritten.
2931
+ * @param event - the m.tag event
2932
+ */
2933
+ addTags(event) {
2934
+ // event content looks like:
2935
+ // content: {
2936
+ // tags: {
2937
+ // $tagName: { $metadata: $value },
2938
+ // $tagName: { $metadata: $value },
2939
+ // }
2940
+ // }
2941
+
2942
+ // XXX: do we need to deep copy here?
2943
+ this.tags = event.getContent().tags || {};
2944
+
2945
+ // XXX: we could do a deep-comparison to see if the tags have really
2946
+ // changed - but do we want to bother?
2947
+ this.emit(RoomEvent.Tags, event, this);
2948
+ }
2949
+
2950
+ /**
2951
+ * Update the account_data events for this room, overwriting events of the same type.
2952
+ * @param events - an array of account_data events to add
2953
+ */
2954
+ addAccountData(events) {
2955
+ for (var event of events) {
2956
+ if (event.getType() === "m.tag") {
2957
+ this.addTags(event);
2958
+ }
2959
+ var eventType = event.getType();
2960
+ var lastEvent = this.accountData.get(eventType);
2961
+ this.accountData.set(eventType, event);
2962
+ this.emit(RoomEvent.AccountData, event, this, lastEvent);
2963
+ }
2964
+ }
2965
+
2966
+ /**
2967
+ * Access account_data event of given event type for this room
2968
+ * @param type - the type of account_data event to be accessed
2969
+ * @returns the account_data event in question
2970
+ */
2971
+ getAccountData(type) {
2972
+ return this.accountData.get(type);
2973
+ }
2974
+
2975
+ /**
2976
+ * Get an iterator of currently active sticky events.
2977
+ */
2978
+ // eslint-disable-next-line
2979
+ _unstable_getStickyEvents() {
2980
+ return this.stickyEvents.getStickyEvents();
2981
+ }
2982
+
2983
+ /**
2984
+ * Get a sticky event that match the given `type`, `sender`, and `stickyKey`
2985
+ * @param type The event `type`.
2986
+ * @param sender The sender of the sticky event.
2987
+ * @param stickyKey The sticky key used by the event.
2988
+ * @returns A matching active sticky event, or undefined.
2989
+ */
2990
+ // eslint-disable-next-line
2991
+ _unstable_getKeyedStickyEvent(sender, type, stickyKey) {
2992
+ return this.stickyEvents.getKeyedStickyEvent(sender, type, stickyKey);
2993
+ }
2994
+
2995
+ /**
2996
+ * Get active sticky events without a sticky key that match the given `type` and `sender`.
2997
+ * @param type The event `type`.
2998
+ * @param sender The sender of the sticky event.
2999
+ * @returns An array of matching sticky events.
3000
+ */
3001
+ // eslint-disable-next-line
3002
+ _unstable_getUnkeyedStickyEvent(sender, type) {
3003
+ return this.stickyEvents.getUnkeyedStickyEvent(sender, type);
3004
+ }
3005
+
3006
+ /**
3007
+ * Add a series of sticky events, emitting `RoomEvent.StickyEvents` if any
3008
+ * changes were made.
3009
+ * @param events A set of new sticky events.
3010
+ * @internal
3011
+ */
3012
+ // eslint-disable-next-line
3013
+ _unstable_addStickyEvents(events) {
3014
+ return this.stickyEvents.addStickyEvents(events);
3015
+ }
3016
+
3017
+ /**
3018
+ * Returns whether the syncing user has permission to send a message in the room
3019
+ * @returns true if the user should be permitted to send
3020
+ * message events into the room.
3021
+ */
3022
+ maySendMessage() {
3023
+ return this.getMyMembership() === KnownMembership.Join && (this.hasEncryptionStateEvent() ? this.currentState.maySendEvent(EventType.RoomMessageEncrypted, this.myUserId) : this.currentState.maySendEvent(EventType.RoomMessage, this.myUserId));
3024
+ }
3025
+
3026
+ /**
3027
+ * Returns whether the given user has permissions to issue an invite for this room.
3028
+ * @param userId - the ID of the Matrix user to check permissions for
3029
+ * @returns true if the user should be permitted to issue invites for this room.
3030
+ */
3031
+ canInvite(userId) {
3032
+ var canInvite = this.getMyMembership() === KnownMembership.Join;
3033
+ var powerLevelsEvent = this.currentState.getStateEvents(EventType.RoomPowerLevels, "");
3034
+ var powerLevels = powerLevelsEvent && powerLevelsEvent.getContent();
3035
+ var me = this.getMember(userId);
3036
+ if (powerLevels && me && powerLevels.invite > me.powerLevel) {
3037
+ canInvite = false;
3038
+ }
3039
+ return canInvite;
3040
+ }
3041
+
3042
+ /**
3043
+ * Returns the join rule based on the m.room.join_rule state event, defaulting to `invite`.
3044
+ * @returns the join_rule applied to this room
3045
+ */
3046
+ getJoinRule() {
3047
+ return this.currentState.getJoinRule();
3048
+ }
3049
+
3050
+ /**
3051
+ * Returns the history visibility based on the m.room.history_visibility state event, defaulting to `shared`.
3052
+ * @returns the history_visibility applied to this room
3053
+ */
3054
+ getHistoryVisibility() {
3055
+ return this.currentState.getHistoryVisibility();
3056
+ }
3057
+
3058
+ /**
3059
+ * Returns the history visibility based on the m.room.history_visibility state event, defaulting to `shared`.
3060
+ * @returns the history_visibility applied to this room
3061
+ */
3062
+ getGuestAccess() {
3063
+ return this.currentState.getGuestAccess();
3064
+ }
3065
+
3066
+ /**
3067
+ * Returns the type of the room from the `m.room.create` event content or undefined if none is set
3068
+ * @returns the type of the room.
3069
+ */
3070
+ getType() {
3071
+ var createEvent = this.currentState.getStateEvents(EventType.RoomCreate, "");
3072
+ if (!createEvent) {
3073
+ if (!this.getTypeWarning) {
3074
+ logger.warn("[getType] Room " + this.roomId + " does not have an m.room.create event");
3075
+ this.getTypeWarning = true;
3076
+ }
3077
+ return undefined;
3078
+ }
3079
+ return createEvent.getContent()[RoomCreateTypeField];
3080
+ }
3081
+
3082
+ /**
3083
+ * Returns whether the room is a space-room as defined by MSC1772.
3084
+ * @returns true if the room's type is RoomType.Space
3085
+ */
3086
+ isSpaceRoom() {
3087
+ return this.getType() === RoomType.Space;
3088
+ }
3089
+
3090
+ /**
3091
+ * Returns whether the room is a call-room as defined by MSC3417.
3092
+ * @returns true if the room's type is RoomType.UnstableCall
3093
+ */
3094
+ isCallRoom() {
3095
+ return this.getType() === RoomType.UnstableCall;
3096
+ }
3097
+
3098
+ /**
3099
+ * Returns whether the room is a video room.
3100
+ * @returns true if the room's type is RoomType.ElementVideo
3101
+ */
3102
+ isElementVideoRoom() {
3103
+ return this.getType() === RoomType.ElementVideo;
3104
+ }
3105
+
3106
+ /**
3107
+ * Find the predecessor of this room.
3108
+ *
3109
+ * @param msc3946ProcessDynamicPredecessor - if true, look for an
3110
+ * m.room.predecessor state event and use it if found (MSC3946).
3111
+ * @returns null if this room has no predecessor. Otherwise, returns
3112
+ * the roomId, last eventId and viaServers of the predecessor room.
3113
+ *
3114
+ * If msc3946ProcessDynamicPredecessor is true, use m.predecessor events
3115
+ * as well as m.room.create events to find predecessors.
3116
+ *
3117
+ * Note: if an m.predecessor event is used, eventId may be undefined
3118
+ * since last_known_event_id is optional.
3119
+ *
3120
+ * Note: viaServers may be undefined, and will definitely be undefined if
3121
+ * this predecessor comes from a RoomCreate event (rather than a
3122
+ * RoomPredecessor, which has the optional via_servers property).
3123
+ */
3124
+ findPredecessor() {
3125
+ var msc3946ProcessDynamicPredecessor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3126
+ var currentState = this.getLiveTimeline().getState(EventTimeline.FORWARDS);
3127
+ if (!currentState) {
3128
+ return null;
3129
+ }
3130
+ return currentState.findPredecessor(msc3946ProcessDynamicPredecessor);
3131
+ }
3132
+ roomNameGenerator(state) {
3133
+ if (this.client.roomNameGenerator) {
3134
+ var name = this.client.roomNameGenerator(this.roomId, state);
3135
+ if (name !== null) {
3136
+ return name;
3137
+ }
3138
+ }
3139
+ switch (state.type) {
3140
+ case RoomNameType.Actual:
3141
+ return state.name;
3142
+ case RoomNameType.Generated:
3143
+ switch (state.subtype) {
3144
+ case "Inviting":
3145
+ return "Inviting ".concat(memberNamesToRoomName(state.names, state.count));
3146
+ default:
3147
+ return memberNamesToRoomName(state.names, state.count);
3148
+ }
3149
+ case RoomNameType.EmptyRoom:
3150
+ if (state.oldName) {
3151
+ return "Empty room (was ".concat(state.oldName, ")");
3152
+ } else {
3153
+ return "Empty room";
3154
+ }
3155
+ }
3156
+ }
3157
+
3158
+ /**
3159
+ * This is an internal method. Calculates the name of the room from the current
3160
+ * room state.
3161
+ * @param userId - The client's user ID. Used to filter room members
3162
+ * correctly.
3163
+ * @param ignoreRoomNameEvent - Return the implicit room name that we'd see if there
3164
+ * was no m.room.name event.
3165
+ * @returns The calculated room name.
3166
+ */
3167
+ calculateRoomName(userId) {
3168
+ var ignoreRoomNameEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3169
+ if (!ignoreRoomNameEvent) {
3170
+ var _this$currentState$ge4;
3171
+ var name = (_this$currentState$ge4 = this.currentState.getStateEvents(EventType.RoomName, "")) === null || _this$currentState$ge4 === void 0 ? void 0 : _this$currentState$ge4.getContent().name;
3172
+ if (name && typeof name === "string") {
3173
+ return this.roomNameGenerator({
3174
+ type: RoomNameType.Actual,
3175
+ name
3176
+ });
3177
+ }
3178
+ }
3179
+ var alias = this.getCanonicalAlias();
3180
+ if (alias) {
3181
+ return this.roomNameGenerator({
3182
+ type: RoomNameType.Actual,
3183
+ name: alias
3184
+ });
3185
+ }
3186
+ var joinedMemberCount = this.currentState.getJoinedMemberCount();
3187
+ var invitedMemberCount = this.currentState.getInvitedMemberCount();
3188
+ // -1 because these numbers include the syncing user
3189
+ var inviteJoinCount = joinedMemberCount + invitedMemberCount - 1;
3190
+
3191
+ // get service members (e.g. helper bots) for exclusion
3192
+ var excludedUserIds = this.getFunctionalMembers();
3193
+
3194
+ // get members from heroes that are NOT ourselves
3195
+ var otherNames = [];
3196
+ if (this.heroes) {
3197
+ // if we have heroes, use those as the names
3198
+ this.heroes.forEach(hero => {
3199
+ // filter service members
3200
+ if (excludedUserIds.includes(hero.userId)) {
3201
+ inviteJoinCount--;
3202
+ return;
3203
+ }
3204
+ // If the hero has a display name, use that.
3205
+ // Otherwise, look their user ID up in the membership and use
3206
+ // the name from there, or the user ID as a last resort.
3207
+ if (hero.displayName) {
3208
+ otherNames.push(hero.displayName);
3209
+ } else {
3210
+ var member = this.getMember(hero.userId);
3211
+ otherNames.push(member ? member.name : hero.userId);
3212
+ }
3213
+ });
3214
+ } else {
3215
+ var otherMembers = this.currentState.getMembers().filter(m => {
3216
+ return m.userId !== userId && (m.membership === KnownMembership.Invite || m.membership === KnownMembership.Join);
3217
+ });
3218
+ otherMembers = otherMembers.filter(_ref6 => {
3219
+ var {
3220
+ userId
3221
+ } = _ref6;
3222
+ // filter service members
3223
+ if (excludedUserIds.includes(userId)) {
3224
+ inviteJoinCount--;
3225
+ return false;
3226
+ }
3227
+ return true;
3228
+ });
3229
+ // make sure members have stable order
3230
+ var collator = new Intl.Collator();
3231
+ otherMembers.sort((a, b) => collator.compare(a.userId, b.userId));
3232
+ // only 5 first members, immitate summaryHeroes
3233
+ otherMembers = otherMembers.slice(0, 5);
3234
+ otherNames = otherMembers.map(m => m.name);
3235
+ }
3236
+ if (inviteJoinCount) {
3237
+ return this.roomNameGenerator({
3238
+ type: RoomNameType.Generated,
3239
+ names: otherNames,
3240
+ count: inviteJoinCount
3241
+ });
3242
+ }
3243
+ var myMembership = this.getMyMembership();
3244
+ // if I have created a room and invited people through
3245
+ // 3rd party invites
3246
+ if (myMembership == KnownMembership.Join) {
3247
+ var thirdPartyInvites = this.currentState.getStateEvents(EventType.RoomThirdPartyInvite);
3248
+ if (thirdPartyInvites !== null && thirdPartyInvites !== void 0 && thirdPartyInvites.length) {
3249
+ var thirdPartyNames = thirdPartyInvites.map(i => {
3250
+ return i.getContent().display_name;
3251
+ });
3252
+ return this.roomNameGenerator({
3253
+ type: RoomNameType.Generated,
3254
+ subtype: "Inviting",
3255
+ names: thirdPartyNames,
3256
+ count: thirdPartyNames.length + 1
3257
+ });
3258
+ }
3259
+ }
3260
+
3261
+ // let's try to figure out who was here before
3262
+ var leftNames = otherNames;
3263
+ // if we didn't have heroes, try finding them in the room state
3264
+ if (!leftNames.length) {
3265
+ leftNames = this.currentState.getMembers().filter(m => {
3266
+ return m.userId !== userId && m.membership !== KnownMembership.Invite && m.membership !== KnownMembership.Join;
3267
+ }).map(m => m.name);
3268
+ }
3269
+ var oldName;
3270
+ if (leftNames.length) {
3271
+ oldName = this.roomNameGenerator({
3272
+ type: RoomNameType.Generated,
3273
+ names: leftNames,
3274
+ count: leftNames.length + 1
3275
+ });
3276
+ }
3277
+ return this.roomNameGenerator({
3278
+ type: RoomNameType.EmptyRoom,
3279
+ oldName
3280
+ });
3281
+ }
3282
+
3283
+ /**
3284
+ * When we receive a new visibility change event:
3285
+ *
3286
+ * - store this visibility change alongside the timeline, in case we
3287
+ * later need to apply it to an event that we haven't received yet;
3288
+ * - if we have already received the event whose visibility has changed,
3289
+ * patch it to reflect the visibility change and inform listeners.
3290
+ */
3291
+ applyNewVisibilityEvent(event) {
3292
+ var visibilityChange = event.asVisibilityChange();
3293
+ if (!visibilityChange) {
3294
+ // The event is ill-formed.
3295
+ return;
3296
+ }
3297
+
3298
+ // Ignore visibility change events that are not emitted by moderators.
3299
+ var userId = event.getSender();
3300
+ if (!userId) {
3301
+ return;
3302
+ }
3303
+ var isPowerSufficient = EVENT_VISIBILITY_CHANGE_TYPE.name && this.currentState.maySendStateEvent(EVENT_VISIBILITY_CHANGE_TYPE.name, userId) || EVENT_VISIBILITY_CHANGE_TYPE.altName && this.currentState.maySendStateEvent(EVENT_VISIBILITY_CHANGE_TYPE.altName, userId);
3304
+ if (!isPowerSufficient) {
3305
+ // Powerlevel is insufficient.
3306
+ return;
3307
+ }
3308
+
3309
+ // Record this change in visibility.
3310
+ // If the event is not in our timeline and we only receive it later,
3311
+ // we may need to apply the visibility change at a later date.
3312
+
3313
+ var visibilityEventsOnOriginalEvent = this.visibilityEvents.get(visibilityChange.eventId);
3314
+ if (visibilityEventsOnOriginalEvent) {
3315
+ // It would be tempting to simply erase the latest visibility change
3316
+ // but we need to record all of the changes in case the latest change
3317
+ // is ever redacted.
3318
+ //
3319
+ // In practice, linear scans through `visibilityEvents` should be fast.
3320
+ // However, to protect against a potential DoS attack, we limit the
3321
+ // number of iterations in this loop.
3322
+ var index = visibilityEventsOnOriginalEvent.length - 1;
3323
+ var min = Math.max(0, visibilityEventsOnOriginalEvent.length - MAX_NUMBER_OF_VISIBILITY_EVENTS_TO_SCAN_THROUGH);
3324
+ for (; index >= min; --index) {
3325
+ var target = visibilityEventsOnOriginalEvent[index];
3326
+ if (target.getTs() < event.getTs()) {
3327
+ break;
3328
+ }
3329
+ }
3330
+ if (index === -1) {
3331
+ visibilityEventsOnOriginalEvent.unshift(event);
3332
+ } else {
3333
+ visibilityEventsOnOriginalEvent.splice(index + 1, 0, event);
3334
+ }
3335
+ } else {
3336
+ this.visibilityEvents.set(visibilityChange.eventId, [event]);
3337
+ }
3338
+
3339
+ // Finally, let's check if the event is already in our timeline.
3340
+ // If so, we need to patch it and inform listeners.
3341
+
3342
+ var originalEvent = this.findEventById(visibilityChange.eventId);
3343
+ if (!originalEvent) {
3344
+ return;
3345
+ }
3346
+ originalEvent.applyVisibilityEvent(visibilityChange);
3347
+ }
3348
+ redactVisibilityChangeEvent(event) {
3349
+ // Sanity checks.
3350
+ if (!event.isVisibilityEvent) {
3351
+ throw new Error("expected a visibility change event");
3352
+ }
3353
+ var relation = event.getRelation();
3354
+ var originalEventId = relation === null || relation === void 0 ? void 0 : relation.event_id;
3355
+ var visibilityEventsOnOriginalEvent = this.visibilityEvents.get(originalEventId);
3356
+ if (!visibilityEventsOnOriginalEvent) {
3357
+ // No visibility changes on the original event.
3358
+ // In particular, this change event was not recorded,
3359
+ // most likely because it was ill-formed.
3360
+ return;
3361
+ }
3362
+ var index = visibilityEventsOnOriginalEvent.findIndex(change => change.getId() === event.getId());
3363
+ if (index === -1) {
3364
+ // This change event was not recorded, most likely because
3365
+ // it was ill-formed.
3366
+ return;
3367
+ }
3368
+ // Remove visibility change.
3369
+ visibilityEventsOnOriginalEvent.splice(index, 1);
3370
+
3371
+ // If we removed the latest visibility change event, propagate changes.
3372
+ if (index === visibilityEventsOnOriginalEvent.length) {
3373
+ var originalEvent = this.findEventById(originalEventId);
3374
+ if (!originalEvent) {
3375
+ return;
3376
+ }
3377
+ if (index === 0) {
3378
+ // We have just removed the only visibility change event.
3379
+ this.visibilityEvents.delete(originalEventId);
3380
+ originalEvent.applyVisibilityEvent();
3381
+ } else {
3382
+ var newEvent = visibilityEventsOnOriginalEvent[visibilityEventsOnOriginalEvent.length - 1];
3383
+ var newVisibility = newEvent.asVisibilityChange();
3384
+ if (!newVisibility) {
3385
+ // Event is ill-formed.
3386
+ // This breaks our invariant.
3387
+ throw new Error("at this stage, visibility changes should be well-formed");
3388
+ }
3389
+ originalEvent.applyVisibilityEvent(newVisibility);
3390
+ }
3391
+ }
3392
+ }
3393
+
3394
+ /**
3395
+ * When we receive an event whose visibility has been altered by
3396
+ * a (more recent) visibility change event, patch the event in
3397
+ * place so that clients now not to display it.
3398
+ *
3399
+ * @param event - Any matrix event. If this event has at least one a
3400
+ * pending visibility change event, apply the latest visibility
3401
+ * change event.
3402
+ */
3403
+ applyPendingVisibilityEvents(event) {
3404
+ var visibilityEvents = this.visibilityEvents.get(event.getId());
3405
+ if (!visibilityEvents || visibilityEvents.length == 0) {
3406
+ // No pending visibility change in store.
3407
+ return;
3408
+ }
3409
+ var visibilityEvent = visibilityEvents[visibilityEvents.length - 1];
3410
+ var visibilityChange = visibilityEvent.asVisibilityChange();
3411
+ if (!visibilityChange) {
3412
+ return;
3413
+ }
3414
+ if (visibilityChange.visible) {
3415
+ // Events are visible by default, no need to apply a visibility change.
3416
+ // Note that we need to keep the visibility changes in `visibilityEvents`,
3417
+ // in case we later fetch an older visibility change event that is superseded
3418
+ // by `visibilityChange`.
3419
+ }
3420
+ if (visibilityEvent.getTs() < event.getTs()) {
3421
+ // Something is wrong, the visibility change cannot happen before the
3422
+ // event. Presumably an ill-formed event.
3423
+ return;
3424
+ }
3425
+ event.applyVisibilityEvent(visibilityChange);
3426
+ }
3427
+
3428
+ /**
3429
+ * Find when a client has gained thread capabilities by inspecting the oldest
3430
+ * threaded receipt
3431
+ * @returns the timestamp of the oldest threaded receipt
3432
+ */
3433
+ getOldestThreadedReceiptTs() {
3434
+ return this.oldestThreadedReceiptTs;
3435
+ }
3436
+
3437
+ /**
3438
+ * Determines if the given user has read a particular event ID with the known
3439
+ * history of the room. This is not a definitive check as it relies only on
3440
+ * what is available to the room at the time of execution.
3441
+ *
3442
+ * @param userId - The user ID to check the read state of.
3443
+ * @param eventId - The event ID to check if the user read.
3444
+ * @returns true if the user has read the event, false otherwise.
3445
+ */
3446
+ hasUserReadEvent(userId, eventId) {
3447
+ return this.roomReceipts.hasUserReadEvent(userId, eventId);
3448
+ }
3449
+
3450
+ /**
3451
+ * Returns the most recent unthreaded receipt for a given user
3452
+ * @param userId - the MxID of the User
3453
+ * @returns an unthreaded Receipt. Can be undefined if receipts have been disabled
3454
+ * or a user chooses to use private read receipts (or we have simply not received
3455
+ * a receipt from this user yet).
3456
+ */
3457
+ getLastUnthreadedReceiptFor(userId) {
3458
+ return this.unthreadedReceipts.get(userId);
3459
+ }
3460
+
3461
+ /**
3462
+ * This issue should also be addressed on synapse's side and is tracked as part
3463
+ * of https://github.com/matrix-org/synapse/issues/14837
3464
+ *
3465
+ *
3466
+ * We consider a room fully read if the current user has sent
3467
+ * the last event in the live timeline of that context and if the read receipt
3468
+ * we have on record matches.
3469
+ * This also detects all unread threads and applies the same logic to those
3470
+ * contexts
3471
+ */
3472
+ fixupNotifications(userId) {
3473
+ super.fixupNotifications(userId);
3474
+ var unreadThreads = this.getThreads().filter(thread => this.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Total) > 0);
3475
+ for (var thread of unreadThreads) {
3476
+ thread.fixupNotifications(userId);
3477
+ }
3478
+ }
3479
+
3480
+ /**
3481
+ * Determine the order of two events in this room.
3482
+ *
3483
+ * In principle this should use the same order as the server, but in practice
3484
+ * this is difficult for events that were not received over the Sync API. See
3485
+ * MSC4033 for details.
3486
+ *
3487
+ * This implementation leans on the order of events within their timelines, and
3488
+ * falls back to comparing event timestamps when they are in different
3489
+ * timelines.
3490
+ *
3491
+ * See https://github.com/matrix-org/matrix-js-sdk/issues/3325 for where we are
3492
+ * tracking the work to fix this.
3493
+ *
3494
+ * @param leftEventId - the id of the first event
3495
+ * @param rightEventId - the id of the second event
3496
+ * @returns -1 if left \< right, 1 if left \> right, 0 if left == right, null if
3497
+ * we can't tell (because we can't find the events).
3498
+ */
3499
+ compareEventOrdering(leftEventId, rightEventId) {
3500
+ return compareEventOrdering(this, leftEventId, rightEventId);
3501
+ }
3502
+
3503
+ /**
3504
+ * Return true if this room has an `m.room.encryption` state event.
3505
+ *
3506
+ * If this returns `true`, events sent to this room should be encrypted (and `BriijClient.sendEvent` and friends
3507
+ * will encrypt outgoing events).
3508
+ */
3509
+ hasEncryptionStateEvent() {
3510
+ var _this$getLiveTimeline;
3511
+ return Boolean((_this$getLiveTimeline = this.getLiveTimeline().getState(EventTimeline.FORWARDS)) === null || _this$getLiveTimeline === void 0 ? void 0 : _this$getLiveTimeline.getStateEvents(EventType.RoomEncryption, ""));
3512
+ }
3513
+ }
3514
+
3515
+ // a map from current event status to a list of allowed next statuses
3516
+ var ALLOWED_TRANSITIONS = {
3517
+ [EventStatus.ENCRYPTING]: [EventStatus.SENDING, EventStatus.NOT_SENT, EventStatus.CANCELLED],
3518
+ [EventStatus.SENDING]: [EventStatus.ENCRYPTING, EventStatus.QUEUED, EventStatus.NOT_SENT, EventStatus.SENT],
3519
+ [EventStatus.QUEUED]: [EventStatus.SENDING, EventStatus.NOT_SENT, EventStatus.CANCELLED],
3520
+ [EventStatus.SENT]: [],
3521
+ [EventStatus.NOT_SENT]: [EventStatus.SENDING, EventStatus.QUEUED, EventStatus.CANCELLED],
3522
+ [EventStatus.CANCELLED]: []
3523
+ };
3524
+ export var RoomNameType = /*#__PURE__*/function (RoomNameType) {
3525
+ RoomNameType[RoomNameType["EmptyRoom"] = 0] = "EmptyRoom";
3526
+ RoomNameType[RoomNameType["Generated"] = 1] = "Generated";
3527
+ RoomNameType[RoomNameType["Actual"] = 2] = "Actual";
3528
+ return RoomNameType;
3529
+ }({});
3530
+ // Can be overriden by IBriijClientCreateOpts::memberNamesToRoomNameFn
3531
+ function memberNamesToRoomName(names, count) {
3532
+ var countWithoutMe = count - 1;
3533
+ if (!names.length) {
3534
+ return "Empty room";
3535
+ } else if (names.length === 1 && countWithoutMe <= 1) {
3536
+ return names[0];
3537
+ } else if (names.length === 2 && countWithoutMe <= 2) {
3538
+ return "".concat(names[0], " and ").concat(names[1]);
3539
+ } else {
3540
+ var plural = countWithoutMe > 1;
3541
+ if (plural) {
3542
+ return "".concat(names[0], " and ").concat(countWithoutMe, " others");
3543
+ } else {
3544
+ return "".concat(names[0], " and 1 other");
3545
+ }
3546
+ }
3547
+ }
3548
+ //# sourceMappingURL=room.js.map