matrix-js-sdk 16.0.0 → 16.0.2-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/browser-matrix.js +1060 -1117
  3. package/dist/browser-matrix.js.map +31 -29
  4. package/dist/browser-matrix.min.js +5 -5
  5. package/dist/browser-matrix.min.js.map +1 -1
  6. package/git-revision.txt +1 -1
  7. package/lib/@types/beacon.d.ts +108 -0
  8. package/lib/@types/beacon.d.ts.map +1 -0
  9. package/lib/@types/beacon.js +79 -0
  10. package/lib/@types/event.d.ts +4 -9
  11. package/lib/@types/event.d.ts.map +1 -1
  12. package/lib/@types/event.js +3 -1
  13. package/lib/@types/location.d.ts +50 -15
  14. package/lib/@types/location.d.ts.map +1 -1
  15. package/lib/@types/location.js +12 -31
  16. package/lib/NamespacedValue.d.ts +5 -0
  17. package/lib/NamespacedValue.d.ts.map +1 -1
  18. package/lib/NamespacedValue.js +28 -2
  19. package/lib/client.d.ts +34 -249
  20. package/lib/client.d.ts.map +1 -1
  21. package/lib/client.js +147 -562
  22. package/lib/content-helpers.d.ts +26 -4
  23. package/lib/content-helpers.d.ts.map +1 -1
  24. package/lib/content-helpers.js +126 -31
  25. package/lib/crypto/algorithms/megolm.js +2 -1
  26. package/lib/crypto/index.d.ts.map +1 -1
  27. package/lib/crypto/index.js +2 -2
  28. package/lib/crypto/store/localStorage-crypto-store.js +1 -1
  29. package/lib/crypto/verification/request/VerificationRequest.d.ts +1 -1
  30. package/lib/crypto/verification/request/VerificationRequest.d.ts.map +1 -1
  31. package/lib/crypto/verification/request/VerificationRequest.js +1 -0
  32. package/lib/event-mapper.d.ts.map +1 -1
  33. package/lib/event-mapper.js +20 -15
  34. package/lib/filter-component.d.ts +4 -3
  35. package/lib/filter-component.d.ts.map +1 -1
  36. package/lib/filter-component.js +15 -17
  37. package/lib/filter.d.ts +4 -5
  38. package/lib/filter.d.ts.map +1 -1
  39. package/lib/filter.js +2 -9
  40. package/lib/http-api.d.ts +0 -1
  41. package/lib/http-api.d.ts.map +1 -1
  42. package/lib/http-api.js +0 -1
  43. package/lib/matrix.d.ts +1 -1
  44. package/lib/matrix.d.ts.map +1 -1
  45. package/lib/matrix.js +12 -12
  46. package/lib/models/beacon.d.ts +40 -0
  47. package/lib/models/beacon.d.ts.map +1 -0
  48. package/lib/models/beacon.js +146 -0
  49. package/lib/models/event-context.d.ts +1 -0
  50. package/lib/models/event-context.d.ts.map +1 -1
  51. package/lib/models/event-context.js +1 -0
  52. package/lib/models/event.d.ts +14 -5
  53. package/lib/models/event.d.ts.map +1 -1
  54. package/lib/models/event.js +3 -2
  55. package/lib/models/room-state.d.ts +24 -2
  56. package/lib/models/room-state.d.ts.map +1 -1
  57. package/lib/models/room-state.js +67 -1
  58. package/lib/models/room.d.ts +35 -8
  59. package/lib/models/room.d.ts.map +1 -1
  60. package/lib/models/room.js +316 -100
  61. package/lib/models/search-result.d.ts.map +1 -1
  62. package/lib/models/search-result.js +9 -5
  63. package/lib/models/thread.d.ts +10 -1
  64. package/lib/models/thread.d.ts.map +1 -1
  65. package/lib/models/thread.js +67 -57
  66. package/lib/store/index.d.ts +1 -22
  67. package/lib/store/index.d.ts.map +1 -1
  68. package/lib/store/indexeddb-local-backend.d.ts +0 -1
  69. package/lib/store/indexeddb-local-backend.d.ts.map +1 -1
  70. package/lib/store/indexeddb-local-backend.js +3 -6
  71. package/lib/store/memory.d.ts +0 -21
  72. package/lib/store/memory.d.ts.map +1 -1
  73. package/lib/store/memory.js +0 -33
  74. package/lib/store/stub.d.ts +0 -20
  75. package/lib/store/stub.d.ts.map +1 -1
  76. package/lib/store/stub.js +0 -29
  77. package/lib/sync-accumulator.d.ts +0 -14
  78. package/lib/sync-accumulator.d.ts.map +1 -1
  79. package/lib/sync-accumulator.js +0 -45
  80. package/lib/sync.d.ts +1 -12
  81. package/lib/sync.d.ts.map +1 -1
  82. package/lib/sync.js +27 -113
  83. package/lib/timeline-window.d.ts +1 -1
  84. package/lib/timeline-window.d.ts.map +1 -1
  85. package/lib/timeline-window.js +8 -16
  86. package/package.json +1 -1
  87. package/src/@types/beacon.ts +147 -0
  88. package/src/@types/event.ts +3 -8
  89. package/src/@types/location.ts +47 -21
  90. package/src/NamespacedValue.ts +16 -0
  91. package/src/client.ts +163 -563
  92. package/src/content-helpers.ts +144 -20
  93. package/src/crypto/algorithms/megolm.ts +1 -0
  94. package/src/crypto/index.ts +3 -2
  95. package/src/crypto/store/localStorage-crypto-store.ts +1 -1
  96. package/src/crypto/verification/request/VerificationRequest.ts +1 -1
  97. package/src/event-mapper.ts +16 -2
  98. package/src/filter-component.ts +25 -20
  99. package/src/filter.ts +6 -13
  100. package/src/http-api.ts +1 -1
  101. package/src/matrix.ts +1 -1
  102. package/src/models/beacon.ts +134 -0
  103. package/src/models/event-context.ts +1 -1
  104. package/src/models/event.ts +18 -10
  105. package/src/models/room-state.ts +75 -1
  106. package/src/models/room.ts +363 -99
  107. package/src/models/search-result.ts +9 -4
  108. package/src/models/thread.ts +71 -48
  109. package/src/store/index.ts +1 -25
  110. package/src/store/indexeddb-local-backend.ts +1 -5
  111. package/src/store/memory.ts +0 -30
  112. package/src/store/stub.ts +0 -27
  113. package/src/sync-accumulator.ts +0 -50
  114. package/src/sync.ts +31 -113
  115. package/src/timeline-window.ts +11 -20
  116. package/lib/models/group.js +0 -108
  117. package/src/models/group.js +0 -100
@@ -16951,6 +16951,75 @@ var RuleId;
16951
16951
  },{}],77:[function(require,module,exports){
16952
16952
  "use strict";
16953
16953
  /*
16954
+ Copyright 2022 The Matrix.org Foundation C.I.C.
16955
+
16956
+ Licensed under the Apache License, Version 2.0 (the "License");
16957
+ you may not use this file except in compliance with the License.
16958
+ You may obtain a copy of the License at
16959
+
16960
+ http://www.apache.org/licenses/LICENSE-2.0
16961
+
16962
+ Unless required by applicable law or agreed to in writing, software
16963
+ distributed under the License is distributed on an "AS IS" BASIS,
16964
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16965
+ See the License for the specific language governing permissions and
16966
+ limitations under the License.
16967
+ */
16968
+ Object.defineProperty(exports, "__esModule", { value: true });
16969
+ exports.M_BEACON = exports.M_BEACON_INFO = exports.M_BEACON_INFO_VARIABLE = void 0;
16970
+ const NamespacedValue_1 = require("../NamespacedValue");
16971
+ /**
16972
+ * Beacon info and beacon event types as described in MSC3489
16973
+ * https://github.com/matrix-org/matrix-spec-proposals/pull/3489
16974
+ */
16975
+ /**
16976
+ * Beacon info events are state events.
16977
+ * We have two requirements for these events:
16978
+ * 1. they can only be written by their owner
16979
+ * 2. a user can have an arbitrary number of beacon_info events
16980
+ *
16981
+ * 1. is achieved by setting the state_key to the owners mxid.
16982
+ * Event keys in room state are a combination of `type` + `state_key`.
16983
+ * To achieve an arbitrary number of only owner-writable state events
16984
+ * we introduce a variable suffix to the event type
16985
+ *
16986
+ * Eg
16987
+ * {
16988
+ * "type": "m.beacon_info.@matthew:matrix.org.1",
16989
+ * "state_key": "@matthew:matrix.org",
16990
+ * "content": {
16991
+ * "m.beacon_info": {
16992
+ * "description": "The Matthew Tracker",
16993
+ * "timeout": 86400000,
16994
+ * },
16995
+ * // more content as described below
16996
+ * }
16997
+ * },
16998
+ * {
16999
+ * "type": "m.beacon_info.@matthew:matrix.org.2",
17000
+ * "state_key": "@matthew:matrix.org",
17001
+ * "content": {
17002
+ * "m.beacon_info": {
17003
+ * "description": "Another different Matthew tracker",
17004
+ * "timeout": 400000,
17005
+ * },
17006
+ * // more content as described below
17007
+ * }
17008
+ * }
17009
+ */
17010
+ /**
17011
+ * Variable event type for m.beacon_info
17012
+ */
17013
+ exports.M_BEACON_INFO_VARIABLE = new NamespacedValue_1.UnstableValue("m.beacon_info.*", "org.matrix.msc3489.beacon_info.*");
17014
+ /**
17015
+ * Non-variable type for m.beacon_info event content
17016
+ */
17017
+ exports.M_BEACON_INFO = new NamespacedValue_1.UnstableValue("m.beacon_info", "org.matrix.msc3489.beacon_info");
17018
+ exports.M_BEACON = new NamespacedValue_1.UnstableValue("m.beacon", "org.matrix.msc3489.beacon");
17019
+
17020
+ },{"../NamespacedValue":84}],78:[function(require,module,exports){
17021
+ "use strict";
17022
+ /*
16954
17023
  Copyright 2020 The Matrix.org Foundation C.I.C.
16955
17024
 
16956
17025
  Licensed under the Apache License, Version 2.0 (the "License");
@@ -17040,14 +17109,7 @@ var RelationType;
17040
17109
  RelationType["Annotation"] = "m.annotation";
17041
17110
  RelationType["Replace"] = "m.replace";
17042
17111
  RelationType["Reference"] = "m.reference";
17043
- /**
17044
- * Note, "io.element.thread" is hardcoded
17045
- * Should be replaced with "m.thread" once MSC3440 lands
17046
- * Can not use `UnstableValue` as TypeScript does not
17047
- * allow computed values in enums
17048
- * https://github.com/microsoft/TypeScript/issues/27976
17049
- */
17050
- RelationType["Thread"] = "io.element.thread";
17112
+ RelationType["Thread"] = "m.thread";
17051
17113
  })(RelationType = exports.RelationType || (exports.RelationType = {}));
17052
17114
  var MsgType;
17053
17115
  (function (MsgType) {
@@ -17065,6 +17127,8 @@ exports.RoomCreateTypeField = "type";
17065
17127
  var RoomType;
17066
17128
  (function (RoomType) {
17067
17129
  RoomType["Space"] = "m.space";
17130
+ RoomType["UnstableCall"] = "org.matrix.msc3417.call";
17131
+ RoomType["ElementVideo"] = "io.element.video";
17068
17132
  })(RoomType = exports.RoomType || (exports.RoomType = {}));
17069
17133
  /**
17070
17134
  * Identifier for an [MSC3088](https://github.com/matrix-org/matrix-doc/pull/3088)
@@ -17123,7 +17187,7 @@ exports.UNSTABLE_ELEMENT_FUNCTIONAL_USERS = new NamespacedValue_1.UnstableValue(
17123
17187
  */
17124
17188
  exports.EVENT_VISIBILITY_CHANGE_TYPE = new NamespacedValue_1.UnstableValue("m.visibility", "org.matrix.msc3531.visibility");
17125
17189
 
17126
- },{"../NamespacedValue":83}],78:[function(require,module,exports){
17190
+ },{"../NamespacedValue":84}],79:[function(require,module,exports){
17127
17191
  "use strict";
17128
17192
  /*
17129
17193
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17146,7 +17210,7 @@ exports.TEXT_NODE_TYPE = void 0;
17146
17210
  const NamespacedValue_1 = require("../NamespacedValue");
17147
17211
  exports.TEXT_NODE_TYPE = new NamespacedValue_1.UnstableValue("m.text", "org.matrix.msc1767.text");
17148
17212
 
17149
- },{"../NamespacedValue":83}],79:[function(require,module,exports){
17213
+ },{"../NamespacedValue":84}],80:[function(require,module,exports){
17150
17214
  "use strict";
17151
17215
  /*
17152
17216
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17164,21 +17228,19 @@ See the License for the specific language governing permissions and
17164
17228
  limitations under the License.
17165
17229
  */
17166
17230
  Object.defineProperty(exports, "__esModule", { value: true });
17167
- exports.LocationAssetType = exports.TIMESTAMP_NODE_TYPE = exports.ASSET_NODE_TYPE = exports.LOCATION_EVENT_TYPE = void 0;
17168
- // Types for MSC3488 - m.location: Extending events with location data
17231
+ exports.M_LOCATION = exports.M_TIMESTAMP = exports.M_ASSET = exports.LocationAssetType = void 0;
17169
17232
  const NamespacedValue_1 = require("../NamespacedValue");
17170
17233
  const extensible_events_1 = require("./extensible_events");
17171
- exports.LOCATION_EVENT_TYPE = new NamespacedValue_1.UnstableValue("m.location", "org.matrix.msc3488.location");
17172
- exports.ASSET_NODE_TYPE = new NamespacedValue_1.UnstableValue("m.asset", "org.matrix.msc3488.asset");
17173
- exports.TIMESTAMP_NODE_TYPE = new NamespacedValue_1.UnstableValue("m.ts", "org.matrix.msc3488.ts");
17174
17234
  var LocationAssetType;
17175
17235
  (function (LocationAssetType) {
17176
17236
  LocationAssetType["Self"] = "m.self";
17177
17237
  LocationAssetType["Pin"] = "m.pin";
17178
17238
  })(LocationAssetType = exports.LocationAssetType || (exports.LocationAssetType = {}));
17179
- /* eslint-enable camelcase */
17239
+ exports.M_ASSET = new NamespacedValue_1.UnstableValue("m.asset", "org.matrix.msc3488.asset");
17240
+ exports.M_TIMESTAMP = new NamespacedValue_1.UnstableValue("m.ts", "org.matrix.msc3488.ts");
17241
+ exports.M_LOCATION = new NamespacedValue_1.UnstableValue("m.location", "org.matrix.msc3488.location");
17180
17242
 
17181
- },{"../NamespacedValue":83,"./extensible_events":78}],80:[function(require,module,exports){
17243
+ },{"../NamespacedValue":84,"./extensible_events":79}],81:[function(require,module,exports){
17182
17244
  "use strict";
17183
17245
  /*
17184
17246
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17237,7 +17299,7 @@ var HistoryVisibility;
17237
17299
  HistoryVisibility["WorldReadable"] = "world_readable";
17238
17300
  })(HistoryVisibility = exports.HistoryVisibility || (exports.HistoryVisibility = {}));
17239
17301
 
17240
- },{}],81:[function(require,module,exports){
17302
+ },{}],82:[function(require,module,exports){
17241
17303
  "use strict";
17242
17304
  /*
17243
17305
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17257,7 +17319,7 @@ limitations under the License.
17257
17319
  Object.defineProperty(exports, "__esModule", { value: true });
17258
17320
  /* eslint-enable camelcase */
17259
17321
 
17260
- },{}],82:[function(require,module,exports){
17322
+ },{}],83:[function(require,module,exports){
17261
17323
  "use strict";
17262
17324
  /*
17263
17325
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17288,7 +17350,7 @@ var SearchOrderBy;
17288
17350
  })(SearchOrderBy = exports.SearchOrderBy || (exports.SearchOrderBy = {}));
17289
17351
  /* eslint-enable camelcase */
17290
17352
 
17291
- },{}],83:[function(require,module,exports){
17353
+ },{}],84:[function(require,module,exports){
17292
17354
  "use strict";
17293
17355
  /*
17294
17356
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -17306,7 +17368,7 @@ See the License for the specific language governing permissions and
17306
17368
  limitations under the License.
17307
17369
  */
17308
17370
  Object.defineProperty(exports, "__esModule", { value: true });
17309
- exports.UnstableValue = exports.NamespacedValue = void 0;
17371
+ exports.UnstableValue = exports.ServerControlledNamespacedValue = exports.NamespacedValue = void 0;
17310
17372
  /**
17311
17373
  * Represents a simple Matrix namespaced value. This will assume that if a stable prefix
17312
17374
  * is provided that the stable prefix should be used when representing the identifier.
@@ -17360,6 +17422,22 @@ class NamespacedValue {
17360
17422
  }
17361
17423
  }
17362
17424
  exports.NamespacedValue = NamespacedValue;
17425
+ class ServerControlledNamespacedValue extends NamespacedValue {
17426
+ constructor() {
17427
+ super(...arguments);
17428
+ this.preferUnstable = false;
17429
+ }
17430
+ setPreferUnstable(preferUnstable) {
17431
+ this.preferUnstable = preferUnstable;
17432
+ }
17433
+ get name() {
17434
+ if (this.stable && !this.preferUnstable) {
17435
+ return this.stable;
17436
+ }
17437
+ return this.unstable;
17438
+ }
17439
+ }
17440
+ exports.ServerControlledNamespacedValue = ServerControlledNamespacedValue;
17363
17441
  /**
17364
17442
  * Represents a namespaced value which prioritizes the unstable value over the stable
17365
17443
  * value.
@@ -17381,7 +17459,7 @@ class UnstableValue extends NamespacedValue {
17381
17459
  }
17382
17460
  exports.UnstableValue = UnstableValue;
17383
17461
 
17384
- },{}],84:[function(require,module,exports){
17462
+ },{}],85:[function(require,module,exports){
17385
17463
  "use strict";
17386
17464
  /*
17387
17465
  Copyright 2015, 2016 OpenMarket Ltd
@@ -17441,7 +17519,7 @@ class TypedReEmitter extends ReEmitter {
17441
17519
  }
17442
17520
  exports.TypedReEmitter = TypedReEmitter;
17443
17521
 
17444
- },{}],85:[function(require,module,exports){
17522
+ },{}],86:[function(require,module,exports){
17445
17523
  "use strict";
17446
17524
  /*
17447
17525
  Copyright 2018 New Vector Ltd
@@ -17867,7 +17945,7 @@ AutoDiscovery.PROMPT = AutoDiscoveryAction.PROMPT;
17867
17945
  */
17868
17946
  AutoDiscovery.SUCCESS = AutoDiscoveryAction.SUCCESS;
17869
17947
 
17870
- },{"./logger":129,"./matrix":130,"url":74}],86:[function(require,module,exports){
17948
+ },{"./logger":130,"./matrix":131,"url":74}],87:[function(require,module,exports){
17871
17949
  (function (global){(function (){
17872
17950
  "use strict";
17873
17951
 
@@ -17956,7 +18034,7 @@ global.matrixcs = matrixcs;
17956
18034
 
17957
18035
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
17958
18036
 
17959
- },{"./matrix":130,"@babel/runtime/helpers/interopRequireDefault":7,"@babel/runtime/helpers/typeof":12,"browser-request":17,"qs":60}],87:[function(require,module,exports){
18037
+ },{"./matrix":131,"@babel/runtime/helpers/interopRequireDefault":7,"@babel/runtime/helpers/typeof":12,"browser-request":17,"qs":60}],88:[function(require,module,exports){
17960
18038
  (function (global){(function (){
17961
18039
  "use strict";
17962
18040
  /*
@@ -18047,6 +18125,8 @@ const search_1 = require("./@types/search");
18047
18125
  const PushRules_1 = require("./@types/PushRules");
18048
18126
  const mediaHandler_1 = require("./webrtc/mediaHandler");
18049
18127
  const typed_event_emitter_1 = require("./models/typed-event-emitter");
18128
+ const thread_1 = require("./models/thread");
18129
+ const beacon_1 = require("./@types/beacon");
18050
18130
  const SCROLLBACK_DELAY_MS = 3000;
18051
18131
  exports.CRYPTO_ENABLED = (0, crypto_1.isCryptoAvailable)();
18052
18132
  const CAPABILITIES_CACHE_MS = 21600000; // 6 hours - an arbitrary value
@@ -18083,11 +18163,6 @@ var ClientEvent;
18083
18163
  ClientEvent["DeleteRoom"] = "deleteRoom";
18084
18164
  ClientEvent["SyncUnexpectedError"] = "sync.unexpectedError";
18085
18165
  ClientEvent["ClientWellKnown"] = "WellKnown.client";
18086
- /* @deprecated */
18087
- ClientEvent["Group"] = "Group";
18088
- // The following enum members are both deprecated and in the wrong place, Groups haven't been TSified
18089
- ClientEvent["GroupProfile"] = "Group.profile";
18090
- ClientEvent["GroupMyMembership"] = "Group.myMembership";
18091
18166
  })(ClientEvent = exports.ClientEvent || (exports.ClientEvent = {}));
18092
18167
  /**
18093
18168
  * Represents a Matrix Client. Only directly construct this if you want to use
@@ -18326,7 +18401,13 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
18326
18401
  logger_1.logger.error("Still have sync object whilst not running: stopping old one");
18327
18402
  this.syncApi.stop();
18328
18403
  }
18329
- yield this.getCapabilities(true);
18404
+ try {
18405
+ const { serverSupport, stable } = yield this.doesServerSupportThread();
18406
+ thread_1.Thread.setServerSideSupport(serverSupport, stable);
18407
+ }
18408
+ catch (e) {
18409
+ thread_1.Thread.setServerSideSupport(false, true);
18410
+ }
18330
18411
  // shallow-copy the opts dict before modifying and storing it
18331
18412
  this.clientOpts = Object.assign({}, opts);
18332
18413
  this.clientOpts.crypto = this.crypto;
@@ -20019,25 +20100,6 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
20019
20100
  }
20020
20101
  });
20021
20102
  }
20022
- /**
20023
- * Get the group for the given group ID.
20024
- * This function will return a valid group for any group for which a Group event
20025
- * has been emitted.
20026
- * @param {string} groupId The group ID
20027
- * @return {Group} The Group or null if the group is not known or there is no data store.
20028
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
20029
- */
20030
- getGroup(groupId) {
20031
- return this.store.getGroup(groupId);
20032
- }
20033
- /**
20034
- * Retrieve all known groups.
20035
- * @return {Group[]} A list of groups, or an empty list if there is no data store.
20036
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
20037
- */
20038
- getGroups() {
20039
- return this.store.getGroups();
20040
- }
20041
20103
  /**
20042
20104
  * Get the config for the media repository.
20043
20105
  * @param {module:client.callback} callback Optional.
@@ -20405,6 +20467,39 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
20405
20467
  });
20406
20468
  return this.http.authedRequest(callback, http_api_1.Method.Put, path, undefined, content);
20407
20469
  }
20470
+ /**
20471
+ * Create an m.beacon_info event
20472
+ * @param {string} roomId
20473
+ * @param {MBeaconInfoEventContent} beaconInfoContent
20474
+ * @param {string} eventTypeSuffix - string to suffix event type
20475
+ * to make event type unique.
20476
+ * See MSC3489 for more context
20477
+ * https://github.com/matrix-org/matrix-spec-proposals/pull/3489
20478
+ * @returns {ISendEventResponse}
20479
+ */
20480
+ // eslint-disable-next-line @typescript-eslint/naming-convention
20481
+ unstable_createLiveBeacon(roomId, beaconInfoContent, eventTypeSuffix) {
20482
+ return __awaiter(this, void 0, void 0, function* () {
20483
+ const userId = this.getUserId();
20484
+ const eventType = beacon_1.M_BEACON_INFO_VARIABLE.name.replace('*', `${userId}.${eventTypeSuffix}`);
20485
+ return this.unstable_setLiveBeacon(roomId, eventType, beaconInfoContent);
20486
+ });
20487
+ }
20488
+ /**
20489
+ * Upsert a live beacon event
20490
+ * using a specific m.beacon_info.* event variable type
20491
+ * @param {string} roomId string
20492
+ * @param {string} beaconInfoEventType event type including variable suffix
20493
+ * @param {MBeaconInfoEventContent} beaconInfoContent
20494
+ * @returns {ISendEventResponse}
20495
+ */
20496
+ // eslint-disable-next-line @typescript-eslint/naming-convention
20497
+ unstable_setLiveBeacon(roomId, beaconInfoEventType, beaconInfoContent) {
20498
+ return __awaiter(this, void 0, void 0, function* () {
20499
+ const userId = this.getUserId();
20500
+ return this.sendStateEvent(roomId, beaconInfoEventType, beaconInfoContent, userId);
20501
+ });
20502
+ }
20408
20503
  sendEvent(roomId, threadId, eventType, content, txnId, callback) {
20409
20504
  var _a, _b, _c;
20410
20505
  if (!(threadId === null || threadId === void 0 ? void 0 : threadId.startsWith(EVENT_ID_PREFIX)) && threadId !== null) {
@@ -20417,12 +20512,12 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
20417
20512
  // If we expect that an event is part of a thread but is missing the relation
20418
20513
  // we need to add it manually, as well as the reply fallback
20419
20514
  if (threadId && !((_a = content["m.relates_to"]) === null || _a === void 0 ? void 0 : _a.rel_type)) {
20420
- content["m.relates_to"] = Object.assign(Object.assign({}, content["m.relates_to"]), { "rel_type": event_2.RelationType.Thread, "event_id": threadId });
20515
+ content["m.relates_to"] = Object.assign(Object.assign({}, content["m.relates_to"]), { "rel_type": thread_1.THREAD_RELATION_TYPE.name, "event_id": threadId });
20421
20516
  const thread = (_b = this.getRoom(roomId)) === null || _b === void 0 ? void 0 : _b.threads.get(threadId);
20422
20517
  if (thread) {
20423
20518
  content["m.relates_to"]["m.in_reply_to"] = {
20424
20519
  "event_id": (_c = thread.lastReply((ev) => {
20425
- return ev.isThreadRelation && !ev.status;
20520
+ return ev.isRelation(thread_1.THREAD_RELATION_TYPE.name) && !ev.status;
20426
20521
  })) === null || _c === void 0 ? void 0 : _c.getId(),
20427
20522
  };
20428
20523
  }
@@ -20607,7 +20702,6 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
20607
20702
  /**
20608
20703
  * Returns the eventType that should be used taking encryption into account
20609
20704
  * for a given eventType.
20610
- * @param {MatrixClient} client the client
20611
20705
  * @param {string} roomId the room for the events `eventType` relates to
20612
20706
  * @param {string} eventType the event type
20613
20707
  * @return {string} the event type taking encryption into account
@@ -21231,28 +21325,6 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21231
21325
  };
21232
21326
  return this.http.authedRequest(callback, http_api_1.Method.Post, path, undefined, data);
21233
21327
  }
21234
- /**
21235
- * This is an internal method.
21236
- * @param {MatrixClient} client
21237
- * @param {string} roomId
21238
- * @param {string} userId
21239
- * @param {string} membershipValue
21240
- * @param {string} reason
21241
- * @param {module:client.callback} callback Optional.
21242
- * @return {Promise} Resolves: TODO
21243
- * @return {module:http-api.MatrixError} Rejects: with an error response.
21244
- */
21245
- setMembershipState(roomId, userId, membershipValue, reason, callback) {
21246
- if (utils.isFunction(reason)) {
21247
- callback = reason; // legacy
21248
- reason = undefined;
21249
- }
21250
- const path = utils.encodeUri("/rooms/$roomId/state/m.room.member/$userId", { $roomId: roomId, $userId: userId });
21251
- return this.http.authedRequest(callback, http_api_1.Method.Put, path, undefined, {
21252
- membership: membershipValue,
21253
- reason: reason,
21254
- });
21255
- }
21256
21328
  membershipChange(roomId, userId, membership, reason, callback) {
21257
21329
  if (utils.isFunction(reason)) {
21258
21330
  callback = reason; // legacy
@@ -21448,7 +21520,7 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21448
21520
  const stateEvents = res.state.map(this.getEventMapper());
21449
21521
  room.currentState.setUnknownStateEvents(stateEvents);
21450
21522
  }
21451
- const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(matrixEvents);
21523
+ const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(room, matrixEvents);
21452
21524
  room.addEventsToTimeline(timelineEvents, true, room.getLiveTimeline());
21453
21525
  yield this.processThreadEvents(room, threadedEvents, true);
21454
21526
  room.oldState.paginationToken = res.end;
@@ -21494,67 +21566,88 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21494
21566
  * @param {string} eventId The ID of the event to look for
21495
21567
  *
21496
21568
  * @return {Promise} Resolves:
21497
- * {@link module:models/event-timeline~EventTimeline} including the given
21498
- * event
21569
+ * {@link module:models/event-timeline~EventTimeline} including the given event
21499
21570
  */
21500
21571
  getEventTimeline(timelineSet, eventId) {
21501
- // don't allow any timeline support unless it's been enabled.
21502
- if (!this.timelineSupport) {
21503
- throw new Error("timeline support is disabled. Set the 'timelineSupport'" +
21504
- " parameter to true when creating MatrixClient to enable" +
21505
- " it.");
21506
- }
21507
- if (timelineSet.getTimelineForEvent(eventId)) {
21508
- return Promise.resolve(timelineSet.getTimelineForEvent(eventId));
21509
- }
21510
- const path = utils.encodeUri("/rooms/$roomId/context/$eventId", {
21511
- $roomId: timelineSet.room.roomId,
21512
- $eventId: eventId,
21513
- });
21514
- let params = undefined;
21515
- if (this.clientOpts.lazyLoadMembers) {
21516
- params = { filter: JSON.stringify(filter_1.Filter.LAZY_LOADING_MESSAGES_FILTER) };
21517
- }
21518
- // TODO: we should implement a backoff (as per scrollback()) to deal more
21519
- // nicely with HTTP errors.
21520
- const promise = this.http.authedRequest(undefined, http_api_1.Method.Get, path, params).then((res) => __awaiter(this, void 0, void 0, function* () {
21572
+ var _a, _b, _c;
21573
+ return __awaiter(this, void 0, void 0, function* () {
21574
+ // don't allow any timeline support unless it's been enabled.
21575
+ if (!this.timelineSupport) {
21576
+ throw new Error("timeline support is disabled. Set the 'timelineSupport'" +
21577
+ " parameter to true when creating MatrixClient to enable it.");
21578
+ }
21579
+ if (timelineSet.getTimelineForEvent(eventId)) {
21580
+ return timelineSet.getTimelineForEvent(eventId);
21581
+ }
21582
+ const path = utils.encodeUri("/rooms/$roomId/context/$eventId", {
21583
+ $roomId: timelineSet.room.roomId,
21584
+ $eventId: eventId,
21585
+ });
21586
+ let params = undefined;
21587
+ if (this.clientOpts.lazyLoadMembers) {
21588
+ params = { filter: JSON.stringify(filter_1.Filter.LAZY_LOADING_MESSAGES_FILTER) };
21589
+ }
21590
+ // TODO: we should implement a backoff (as per scrollback()) to deal more nicely with HTTP errors.
21591
+ const res = yield this.http.authedRequest(undefined, http_api_1.Method.Get, path, params); // TODO types
21521
21592
  if (!res.event) {
21522
21593
  throw new Error("'event' not in '/context' result - homeserver too old?");
21523
21594
  }
21524
- // by the time the request completes, the event might have ended up in
21525
- // the timeline.
21595
+ // by the time the request completes, the event might have ended up in the timeline.
21526
21596
  if (timelineSet.getTimelineForEvent(eventId)) {
21527
21597
  return timelineSet.getTimelineForEvent(eventId);
21528
21598
  }
21529
- // we start with the last event, since that's the point at which we
21530
- // have known state.
21531
- // events_after is already backwards; events_before is forwards.
21532
- res.events_after.reverse();
21533
- const events = res.events_after
21534
- .concat([res.event])
21535
- .concat(res.events_before);
21536
- const matrixEvents = events.map(this.getEventMapper());
21537
- let timeline = timelineSet.getTimelineForEvent(matrixEvents[0].getId());
21538
- if (!timeline) {
21539
- timeline = timelineSet.addTimeline();
21540
- timeline.initialiseState(res.state.map(this.getEventMapper()));
21541
- timeline.getState(event_timeline_1.EventTimeline.FORWARDS).paginationToken = res.end;
21599
+ const mapper = this.getEventMapper();
21600
+ const event = mapper(res.event);
21601
+ const events = [
21602
+ // we start with the last event, since that's the point at which we have known state.
21603
+ // events_after is already backwards; events_before is forwards.
21604
+ ...res.events_after.reverse().map(mapper),
21605
+ event,
21606
+ ...res.events_before.map(mapper),
21607
+ ];
21608
+ // Where the event is a thread reply (not a root) and running in MSC-enabled mode the Thread timeline only
21609
+ // functions contiguously, so we have to jump through some hoops to get our target event in it.
21610
+ // XXX: workaround for https://github.com/vector-im/element-meta/issues/150
21611
+ if (thread_1.Thread.hasServerSideSupport && event.isRelation(thread_1.THREAD_RELATION_TYPE.name)) {
21612
+ const [, threadedEvents] = this.partitionThreadedEvents(timelineSet.room, events);
21613
+ const thread = yield timelineSet.room.createThreadFetchRoot(event.threadRootId, threadedEvents, true);
21614
+ let nextBatch;
21615
+ const response = yield thread.fetchInitialEvents();
21616
+ if (response === null || response === void 0 ? void 0 : response.nextBatch) {
21617
+ nextBatch = response.nextBatch;
21618
+ }
21619
+ const opts = {
21620
+ limit: 50,
21621
+ };
21622
+ // Fetch events until we find the one we were asked for
21623
+ while (!thread.findEventById(eventId)) {
21624
+ if (nextBatch) {
21625
+ opts.from = nextBatch;
21626
+ }
21627
+ ({ nextBatch } = yield thread.fetchEvents(opts));
21628
+ }
21629
+ return thread.liveTimeline;
21630
+ }
21631
+ // Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
21632
+ let timeline = timelineSet.getTimelineForEvent(events[0].getId());
21633
+ if (timeline) {
21634
+ timeline.getState(event_timeline_1.EventTimeline.BACKWARDS).setUnknownStateEvents(res.state.map(mapper));
21542
21635
  }
21543
21636
  else {
21544
- const stateEvents = res.state.map(this.getEventMapper());
21545
- timeline.getState(event_timeline_1.EventTimeline.BACKWARDS).setUnknownStateEvents(stateEvents);
21637
+ timeline = timelineSet.addTimeline();
21638
+ timeline.initialiseState(res.state.map(mapper));
21639
+ timeline.getState(event_timeline_1.EventTimeline.FORWARDS).paginationToken = res.end;
21546
21640
  }
21547
- const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(matrixEvents);
21641
+ const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(timelineSet.room, events);
21548
21642
  timelineSet.addEventsToTimeline(timelineEvents, true, timeline, res.start);
21643
+ // The target event is not in a thread but process the contextual events, so we can show any threads around it.
21549
21644
  yield this.processThreadEvents(timelineSet.room, threadedEvents, true);
21550
- // there is no guarantee that the event ended up in "timeline" (we
21551
- // might have switched to a neighbouring timeline) - so check the
21552
- // room's index again. On the other hand, there's no guarantee the
21553
- // event ended up anywhere, if it was later redacted, so we just
21554
- // return the timeline we first thought of.
21555
- return timelineSet.getTimelineForEvent(eventId) || timeline;
21556
- }));
21557
- return promise;
21645
+ // There is no guarantee that the event ended up in "timeline" (we might have switched to a neighbouring
21646
+ // timeline) - so check the room's index again. On the other hand, there's no guarantee the event ended up
21647
+ // anywhere, if it was later redacted, so we just return the timeline we first thought of.
21648
+ return (_c = (_a = timelineSet.getTimelineForEvent(eventId)) !== null && _a !== void 0 ? _a : (_b = timelineSet.room.findThreadForEvent(event)) === null || _b === void 0 ? void 0 : _b.liveTimeline // for Threads degraded support
21649
+ ) !== null && _c !== void 0 ? _c : timeline;
21650
+ });
21558
21651
  }
21559
21652
  /**
21560
21653
  * Makes a request to /messages with the appropriate lazy loading filter set.
@@ -21637,7 +21730,7 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21637
21730
  limit: ((_a = opts.limit) !== null && _a !== void 0 ? _a : 30).toString(),
21638
21731
  only: 'highlight',
21639
21732
  };
21640
- if (token && token !== "end") {
21733
+ if (token !== "end") {
21641
21734
  params.from = token;
21642
21735
  }
21643
21736
  promise = this.http.authedRequest(// TODO types
@@ -21651,8 +21744,8 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21651
21744
  event.event.room_id = notification.room_id; // XXX: gutwrenching
21652
21745
  matrixEvents[i] = event;
21653
21746
  }
21654
- const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(matrixEvents);
21655
21747
  const timelineSet = eventTimeline.getTimelineSet();
21748
+ const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(timelineSet.room, matrixEvents);
21656
21749
  timelineSet.addEventsToTimeline(timelineEvents, backwards, eventTimeline, token);
21657
21750
  yield this.processThreadEvents(timelineSet.room, threadedEvents, backwards);
21658
21751
  // if we've hit the end of the timeline, we need to stop trying to
@@ -21680,9 +21773,9 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
21680
21773
  }
21681
21774
  const token = res.end;
21682
21775
  const matrixEvents = res.chunk.map(this.getEventMapper());
21683
- const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(matrixEvents);
21684
- eventTimeline.getTimelineSet()
21685
- .addEventsToTimeline(timelineEvents, backwards, eventTimeline, token);
21776
+ const timelineSet = eventTimeline.getTimelineSet();
21777
+ const [timelineEvents, threadedEvents] = this.partitionThreadedEvents(timelineSet.room, matrixEvents);
21778
+ timelineSet.addEventsToTimeline(timelineEvents, backwards, eventTimeline, token);
21686
21779
  yield this.processThreadEvents(room, threadedEvents, backwards);
21687
21780
  // if we've hit the end of the timeline, we need to stop trying to
21688
21781
  // paginate. We need to keep the 'forwards' token though, to make sure
@@ -22075,7 +22168,7 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
22075
22168
  * @return {module:http-api.MatrixError} Rejects: with an error response.
22076
22169
  */
22077
22170
  searchRoomEvents(opts) {
22078
- // TODO: support groups
22171
+ // TODO: support search groups
22079
22172
  const body = {
22080
22173
  search_categories: {
22081
22174
  room_events: {
@@ -22137,6 +22230,7 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
22137
22230
  */
22138
22231
  // XXX: Intended private, used in code
22139
22232
  processRoomEventsSearch(searchResults, response) {
22233
+ var _a, _b;
22140
22234
  const roomEvents = response.search_categories.room_events;
22141
22235
  searchResults.count = roomEvents.count;
22142
22236
  searchResults.next_batch = roomEvents.next_batch;
@@ -22147,10 +22241,11 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
22147
22241
  });
22148
22242
  // turn it back into a list.
22149
22243
  searchResults.highlights = Array.from(highlights);
22244
+ const mapper = this.getEventMapper();
22150
22245
  // append the new results to our existing results
22151
- const resultsLength = roomEvents.results ? roomEvents.results.length : 0;
22246
+ const resultsLength = (_b = (_a = roomEvents.results) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
22152
22247
  for (let i = 0; i < resultsLength; i++) {
22153
- const sr = search_result_1.SearchResult.fromJson(roomEvents.results[i], this.getEventMapper());
22248
+ const sr = search_result_1.SearchResult.fromJson(roomEvents.results[i], mapper);
22154
22249
  const room = this.getRoom(sr.context.getEvent().getRoomId());
22155
22250
  if (room) {
22156
22251
  // Copy over a known event sender if we can
@@ -22613,6 +22708,22 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
22613
22708
  return unstableFeatures && !!unstableFeatures[`io.element.e2ee_forced.${versionsPresetName}`];
22614
22709
  });
22615
22710
  }
22711
+ doesServerSupportThread() {
22712
+ return __awaiter(this, void 0, void 0, function* () {
22713
+ try {
22714
+ const hasUnstableSupport = yield this.doesServerSupportUnstableFeature("org.matrix.msc3440");
22715
+ const hasStableSupport = (yield this.doesServerSupportUnstableFeature("org.matrix.msc3440.stable"))
22716
+ || (yield this.isVersionSupported("v1.3"));
22717
+ return {
22718
+ serverSupport: hasUnstableSupport || hasStableSupport,
22719
+ stable: hasStableSupport,
22720
+ };
22721
+ }
22722
+ catch (e) {
22723
+ return null;
22724
+ }
22725
+ });
22726
+ }
22616
22727
  /**
22617
22728
  * Get if lazy loading members is being used.
22618
22729
  * @return {boolean} Whether or not members are lazy loaded by this client
@@ -22655,10 +22766,7 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
22655
22766
  const fetchedEventType = this.getEncryptedIfNeededEventType(roomId, eventType);
22656
22767
  const result = yield this.fetchRelations(roomId, eventId, relationType, fetchedEventType, opts);
22657
22768
  const mapper = this.getEventMapper();
22658
- let originalEvent;
22659
- if (result.original_event) {
22660
- originalEvent = mapper(result.original_event);
22661
- }
22769
+ const originalEvent = result.original_event ? mapper(result.original_event) : undefined;
22662
22770
  let events = result.chunk.map(mapper);
22663
22771
  if (fetchedEventType === event_2.EventType.RoomMessageEncrypted) {
22664
22772
  const allEvents = originalEvent ? events.concat(originalEvent) : events;
@@ -24481,289 +24589,6 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
24481
24589
  return null;
24482
24590
  return new MSC3089TreeSpace_1.MSC3089TreeSpace(this, roomId);
24483
24591
  }
24484
- // TODO: Remove this warning, alongside the functions
24485
- // See https://github.com/vector-im/element-web/issues/17532
24486
- // ======================================================
24487
- // ** ANCIENT APIS BELOW **
24488
- // ======================================================
24489
- /**
24490
- * @param {string} groupId
24491
- * @return {Promise} Resolves: Group summary object
24492
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24493
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24494
- */
24495
- getGroupSummary(groupId) {
24496
- const path = utils.encodeUri("/groups/$groupId/summary", { $groupId: groupId });
24497
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24498
- }
24499
- /**
24500
- * @param {string} groupId
24501
- * @return {Promise} Resolves: Group profile object
24502
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24503
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24504
- */
24505
- getGroupProfile(groupId) {
24506
- const path = utils.encodeUri("/groups/$groupId/profile", { $groupId: groupId });
24507
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24508
- }
24509
- /**
24510
- * @param {string} groupId
24511
- * @param {Object} profile The group profile object
24512
- * @param {string=} profile.name Name of the group
24513
- * @param {string=} profile.avatar_url MXC avatar URL
24514
- * @param {string=} profile.short_description A short description of the room
24515
- * @param {string=} profile.long_description A longer HTML description of the room
24516
- * @return {Promise} Resolves: Empty object
24517
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24518
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24519
- */
24520
- setGroupProfile(groupId, profile) {
24521
- const path = utils.encodeUri("/groups/$groupId/profile", { $groupId: groupId });
24522
- return this.http.authedRequest(undefined, http_api_1.Method.Post, path, undefined, profile);
24523
- }
24524
- /**
24525
- * @param {string} groupId
24526
- * @param {object} policy The join policy for the group. Must include at
24527
- * least a 'type' field which is 'open' if anyone can join the group
24528
- * the group without prior approval, or 'invite' if an invite is
24529
- * required to join.
24530
- * @return {Promise} Resolves: Empty object
24531
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24532
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24533
- */
24534
- setGroupJoinPolicy(groupId, policy) {
24535
- const path = utils.encodeUri("/groups/$groupId/settings/m.join_policy", { $groupId: groupId });
24536
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {
24537
- 'm.join_policy': policy,
24538
- });
24539
- }
24540
- /**
24541
- * @param {string} groupId
24542
- * @return {Promise} Resolves: Group users list object
24543
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24544
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24545
- */
24546
- getGroupUsers(groupId) {
24547
- const path = utils.encodeUri("/groups/$groupId/users", { $groupId: groupId });
24548
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24549
- }
24550
- /**
24551
- * @param {string} groupId
24552
- * @return {Promise} Resolves: Group users list object
24553
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24554
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24555
- */
24556
- getGroupInvitedUsers(groupId) {
24557
- const path = utils.encodeUri("/groups/$groupId/invited_users", { $groupId: groupId });
24558
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24559
- }
24560
- /**
24561
- * @param {string} groupId
24562
- * @return {Promise} Resolves: Group rooms list object
24563
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24564
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24565
- */
24566
- getGroupRooms(groupId) {
24567
- const path = utils.encodeUri("/groups/$groupId/rooms", { $groupId: groupId });
24568
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24569
- }
24570
- /**
24571
- * @param {string} groupId
24572
- * @param {string} userId
24573
- * @return {Promise} Resolves: Empty object
24574
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24575
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24576
- */
24577
- inviteUserToGroup(groupId, userId) {
24578
- const path = utils.encodeUri("/groups/$groupId/admin/users/invite/$userId", { $groupId: groupId, $userId: userId });
24579
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24580
- }
24581
- /**
24582
- * @param {string} groupId
24583
- * @param {string} userId
24584
- * @return {Promise} Resolves: Empty object
24585
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24586
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24587
- */
24588
- removeUserFromGroup(groupId, userId) {
24589
- const path = utils.encodeUri("/groups/$groupId/admin/users/remove/$userId", { $groupId: groupId, $userId: userId });
24590
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24591
- }
24592
- /**
24593
- * @param {string} groupId
24594
- * @param {string} userId
24595
- * @param {string} roleId Optional.
24596
- * @return {Promise} Resolves: Empty object
24597
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24598
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24599
- */
24600
- addUserToGroupSummary(groupId, userId, roleId) {
24601
- const path = utils.encodeUri(roleId ?
24602
- "/groups/$groupId/summary/$roleId/users/$userId" :
24603
- "/groups/$groupId/summary/users/$userId", { $groupId: groupId, $roleId: roleId, $userId: userId });
24604
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24605
- }
24606
- /**
24607
- * @param {string} groupId
24608
- * @param {string} userId
24609
- * @return {Promise} Resolves: Empty object
24610
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24611
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24612
- */
24613
- removeUserFromGroupSummary(groupId, userId) {
24614
- const path = utils.encodeUri("/groups/$groupId/summary/users/$userId", { $groupId: groupId, $userId: userId });
24615
- return this.http.authedRequest(undefined, http_api_1.Method.Delete, path, undefined, {});
24616
- }
24617
- /**
24618
- * @param {string} groupId
24619
- * @param {string} roomId
24620
- * @param {string} categoryId Optional.
24621
- * @return {Promise} Resolves: Empty object
24622
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24623
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24624
- */
24625
- addRoomToGroupSummary(groupId, roomId, categoryId) {
24626
- const path = utils.encodeUri(categoryId ?
24627
- "/groups/$groupId/summary/$categoryId/rooms/$roomId" :
24628
- "/groups/$groupId/summary/rooms/$roomId", { $groupId: groupId, $categoryId: categoryId, $roomId: roomId });
24629
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24630
- }
24631
- /**
24632
- * @param {string} groupId
24633
- * @param {string} roomId
24634
- * @return {Promise} Resolves: Empty object
24635
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24636
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24637
- */
24638
- removeRoomFromGroupSummary(groupId, roomId) {
24639
- const path = utils.encodeUri("/groups/$groupId/summary/rooms/$roomId", { $groupId: groupId, $roomId: roomId });
24640
- return this.http.authedRequest(undefined, http_api_1.Method.Delete, path, undefined, {});
24641
- }
24642
- /**
24643
- * @param {string} groupId
24644
- * @param {string} roomId
24645
- * @param {boolean} isPublic Whether the room-group association is visible to non-members
24646
- * @return {Promise} Resolves: Empty object
24647
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24648
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24649
- */
24650
- addRoomToGroup(groupId, roomId, isPublic) {
24651
- if (isPublic === undefined) {
24652
- isPublic = true;
24653
- }
24654
- const path = utils.encodeUri("/groups/$groupId/admin/rooms/$roomId", { $groupId: groupId, $roomId: roomId });
24655
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, { "m.visibility": { type: isPublic ? "public" : "private" } });
24656
- }
24657
- /**
24658
- * Configure the visibility of a room-group association.
24659
- * @param {string} groupId
24660
- * @param {string} roomId
24661
- * @param {boolean} isPublic Whether the room-group association is visible to non-members
24662
- * @return {Promise} Resolves: Empty object
24663
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24664
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24665
- */
24666
- updateGroupRoomVisibility(groupId, roomId, isPublic) {
24667
- // NB: The /config API is generic but there's not much point in exposing this yet as synapse
24668
- // is the only server to implement this. In future we should consider an API that allows
24669
- // arbitrary configuration, i.e. "config/$configKey".
24670
- const path = utils.encodeUri("/groups/$groupId/admin/rooms/$roomId/config/m.visibility", { $groupId: groupId, $roomId: roomId });
24671
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, { type: isPublic ? "public" : "private" });
24672
- }
24673
- /**
24674
- * @param {string} groupId
24675
- * @param {string} roomId
24676
- * @return {Promise} Resolves: Empty object
24677
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24678
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24679
- */
24680
- removeRoomFromGroup(groupId, roomId) {
24681
- const path = utils.encodeUri("/groups/$groupId/admin/rooms/$roomId", { $groupId: groupId, $roomId: roomId });
24682
- return this.http.authedRequest(undefined, http_api_1.Method.Delete, path, undefined, {});
24683
- }
24684
- /**
24685
- * @param {string} groupId
24686
- * @param {Object} opts Additional options to send alongside the acceptance.
24687
- * @return {Promise} Resolves: Empty object
24688
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24689
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24690
- */
24691
- acceptGroupInvite(groupId, opts = null) {
24692
- const path = utils.encodeUri("/groups/$groupId/self/accept_invite", { $groupId: groupId });
24693
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, opts || {});
24694
- }
24695
- /**
24696
- * @param {string} groupId
24697
- * @return {Promise} Resolves: Empty object
24698
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24699
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24700
- */
24701
- joinGroup(groupId) {
24702
- const path = utils.encodeUri("/groups/$groupId/self/join", { $groupId: groupId });
24703
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24704
- }
24705
- /**
24706
- * @param {string} groupId
24707
- * @return {Promise} Resolves: Empty object
24708
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24709
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24710
- */
24711
- leaveGroup(groupId) {
24712
- const path = utils.encodeUri("/groups/$groupId/self/leave", { $groupId: groupId });
24713
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {});
24714
- }
24715
- /**
24716
- * @return {Promise} Resolves: The groups to which the user is joined
24717
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24718
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24719
- */
24720
- getJoinedGroups() {
24721
- const path = utils.encodeUri("/joined_groups", {});
24722
- return this.http.authedRequest(undefined, http_api_1.Method.Get, path);
24723
- }
24724
- /**
24725
- * @param {Object} content Request content
24726
- * @param {string} content.localpart The local part of the desired group ID
24727
- * @param {Object} content.profile Group profile object
24728
- * @return {Promise} Resolves: Object with key group_id: id of the created group
24729
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24730
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24731
- */
24732
- createGroup(content) {
24733
- const path = utils.encodeUri("/create_group", {});
24734
- return this.http.authedRequest(undefined, http_api_1.Method.Post, path, undefined, content);
24735
- }
24736
- /**
24737
- * @param {string[]} userIds List of user IDs
24738
- * @return {Promise} Resolves: Object as exmaple below
24739
- *
24740
- * {
24741
- * "users": {
24742
- * "@bob:example.com": {
24743
- * "+example:example.com"
24744
- * }
24745
- * }
24746
- * }
24747
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24748
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24749
- */
24750
- getPublicisedGroups(userIds) {
24751
- const path = utils.encodeUri("/publicised_groups", {});
24752
- return this.http.authedRequest(undefined, http_api_1.Method.Post, path, undefined, { user_ids: userIds });
24753
- }
24754
- /**
24755
- * @param {string} groupId
24756
- * @param {boolean} isPublic Whether the user's membership of this group is made public
24757
- * @return {Promise} Resolves: Empty object
24758
- * @return {module:http-api.MatrixError} Rejects: with an error response.
24759
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
24760
- */
24761
- setGroupPublicity(groupId, isPublic) {
24762
- const path = utils.encodeUri("/groups/$groupId/self/update_publicity", { $groupId: groupId });
24763
- return this.http.authedRequest(undefined, http_api_1.Method.Put, path, undefined, {
24764
- publicise: isPublic,
24765
- });
24766
- }
24767
24592
  /**
24768
24593
  * @experimental
24769
24594
  */
@@ -24799,59 +24624,14 @@ class MatrixClient extends typed_event_emitter_1.TypedEventEmitter {
24799
24624
  }
24800
24625
  return threadRoots;
24801
24626
  }
24802
- eventShouldLiveIn(event, room, events, roots) {
24803
- if (event.isThreadRoot) {
24804
- return {
24805
- shouldLiveInRoom: true,
24806
- shouldLiveInThread: true,
24807
- threadId: event.getId(),
24808
- };
24809
- }
24810
- // A thread relation is always only shown in a thread
24811
- if (event.isThreadRelation) {
24812
- return {
24813
- shouldLiveInRoom: false,
24814
- shouldLiveInThread: true,
24815
- threadId: event.relationEventId,
24816
- };
24817
- }
24818
- const parentEventId = event.getAssociatedId();
24819
- const parentEvent = (room === null || room === void 0 ? void 0 : room.findEventById(parentEventId)) || events.find((mxEv) => (mxEv.getId() === parentEventId));
24820
- // A reaction targetting the thread root needs to be routed to both the
24821
- // the main timeline and the associated thread
24822
- const targetingThreadRoot = (parentEvent === null || parentEvent === void 0 ? void 0 : parentEvent.isThreadRoot) || roots.has(event.relationEventId);
24823
- if (targetingThreadRoot) {
24824
- return {
24825
- shouldLiveInRoom: true,
24826
- shouldLiveInThread: true,
24827
- threadId: event.relationEventId,
24828
- };
24829
- }
24830
- // If the parent event also has an associated ID we want to re-run the
24831
- // computation for that parent event.
24832
- // In the case of the redaction of a reaction that targets a root event
24833
- // we want that redaction to be pushed to both timeline
24834
- if (parentEvent === null || parentEvent === void 0 ? void 0 : parentEvent.getAssociatedId()) {
24835
- return this.eventShouldLiveIn(parentEvent, room, events, roots);
24836
- }
24837
- else {
24838
- // We've exhausted all scenarios, can safely assume that this event
24839
- // should live in the room timeline
24840
- return {
24841
- shouldLiveInRoom: true,
24842
- shouldLiveInThread: false,
24843
- };
24844
- }
24845
- }
24846
- partitionThreadedEvents(events) {
24847
- // Indices to the events array, for readibility
24627
+ partitionThreadedEvents(room, events) {
24628
+ // Indices to the events array, for readability
24848
24629
  const ROOM = 0;
24849
24630
  const THREAD = 1;
24850
24631
  if (this.supportsExperimentalThreads()) {
24851
24632
  const threadRoots = this.findThreadRoots(events);
24852
24633
  return events.reduce((memo, event) => {
24853
- const room = this.getRoom(event.getRoomId());
24854
- const { shouldLiveInRoom, shouldLiveInThread, threadId, } = this.eventShouldLiveIn(event, room, events, threadRoots);
24634
+ const { shouldLiveInRoom, shouldLiveInThread, threadId, } = room.eventShouldLiveIn(event, events, threadRoots);
24855
24635
  if (shouldLiveInRoom) {
24856
24636
  memo[ROOM].push(event);
24857
24637
  }
@@ -25055,17 +24835,6 @@ MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY = 'RESTORE_BACKUP_ERROR_BAD_KEY';
25055
24835
  * }
25056
24836
  * });
25057
24837
  */
25058
- /**
25059
- * Fires whenever the sdk learns about a new group. <strong>This event
25060
- * is experimental and may change.</strong>
25061
- * @event module:client~MatrixClient#"Group"
25062
- * @param {Group} group The newly created, fully populated group.
25063
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
25064
- * @example
25065
- * matrixClient.on("Group", function(group){
25066
- * var groupId = group.groupId;
25067
- * });
25068
- */
25069
24838
  /**
25070
24839
  * Fires whenever a new Room is added. This will fire when you are invited to a
25071
24840
  * room, as well as when you join a room. <strong>This event is experimental and
@@ -25235,7 +25004,7 @@ MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY = 'RESTORE_BACKUP_ERROR_BAD_KEY';
25235
25004
 
25236
25005
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
25237
25006
 
25238
- },{"./@types/PushRules":76,"./@types/event":77,"./@types/partials":80,"./@types/search":82,"./ReEmitter":84,"./autodiscovery":85,"./content-helpers":88,"./content-repo":89,"./crypto":106,"./crypto/RoomList":95,"./crypto/api":102,"./crypto/backup":103,"./crypto/dehydration":104,"./crypto/key_passphrase":107,"./crypto/olmlib":108,"./crypto/recoverykey":109,"./event-mapper":123,"./filter":125,"./http-api":126,"./logger":129,"./matrix":130,"./models/MSC3089TreeSpace":132,"./models/event":137,"./models/event-timeline":136,"./models/search-result":144,"./models/typed-event-emitter":146,"./models/user":147,"./pushprocessor":148,"./randomstring":149,"./service-types":152,"./store/stub":158,"./sync":160,"./utils":162,"./webrtc/call":163,"./webrtc/callEventHandler":164,"./webrtc/mediaHandler":167,"matrix-events-sdk":49}],88:[function(require,module,exports){
25007
+ },{"./@types/PushRules":76,"./@types/beacon":77,"./@types/event":78,"./@types/partials":81,"./@types/search":83,"./ReEmitter":85,"./autodiscovery":86,"./content-helpers":89,"./content-repo":90,"./crypto":107,"./crypto/RoomList":96,"./crypto/api":103,"./crypto/backup":104,"./crypto/dehydration":105,"./crypto/key_passphrase":108,"./crypto/olmlib":109,"./crypto/recoverykey":110,"./event-mapper":124,"./filter":126,"./http-api":127,"./logger":130,"./matrix":131,"./models/MSC3089TreeSpace":133,"./models/event":139,"./models/event-timeline":138,"./models/search-result":145,"./models/thread":146,"./models/typed-event-emitter":147,"./models/user":148,"./pushprocessor":149,"./randomstring":150,"./service-types":153,"./store/stub":159,"./sync":161,"./utils":163,"./webrtc/call":164,"./webrtc/callEventHandler":165,"./webrtc/mediaHandler":168,"matrix-events-sdk":49}],89:[function(require,module,exports){
25239
25008
  "use strict";
25240
25009
  /*
25241
25010
  Copyright 2018 - 2022 The Matrix.org Foundation C.I.C.
@@ -25253,8 +25022,10 @@ See the License for the specific language governing permissions and
25253
25022
  limitations under the License.
25254
25023
  */
25255
25024
  Object.defineProperty(exports, "__esModule", { value: true });
25256
- exports.makeLocationContent = exports.makeEmoteMessage = exports.makeNotice = exports.makeTextMessage = exports.makeHtmlEmote = exports.makeHtmlNotice = exports.makeHtmlMessage = void 0;
25025
+ exports.makeBeaconContent = exports.parseBeaconInfoContent = exports.makeBeaconInfoContent = exports.parseLocationEvent = exports.makeLocationContent = exports.getTextForLocationEvent = exports.makeEmoteMessage = exports.makeNotice = exports.makeTextMessage = exports.makeHtmlEmote = exports.makeHtmlNotice = exports.makeHtmlMessage = void 0;
25257
25026
  /** @module ContentHelpers */
25027
+ const matrix_events_sdk_1 = require("matrix-events-sdk");
25028
+ const beacon_1 = require("./@types/beacon");
25258
25029
  const event_1 = require("./@types/event");
25259
25030
  const extensible_events_1 = require("./@types/extensible_events");
25260
25031
  const location_1 = require("./@types/location");
@@ -25339,35 +25110,102 @@ function makeEmoteMessage(body) {
25339
25110
  };
25340
25111
  }
25341
25112
  exports.makeEmoteMessage = makeEmoteMessage;
25113
+ /** Location content helpers */
25114
+ const getTextForLocationEvent = (uri, assetType, timestamp, description) => {
25115
+ const date = `at ${new Date(timestamp).toISOString()}`;
25116
+ const assetName = assetType === location_1.LocationAssetType.Self ? 'User' : undefined;
25117
+ const quotedDescription = description ? `"${description}"` : undefined;
25118
+ return [
25119
+ assetName,
25120
+ 'Location',
25121
+ quotedDescription,
25122
+ uri,
25123
+ date,
25124
+ ].filter(Boolean).join(' ');
25125
+ };
25126
+ exports.getTextForLocationEvent = getTextForLocationEvent;
25342
25127
  /**
25343
25128
  * Generates the content for a Location event
25344
- * @param text a text for of our location
25345
25129
  * @param uri a geo:// uri for the location
25346
25130
  * @param ts the timestamp when the location was correct (milliseconds since
25347
25131
  * the UNIX epoch)
25348
25132
  * @param description the (optional) label for this location on the map
25349
25133
  * @param asset_type the (optional) asset type of this location e.g. "m.self"
25134
+ * @param text optional. A text for the location
25135
+ */
25136
+ const makeLocationContent = (
25137
+ // this is first but optional
25138
+ // to avoid a breaking change
25139
+ text, uri, timestamp, description, assetType) => {
25140
+ const defaultedText = text !== null && text !== void 0 ? text : (0, exports.getTextForLocationEvent)(uri, assetType || location_1.LocationAssetType.Self, timestamp, description);
25141
+ const timestampEvent = timestamp ? { [location_1.M_TIMESTAMP.name]: timestamp } : {};
25142
+ return Object.assign({ msgtype: event_1.MsgType.Location, body: defaultedText, geo_uri: uri, [location_1.M_LOCATION.name]: {
25143
+ description,
25144
+ uri,
25145
+ }, [location_1.M_ASSET.name]: {
25146
+ type: assetType || location_1.LocationAssetType.Self,
25147
+ }, [extensible_events_1.TEXT_NODE_TYPE.name]: defaultedText }, timestampEvent);
25148
+ };
25149
+ exports.makeLocationContent = makeLocationContent;
25150
+ /**
25151
+ * Parse location event content and transform to
25152
+ * a backwards compatible modern m.location event format
25153
+ */
25154
+ const parseLocationEvent = (wireEventContent) => {
25155
+ var _a, _b;
25156
+ const location = location_1.M_LOCATION.findIn(wireEventContent);
25157
+ const asset = location_1.M_ASSET.findIn(wireEventContent);
25158
+ const timestamp = location_1.M_TIMESTAMP.findIn(wireEventContent);
25159
+ const text = extensible_events_1.TEXT_NODE_TYPE.findIn(wireEventContent);
25160
+ const geoUri = (_a = location === null || location === void 0 ? void 0 : location.uri) !== null && _a !== void 0 ? _a : wireEventContent === null || wireEventContent === void 0 ? void 0 : wireEventContent.geo_uri;
25161
+ const description = location === null || location === void 0 ? void 0 : location.description;
25162
+ const assetType = (_b = asset === null || asset === void 0 ? void 0 : asset.type) !== null && _b !== void 0 ? _b : location_1.LocationAssetType.Self;
25163
+ const fallbackText = text !== null && text !== void 0 ? text : wireEventContent.body;
25164
+ return (0, exports.makeLocationContent)(fallbackText, geoUri, timestamp, description, assetType);
25165
+ };
25166
+ exports.parseLocationEvent = parseLocationEvent;
25167
+ const makeBeaconInfoContent = (timeout, isLive, description, assetType, timestamp) => ({
25168
+ [beacon_1.M_BEACON_INFO.name]: {
25169
+ description,
25170
+ timeout,
25171
+ live: isLive,
25172
+ },
25173
+ [location_1.M_TIMESTAMP.name]: timestamp || Date.now(),
25174
+ [location_1.M_ASSET.name]: {
25175
+ type: assetType !== null && assetType !== void 0 ? assetType : location_1.LocationAssetType.Self,
25176
+ },
25177
+ });
25178
+ exports.makeBeaconInfoContent = makeBeaconInfoContent;
25179
+ /**
25180
+ * Flatten beacon info event content
25350
25181
  */
25351
- function makeLocationContent(text, uri, ts, description, assetType) {
25182
+ const parseBeaconInfoContent = (content) => {
25183
+ const { description, timeout, live } = beacon_1.M_BEACON_INFO.findIn(content);
25184
+ const { type: assetType } = location_1.M_ASSET.findIn(content);
25185
+ const timestamp = location_1.M_TIMESTAMP.findIn(content);
25352
25186
  return {
25353
- "body": text,
25354
- "msgtype": event_1.MsgType.Location,
25355
- "geo_uri": uri,
25356
- [location_1.LOCATION_EVENT_TYPE.name]: {
25357
- uri,
25358
- description,
25359
- },
25360
- [location_1.ASSET_NODE_TYPE.name]: {
25361
- type: assetType !== null && assetType !== void 0 ? assetType : location_1.LocationAssetType.Self,
25362
- },
25363
- [extensible_events_1.TEXT_NODE_TYPE.name]: text,
25364
- [location_1.TIMESTAMP_NODE_TYPE.name]: ts,
25365
- // TODO: MSC1767 fallbacks m.image thumbnail
25187
+ description,
25188
+ timeout,
25189
+ live,
25190
+ assetType,
25191
+ timestamp,
25366
25192
  };
25367
- }
25368
- exports.makeLocationContent = makeLocationContent;
25193
+ };
25194
+ exports.parseBeaconInfoContent = parseBeaconInfoContent;
25195
+ const makeBeaconContent = (uri, timestamp, beaconInfoId, description) => ({
25196
+ [location_1.M_LOCATION.name]: {
25197
+ description,
25198
+ uri,
25199
+ },
25200
+ [location_1.M_TIMESTAMP.name]: timestamp,
25201
+ "m.relates_to": {
25202
+ rel_type: matrix_events_sdk_1.REFERENCE_RELATION.name,
25203
+ event_id: beaconInfoId,
25204
+ },
25205
+ });
25206
+ exports.makeBeaconContent = makeBeaconContent;
25369
25207
 
25370
- },{"./@types/event":77,"./@types/extensible_events":78,"./@types/location":79}],89:[function(require,module,exports){
25208
+ },{"./@types/beacon":77,"./@types/event":78,"./@types/extensible_events":79,"./@types/location":80,"matrix-events-sdk":49}],90:[function(require,module,exports){
25371
25209
  "use strict";
25372
25210
  /*
25373
25211
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -25463,7 +25301,7 @@ function getHttpUriForMxc(baseUrl, mxc, width, height, resizeMethod, allowDirect
25463
25301
  }
25464
25302
  exports.getHttpUriForMxc = getHttpUriForMxc;
25465
25303
 
25466
- },{"./utils":162}],90:[function(require,module,exports){
25304
+ },{"./utils":163}],91:[function(require,module,exports){
25467
25305
  (function (global,Buffer){(function (){
25468
25306
  "use strict";
25469
25307
  /*
@@ -26201,7 +26039,7 @@ exports.requestKeysDuringVerification = requestKeysDuringVerification;
26201
26039
 
26202
26040
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
26203
26041
 
26204
- },{"../crypto/store/indexeddb-crypto-store":111,"../logger":129,"./aes":97,"./olmlib":108,"buffer":21}],91:[function(require,module,exports){
26042
+ },{"../crypto/store/indexeddb-crypto-store":112,"../logger":130,"./aes":98,"./olmlib":109,"buffer":21}],92:[function(require,module,exports){
26205
26043
  "use strict";
26206
26044
  /*
26207
26045
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -27081,7 +26919,7 @@ function storeDeviceKeys(olmDevice, userStore, deviceResult) {
27081
26919
  });
27082
26920
  }
27083
26921
 
27084
- },{"../logger":129,"../models/typed-event-emitter":146,"../utils":162,"./CrossSigning":90,"./deviceinfo":105,"./index":106,"./olmlib":108,"./store/indexeddb-crypto-store":111}],92:[function(require,module,exports){
26922
+ },{"../logger":130,"../models/typed-event-emitter":147,"../utils":163,"./CrossSigning":91,"./deviceinfo":106,"./index":107,"./olmlib":109,"./store/indexeddb-crypto-store":112}],93:[function(require,module,exports){
27085
26923
  "use strict";
27086
26924
  /*
27087
26925
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -27432,7 +27270,7 @@ class SSSSCryptoCallbacks {
27432
27270
  }
27433
27271
  }
27434
27272
 
27435
- },{"../http-api":126,"../logger":129,"../matrix":130,"../models/event":137,"../models/typed-event-emitter":146,"./CrossSigning":90,"./store/indexeddb-crypto-store":111}],93:[function(require,module,exports){
27273
+ },{"../http-api":127,"../logger":130,"../matrix":131,"../models/event":139,"../models/typed-event-emitter":147,"./CrossSigning":91,"./store/indexeddb-crypto-store":112}],94:[function(require,module,exports){
27436
27274
  (function (global){(function (){
27437
27275
  "use strict";
27438
27276
  /*
@@ -28675,7 +28513,7 @@ function calculateWithheldMessage(withheld) {
28675
28513
 
28676
28514
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
28677
28515
 
28678
- },{"../logger":129,"./algorithms":99,"./store/indexeddb-crypto-store":111}],94:[function(require,module,exports){
28516
+ },{"../logger":130,"./algorithms":100,"./store/indexeddb-crypto-store":112}],95:[function(require,module,exports){
28679
28517
  "use strict";
28680
28518
  /*
28681
28519
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -29097,7 +28935,7 @@ function stringifyRecipientList(recipients) {
29097
28935
  + ']';
29098
28936
  }
29099
28937
 
29100
- },{"../@types/event":77,"../logger":129}],95:[function(require,module,exports){
28938
+ },{"../@types/event":78,"../logger":130}],96:[function(require,module,exports){
29101
28939
  "use strict";
29102
28940
  /*
29103
28941
  Copyright 2018 - 2021 The Matrix.org Foundation C.I.C.
@@ -29165,7 +29003,7 @@ class RoomList {
29165
29003
  }
29166
29004
  exports.RoomList = RoomList;
29167
29005
 
29168
- },{"./store/indexeddb-crypto-store":111}],96:[function(require,module,exports){
29006
+ },{"./store/indexeddb-crypto-store":112}],97:[function(require,module,exports){
29169
29007
  "use strict";
29170
29008
  /*
29171
29009
  Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
@@ -29703,7 +29541,7 @@ class SecretStorage {
29703
29541
  }
29704
29542
  exports.SecretStorage = SecretStorage;
29705
29543
 
29706
- },{"../logger":129,"../matrix":130,"../randomstring":149,"./aes":97,"./olmlib":108}],97:[function(require,module,exports){
29544
+ },{"../logger":130,"../matrix":131,"../randomstring":150,"./aes":98,"./olmlib":109}],98:[function(require,module,exports){
29707
29545
  (function (Buffer){(function (){
29708
29546
  "use strict";
29709
29547
  /*
@@ -29924,7 +29762,7 @@ exports.calculateKeyCheck = calculateKeyCheck;
29924
29762
 
29925
29763
  }).call(this)}).call(this,require("buffer").Buffer)
29926
29764
 
29927
- },{"../utils":162,"./olmlib":108,"buffer":21}],98:[function(require,module,exports){
29765
+ },{"../utils":163,"./olmlib":109,"buffer":21}],99:[function(require,module,exports){
29928
29766
  "use strict";
29929
29767
  /*
29930
29768
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -30147,7 +29985,7 @@ function registerAlgorithm(algorithm, encryptor, decryptor) {
30147
29985
  }
30148
29986
  exports.registerAlgorithm = registerAlgorithm;
30149
29987
 
30150
- },{}],99:[function(require,module,exports){
29988
+ },{}],100:[function(require,module,exports){
30151
29989
  "use strict";
30152
29990
  /*
30153
29991
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -30182,7 +30020,7 @@ require("./olm");
30182
30020
  require("./megolm");
30183
30021
  __exportStar(require("./base"), exports);
30184
30022
 
30185
- },{"./base":98,"./megolm":100,"./olm":101}],100:[function(require,module,exports){
30023
+ },{"./base":99,"./megolm":101,"./olm":102}],101:[function(require,module,exports){
30186
30024
  "use strict";
30187
30025
  /*
30188
30026
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -30721,6 +30559,7 @@ class MegolmEncryption extends base_1.EncryptionAlgorithm {
30721
30559
  contentMap[userId][deviceId] = message;
30722
30560
  }
30723
30561
  yield this.baseApis.sendToDevice("org.matrix.room_key.withheld", contentMap);
30562
+ yield this.baseApis.sendToDevice("m.room_key.withheld", contentMap);
30724
30563
  // record the fact that we notified these blocked devices
30725
30564
  for (const userId of Object.keys(contentMap)) {
30726
30565
  for (const deviceId of Object.keys(contentMap[userId])) {
@@ -31637,7 +31476,7 @@ const PROBLEM_DESCRIPTIONS = {
31637
31476
  };
31638
31477
  (0, base_1.registerAlgorithm)(olmlib.MEGOLM_ALGORITHM, MegolmEncryption, MegolmDecryption);
31639
31478
 
31640
- },{"../../logger":129,"../OlmDevice":93,"../olmlib":108,"./base":98}],101:[function(require,module,exports){
31479
+ },{"../../logger":130,"../OlmDevice":94,"../olmlib":109,"./base":99}],102:[function(require,module,exports){
31641
31480
  "use strict";
31642
31481
  /*
31643
31482
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -31941,7 +31780,7 @@ class OlmDecryption extends base_1.DecryptionAlgorithm {
31941
31780
  }
31942
31781
  (0, base_1.registerAlgorithm)(olmlib.OLM_ALGORITHM, OlmEncryption, OlmDecryption);
31943
31782
 
31944
- },{"../../logger":129,"../deviceinfo":105,"../olmlib":108,"./base":98}],102:[function(require,module,exports){
31783
+ },{"../../logger":130,"../deviceinfo":106,"../olmlib":109,"./base":99}],103:[function(require,module,exports){
31945
31784
  "use strict";
31946
31785
  /*
31947
31786
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -31968,7 +31807,7 @@ var CrossSigningKey;
31968
31807
  CrossSigningKey["UserSigning"] = "user_signing";
31969
31808
  })(CrossSigningKey = exports.CrossSigningKey || (exports.CrossSigningKey = {}));
31970
31809
 
31971
- },{}],103:[function(require,module,exports){
31810
+ },{}],104:[function(require,module,exports){
31972
31811
  (function (global){(function (){
31973
31812
  "use strict";
31974
31813
  /*
@@ -32662,7 +32501,7 @@ exports.DefaultAlgorithm = Curve25519;
32662
32501
 
32663
32502
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
32664
32503
 
32665
- },{"../NamespacedValue":83,"../client":87,"../logger":129,"../utils":162,"./aes":97,"./index":106,"./key_passphrase":107,"./olmlib":108,"./recoverykey":109,"./store/indexeddb-crypto-store":111}],104:[function(require,module,exports){
32504
+ },{"../NamespacedValue":84,"../client":88,"../logger":130,"../utils":163,"./aes":98,"./index":107,"./key_passphrase":108,"./olmlib":109,"./recoverykey":110,"./store/indexeddb-crypto-store":112}],105:[function(require,module,exports){
32666
32505
  (function (global,Buffer){(function (){
32667
32506
  "use strict";
32668
32507
  /*
@@ -32897,7 +32736,7 @@ exports.DehydrationManager = DehydrationManager;
32897
32736
 
32898
32737
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
32899
32738
 
32900
- },{"../crypto/store/indexeddb-crypto-store":111,"../http-api":126,"../logger":129,"./aes":97,"./olmlib":108,"another-json":14,"buffer":21}],105:[function(require,module,exports){
32739
+ },{"../crypto/store/indexeddb-crypto-store":112,"../http-api":127,"../logger":130,"./aes":98,"./olmlib":109,"another-json":14,"buffer":21}],106:[function(require,module,exports){
32901
32740
  "use strict";
32902
32741
  /*
32903
32742
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -33054,7 +32893,7 @@ DeviceInfo.DeviceVerification = {
33054
32893
  BLOCKED: DeviceVerification.Blocked,
33055
32894
  };
33056
32895
 
33057
- },{}],106:[function(require,module,exports){
32896
+ },{}],107:[function(require,module,exports){
33058
32897
  (function (global,Buffer){(function (){
33059
32898
  "use strict";
33060
32899
  /*
@@ -33325,7 +33164,8 @@ class Crypto extends typed_event_emitter_1.TypedEventEmitter {
33325
33164
  else if (event.getType() === "m.secret.send") {
33326
33165
  this.secretStorage.onSecretReceived(event);
33327
33166
  }
33328
- else if (event.getType() === "org.matrix.room_key.withheld") {
33167
+ else if (event.getType() === "m.room_key.withheld"
33168
+ || event.getType() === "org.matrix.room_key.withheld") {
33329
33169
  this.onRoomKeyWithheldEvent(event);
33330
33170
  }
33331
33171
  else if (event.getContent().transaction_id) {
@@ -33832,7 +33672,7 @@ class Crypto extends typed_event_emitter_1.TypedEventEmitter {
33832
33672
  // secrets using it, in theory. We could move them to the new key but a)
33833
33673
  // that would mean we'd need to prompt for the old passphrase, and b)
33834
33674
  // it's not clear that would be the right thing to do anyway.
33835
- const { keyInfo, privateKey } = yield createSecretStorageKey();
33675
+ const { keyInfo = {}, privateKey } = yield createSecretStorageKey();
33836
33676
  newKeyId = yield createSSSS(keyInfo, privateKey);
33837
33677
  }
33838
33678
  else if (!storageExists && keyBackupInfo) {
@@ -36254,7 +36094,7 @@ class IncomingRoomKeyRequestCancellation {
36254
36094
 
36255
36095
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
36256
36096
 
36257
- },{"../ReEmitter":84,"../client":87,"../errors":122,"../logger":129,"../models/event":137,"../models/room":143,"../models/room-member":140,"../models/typed-event-emitter":146,"./CrossSigning":90,"./DeviceList":91,"./EncryptionSetup":92,"./OlmDevice":93,"./OutgoingRoomKeyRequestManager":94,"./SecretStorage":96,"./aes":97,"./algorithms":99,"./backup":103,"./dehydration":104,"./deviceinfo":105,"./key_passphrase":107,"./olmlib":108,"./recoverykey":109,"./store/indexeddb-crypto-store":111,"./verification/IllegalMethod":116,"./verification/QRCode":117,"./verification/SAS":118,"./verification/request/InRoomChannel":119,"./verification/request/ToDeviceChannel":120,"./verification/request/VerificationRequest":121,"another-json":14,"buffer":21}],107:[function(require,module,exports){
36097
+ },{"../ReEmitter":85,"../client":88,"../errors":123,"../logger":130,"../models/event":139,"../models/room":144,"../models/room-member":141,"../models/typed-event-emitter":147,"./CrossSigning":91,"./DeviceList":92,"./EncryptionSetup":93,"./OlmDevice":94,"./OutgoingRoomKeyRequestManager":95,"./SecretStorage":97,"./aes":98,"./algorithms":100,"./backup":104,"./dehydration":105,"./deviceinfo":106,"./key_passphrase":108,"./olmlib":109,"./recoverykey":110,"./store/indexeddb-crypto-store":112,"./verification/IllegalMethod":117,"./verification/QRCode":118,"./verification/SAS":119,"./verification/request/InRoomChannel":120,"./verification/request/ToDeviceChannel":121,"./verification/request/VerificationRequest":122,"another-json":14,"buffer":21}],108:[function(require,module,exports){
36258
36098
  (function (global,Buffer){(function (){
36259
36099
  "use strict";
36260
36100
  /*
@@ -36350,7 +36190,7 @@ function deriveKeyNode(password, salt, iterations, numBits) {
36350
36190
 
36351
36191
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
36352
36192
 
36353
- },{"../randomstring":149,"../utils":162,"buffer":21}],108:[function(require,module,exports){
36193
+ },{"../randomstring":150,"../utils":163,"buffer":21}],109:[function(require,module,exports){
36354
36194
  (function (global,Buffer){(function (){
36355
36195
  "use strict";
36356
36196
  /*
@@ -36859,7 +36699,7 @@ exports.decodeBase64 = decodeBase64;
36859
36699
 
36860
36700
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
36861
36701
 
36862
- },{"../logger":129,"another-json":14,"buffer":21}],109:[function(require,module,exports){
36702
+ },{"../logger":130,"another-json":14,"buffer":21}],110:[function(require,module,exports){
36863
36703
  (function (global,Buffer){(function (){
36864
36704
  "use strict";
36865
36705
  /*
@@ -36923,7 +36763,7 @@ exports.decodeRecoveryKey = decodeRecoveryKey;
36923
36763
 
36924
36764
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
36925
36765
 
36926
- },{"bs58":20,"buffer":21}],110:[function(require,module,exports){
36766
+ },{"bs58":20,"buffer":21}],111:[function(require,module,exports){
36927
36767
  "use strict";
36928
36768
  /*
36929
36769
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -37826,7 +37666,7 @@ function promiseifyTxn(txn) {
37826
37666
  });
37827
37667
  }
37828
37668
 
37829
- },{"../../logger":129,"../../utils":162}],111:[function(require,module,exports){
37669
+ },{"../../logger":130,"../../utils":163}],112:[function(require,module,exports){
37830
37670
  (function (global){(function (){
37831
37671
  "use strict";
37832
37672
  /*
@@ -38398,7 +38238,7 @@ IndexedDBCryptoStore.STORE_BACKUP = 'sessions_needing_backup';
38398
38238
 
38399
38239
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
38400
38240
 
38401
- },{"../../errors":122,"../../indexeddb-helpers":127,"../../logger":129,"./indexeddb-crypto-store-backend":110,"./localStorage-crypto-store":112,"./memory-crypto-store":113}],112:[function(require,module,exports){
38241
+ },{"../../errors":123,"../../indexeddb-helpers":128,"../../logger":130,"./indexeddb-crypto-store-backend":111,"./localStorage-crypto-store":113,"./memory-crypto-store":114}],113:[function(require,module,exports){
38402
38242
  "use strict";
38403
38243
  /*
38404
38244
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -38648,7 +38488,7 @@ class LocalStorageCryptoStore extends memory_crypto_store_1.MemoryCryptoStore {
38648
38488
  sessionData: sessionData,
38649
38489
  });
38650
38490
  });
38651
- if (limit && session.length >= limit) {
38491
+ if (limit && sessions.length >= limit) {
38652
38492
  break;
38653
38493
  }
38654
38494
  }
@@ -38727,7 +38567,7 @@ function setJsonItem(store, key, val) {
38727
38567
  store.setItem(key, JSON.stringify(val));
38728
38568
  }
38729
38569
 
38730
- },{"../../logger":129,"./memory-crypto-store":113}],113:[function(require,module,exports){
38570
+ },{"../../logger":130,"./memory-crypto-store":114}],114:[function(require,module,exports){
38731
38571
  "use strict";
38732
38572
  /*
38733
38573
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -39165,7 +39005,7 @@ class MemoryCryptoStore {
39165
39005
  }
39166
39006
  exports.MemoryCryptoStore = MemoryCryptoStore;
39167
39007
 
39168
- },{"../../logger":129,"../../utils":162}],114:[function(require,module,exports){
39008
+ },{"../../logger":130,"../../utils":163}],115:[function(require,module,exports){
39169
39009
  "use strict";
39170
39010
  /*
39171
39011
  Copyright 2018 New Vector Ltd
@@ -39501,7 +39341,7 @@ class VerificationBase extends typed_event_emitter_1.TypedEventEmitter {
39501
39341
  }
39502
39342
  exports.VerificationBase = VerificationBase;
39503
39343
 
39504
- },{"../../logger":129,"../../models/event":137,"../../models/typed-event-emitter":146,"../CrossSigning":90,"../deviceinfo":105,"./Error":115}],115:[function(require,module,exports){
39344
+ },{"../../logger":130,"../../models/event":139,"../../models/typed-event-emitter":147,"../CrossSigning":91,"../deviceinfo":106,"./Error":116}],116:[function(require,module,exports){
39505
39345
  "use strict";
39506
39346
  /*
39507
39347
  Copyright 2018 - 2021 The Matrix.org Foundation C.I.C.
@@ -39584,7 +39424,7 @@ function errorFromEvent(event) {
39584
39424
  }
39585
39425
  exports.errorFromEvent = errorFromEvent;
39586
39426
 
39587
- },{"../../models/event":137}],116:[function(require,module,exports){
39427
+ },{"../../models/event":139}],117:[function(require,module,exports){
39588
39428
  "use strict";
39589
39429
  /*
39590
39430
  Copyright 2020 The Matrix.org Foundation C.I.C.
@@ -39641,7 +39481,7 @@ class IllegalMethod extends Base_1.VerificationBase {
39641
39481
  }
39642
39482
  exports.IllegalMethod = IllegalMethod;
39643
39483
 
39644
- },{"./Base":114}],117:[function(require,module,exports){
39484
+ },{"./Base":115}],118:[function(require,module,exports){
39645
39485
  (function (global,Buffer){(function (){
39646
39486
  "use strict";
39647
39487
  /*
@@ -39921,7 +39761,7 @@ exports.QRCodeData = QRCodeData;
39921
39761
 
39922
39762
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
39923
39763
 
39924
- },{"../../logger":129,"../olmlib":108,"./Base":114,"./Error":115,"buffer":21}],118:[function(require,module,exports){
39764
+ },{"../../logger":130,"../olmlib":109,"./Base":115,"./Error":116,"buffer":21}],119:[function(require,module,exports){
39925
39765
  (function (global){(function (){
39926
39766
  "use strict";
39927
39767
  /*
@@ -40396,7 +40236,7 @@ exports.SAS = SAS;
40396
40236
 
40397
40237
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
40398
40238
 
40399
- },{"../../logger":129,"./Base":114,"./Error":115,"another-json":14}],119:[function(require,module,exports){
40239
+ },{"../../logger":130,"./Base":115,"./Error":116,"another-json":14}],120:[function(require,module,exports){
40400
40240
  "use strict";
40401
40241
  /*
40402
40242
  Copyright 2018 New Vector Ltd
@@ -40743,7 +40583,7 @@ class InRoomRequests {
40743
40583
  }
40744
40584
  exports.InRoomRequests = InRoomRequests;
40745
40585
 
40746
- },{"../../../@types/event":77,"../../../logger":129,"./VerificationRequest":121}],120:[function(require,module,exports){
40586
+ },{"../../../@types/event":78,"../../../logger":130,"./VerificationRequest":122}],121:[function(require,module,exports){
40747
40587
  "use strict";
40748
40588
  /*
40749
40589
  Copyright 2018 New Vector Ltd
@@ -41076,7 +40916,7 @@ class ToDeviceRequests {
41076
40916
  }
41077
40917
  exports.ToDeviceRequests = ToDeviceRequests;
41078
40918
 
41079
- },{"../../../logger":129,"../../../models/event":137,"../../../randomstring":149,"../Error":115,"./VerificationRequest":121}],121:[function(require,module,exports){
40919
+ },{"../../../logger":130,"../../../models/event":139,"../../../randomstring":150,"../Error":116,"./VerificationRequest":122}],122:[function(require,module,exports){
41080
40920
  "use strict";
41081
40921
  /*
41082
40922
  Copyright 2018 - 2021 The Matrix.org Foundation C.I.C.
@@ -41920,7 +41760,7 @@ class VerificationRequest extends typed_event_emitter_1.TypedEventEmitter {
41920
41760
  }
41921
41761
  exports.VerificationRequest = VerificationRequest;
41922
41762
 
41923
- },{"../../../logger":129,"../../../models/typed-event-emitter":146,"../Error":115,"../QRCode":117}],122:[function(require,module,exports){
41763
+ },{"../../../logger":130,"../../../models/typed-event-emitter":147,"../Error":116,"../QRCode":118}],123:[function(require,module,exports){
41924
41764
  "use strict";
41925
41765
 
41926
41766
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -42009,7 +41849,7 @@ var KeySignatureUploadError = /*#__PURE__*/function (_Error) {
42009
41849
 
42010
41850
  exports.KeySignatureUploadError = KeySignatureUploadError;
42011
41851
 
42012
- },{"@babel/runtime/helpers/classCallCheck":2,"@babel/runtime/helpers/createClass":4,"@babel/runtime/helpers/getPrototypeOf":5,"@babel/runtime/helpers/inherits":6,"@babel/runtime/helpers/interopRequireDefault":7,"@babel/runtime/helpers/possibleConstructorReturn":10,"@babel/runtime/helpers/wrapNativeSuper":13}],123:[function(require,module,exports){
41852
+ },{"@babel/runtime/helpers/classCallCheck":2,"@babel/runtime/helpers/createClass":4,"@babel/runtime/helpers/getPrototypeOf":5,"@babel/runtime/helpers/inherits":6,"@babel/runtime/helpers/interopRequireDefault":7,"@babel/runtime/helpers/possibleConstructorReturn":10,"@babel/runtime/helpers/wrapNativeSuper":13}],124:[function(require,module,exports){
42013
41853
  "use strict";
42014
41854
  /*
42015
41855
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -42033,8 +41873,20 @@ function eventMapperFor(client, options) {
42033
41873
  const preventReEmit = Boolean(options.preventReEmit);
42034
41874
  const decrypt = options.decrypt !== false;
42035
41875
  function mapper(plainOldJsObject) {
42036
- const event = new event_1.MatrixEvent(plainOldJsObject);
42037
- const room = client.getRoom(event.getRoomId());
41876
+ const room = client.getRoom(plainOldJsObject.room_id);
41877
+ let event;
41878
+ // If the event is already known to the room, let's re-use the model rather than duplicating.
41879
+ // We avoid doing this to state events as they may be forward or backwards looking which tweaks behaviour.
41880
+ if (room && plainOldJsObject.state_key === undefined) {
41881
+ event = room.findEventById(plainOldJsObject.event_id);
41882
+ }
41883
+ if (!event || event.status) {
41884
+ event = new event_1.MatrixEvent(plainOldJsObject);
41885
+ }
41886
+ else {
41887
+ // merge the latest unsigned data from the server
41888
+ event.setUnsigned(Object.assign(Object.assign({}, event.getUnsigned()), plainOldJsObject.unsigned));
41889
+ }
42038
41890
  if (room === null || room === void 0 ? void 0 : room.threads.has(event.getId())) {
42039
41891
  event.setThread(room.threads.get(event.getId()));
42040
41892
  }
@@ -42060,7 +41912,7 @@ function eventMapperFor(client, options) {
42060
41912
  }
42061
41913
  exports.eventMapperFor = eventMapperFor;
42062
41914
 
42063
- },{"./models/event":137}],124:[function(require,module,exports){
41915
+ },{"./models/event":139}],125:[function(require,module,exports){
42064
41916
  "use strict";
42065
41917
  /*
42066
41918
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -42079,8 +41931,7 @@ limitations under the License.
42079
41931
  */
42080
41932
  Object.defineProperty(exports, "__esModule", { value: true });
42081
41933
  exports.FilterComponent = void 0;
42082
- const event_1 = require("./@types/event");
42083
- const filter_1 = require("./filter");
41934
+ const thread_1 = require("./models/thread");
42084
41935
  /**
42085
41936
  * @module filter-component
42086
41937
  */
@@ -42132,7 +41983,7 @@ class FilterComponent {
42132
41983
  // of performance
42133
41984
  // This should be improved when bundled relationships solve that problem
42134
41985
  const relationSenders = [];
42135
- if (this.userId && ((_b = bundledRelationships === null || bundledRelationships === void 0 ? void 0 : bundledRelationships[event_1.RelationType.Thread]) === null || _b === void 0 ? void 0 : _b.current_user_participated)) {
41986
+ if (this.userId && ((_b = bundledRelationships === null || bundledRelationships === void 0 ? void 0 : bundledRelationships[thread_1.THREAD_RELATION_TYPE.name]) === null || _b === void 0 ? void 0 : _b.current_user_participated)) {
42136
41987
  relationSenders.push(this.userId);
42137
41988
  }
42138
41989
  return this.checkFields(event.getRoomId(), event.getSender(), event.getType(), event.getContent() ? event.getContent().url !== undefined : false, relations, relationSenders);
@@ -42142,15 +41993,15 @@ class FilterComponent {
42142
41993
  */
42143
41994
  toJSON() {
42144
41995
  return {
42145
- types: this.filterJson.types || null,
42146
- not_types: this.filterJson.not_types || [],
42147
- rooms: this.filterJson.rooms || null,
42148
- not_rooms: this.filterJson.not_rooms || [],
42149
- senders: this.filterJson.senders || null,
42150
- not_senders: this.filterJson.not_senders || [],
42151
- contains_url: this.filterJson.contains_url || null,
42152
- [filter_1.UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: filter_1.UNSTABLE_FILTER_RELATED_BY_SENDERS.findIn(this.filterJson),
42153
- [filter_1.UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: filter_1.UNSTABLE_FILTER_RELATED_BY_REL_TYPES.findIn(this.filterJson),
41996
+ "types": this.filterJson.types || null,
41997
+ "not_types": this.filterJson.not_types || [],
41998
+ "rooms": this.filterJson.rooms || null,
41999
+ "not_rooms": this.filterJson.not_rooms || [],
42000
+ "senders": this.filterJson.senders || null,
42001
+ "not_senders": this.filterJson.not_senders || [],
42002
+ "contains_url": this.filterJson.contains_url || null,
42003
+ [thread_1.FILTER_RELATED_BY_SENDERS.name]: this.filterJson[thread_1.FILTER_RELATED_BY_SENDERS.name] || [],
42004
+ [thread_1.FILTER_RELATED_BY_REL_TYPES.name]: this.filterJson[thread_1.FILTER_RELATED_BY_REL_TYPES.name] || [],
42154
42005
  };
42155
42006
  }
42156
42007
  /**
@@ -42192,13 +42043,13 @@ class FilterComponent {
42192
42043
  if (containsUrlFilter !== undefined && containsUrlFilter !== containsUrl) {
42193
42044
  return false;
42194
42045
  }
42195
- const relationTypesFilter = this.filterJson[filter_1.UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name];
42046
+ const relationTypesFilter = this.filterJson[thread_1.FILTER_RELATED_BY_REL_TYPES.name];
42196
42047
  if (relationTypesFilter !== undefined) {
42197
42048
  if (!this.arrayMatchesFilter(relationTypesFilter, relationTypes)) {
42198
42049
  return false;
42199
42050
  }
42200
42051
  }
42201
- const relationSendersFilter = this.filterJson[filter_1.UNSTABLE_FILTER_RELATED_BY_SENDERS.name];
42052
+ const relationSendersFilter = this.filterJson[thread_1.FILTER_RELATED_BY_SENDERS.name];
42202
42053
  if (relationSendersFilter !== undefined) {
42203
42054
  if (!this.arrayMatchesFilter(relationSendersFilter, relationSenders)) {
42204
42055
  return false;
@@ -42207,8 +42058,8 @@ class FilterComponent {
42207
42058
  return true;
42208
42059
  }
42209
42060
  arrayMatchesFilter(filter, values) {
42210
- return values.length > 0 && values.every(value => {
42211
- return filter.includes(value);
42061
+ return values.length > 0 && filter.every(value => {
42062
+ return values.includes(value);
42212
42063
  });
42213
42064
  }
42214
42065
  /**
@@ -42230,7 +42081,7 @@ class FilterComponent {
42230
42081
  }
42231
42082
  exports.FilterComponent = FilterComponent;
42232
42083
 
42233
- },{"./@types/event":77,"./filter":125}],125:[function(require,module,exports){
42084
+ },{"./models/thread":146}],126:[function(require,module,exports){
42234
42085
  "use strict";
42235
42086
  /*
42236
42087
  Copyright 2015 - 2021 Matrix.org Foundation C.I.C.
@@ -42248,11 +42099,8 @@ See the License for the specific language governing permissions and
42248
42099
  limitations under the License.
42249
42100
  */
42250
42101
  Object.defineProperty(exports, "__esModule", { value: true });
42251
- exports.Filter = exports.UNSTABLE_FILTER_RELATED_BY_REL_TYPES = exports.UNSTABLE_FILTER_RELATED_BY_SENDERS = void 0;
42102
+ exports.Filter = void 0;
42252
42103
  const filter_component_1 = require("./filter-component");
42253
- const NamespacedValue_1 = require("./NamespacedValue");
42254
- exports.UNSTABLE_FILTER_RELATED_BY_SENDERS = new NamespacedValue_1.UnstableValue("related_by_senders", "io.element.relation_senders");
42255
- exports.UNSTABLE_FILTER_RELATED_BY_REL_TYPES = new NamespacedValue_1.UnstableValue("related_by_rel_types", "io.element.relation_types");
42256
42104
  /**
42257
42105
  * @param {Object} obj
42258
42106
  * @param {string} keyNesting
@@ -42413,7 +42261,7 @@ Filter.LAZY_LOADING_MESSAGES_FILTER = {
42413
42261
  lazy_load_members: true,
42414
42262
  };
42415
42263
 
42416
- },{"./NamespacedValue":83,"./filter-component":124}],126:[function(require,module,exports){
42264
+ },{"./filter-component":125}],127:[function(require,module,exports){
42417
42265
  (function (global){(function (){
42418
42266
  "use strict";
42419
42267
  /*
@@ -43289,7 +43137,6 @@ exports.MatrixError = MatrixError;
43289
43137
  class ConnectionError extends Error {
43290
43138
  constructor(message, cause = undefined) {
43291
43139
  super(message + (cause ? `: ${cause.message}` : ""));
43292
- this.cause = cause;
43293
43140
  }
43294
43141
  get name() {
43295
43142
  return "ConnectionError";
@@ -43343,7 +43190,7 @@ exports.retryNetworkOperation = retryNetworkOperation;
43343
43190
 
43344
43191
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
43345
43192
 
43346
- },{"./logger":129,"./realtime-callbacks":150,"./utils":162,"content-type":24}],127:[function(require,module,exports){
43193
+ },{"./logger":130,"./realtime-callbacks":151,"./utils":163,"content-type":24}],128:[function(require,module,exports){
43347
43194
  "use strict";
43348
43195
  /*
43349
43196
  Copyright 2019 New Vector Ltd
@@ -43398,7 +43245,7 @@ function exists(indexedDB, dbName) {
43398
43245
  }
43399
43246
  exports.exists = exists;
43400
43247
 
43401
- },{}],128:[function(require,module,exports){
43248
+ },{}],129:[function(require,module,exports){
43402
43249
  "use strict";
43403
43250
  /*
43404
43251
  Copyright 2016 OpenMarket Ltd
@@ -43939,7 +43786,7 @@ class InteractiveAuth {
43939
43786
  }
43940
43787
  exports.InteractiveAuth = InteractiveAuth;
43941
43788
 
43942
- },{"./logger":129,"./utils":162}],129:[function(require,module,exports){
43789
+ },{"./logger":130,"./utils":163}],130:[function(require,module,exports){
43943
43790
  "use strict";
43944
43791
  /*
43945
43792
  Copyright 2018 André Jaenisch
@@ -44023,7 +43870,7 @@ function getPrefixedLogger(prefix) {
44023
43870
  return prefixLogger;
44024
43871
  }
44025
43872
 
44026
- },{"loglevel":33}],130:[function(require,module,exports){
43873
+ },{"loglevel":33}],131:[function(require,module,exports){
44027
43874
  (function (global){(function (){
44028
43875
  "use strict";
44029
43876
  /*
@@ -44074,9 +43921,9 @@ __exportStar(require("./http-api"), exports);
44074
43921
  __exportStar(require("./autodiscovery"), exports);
44075
43922
  __exportStar(require("./sync-accumulator"), exports);
44076
43923
  __exportStar(require("./errors"), exports);
43924
+ __exportStar(require("./models/beacon"), exports);
44077
43925
  __exportStar(require("./models/event"), exports);
44078
43926
  __exportStar(require("./models/room"), exports);
44079
- __exportStar(require("./models/group"), exports);
44080
43927
  __exportStar(require("./models/event-timeline"), exports);
44081
43928
  __exportStar(require("./models/event-timeline-set"), exports);
44082
43929
  __exportStar(require("./models/room-member"), exports);
@@ -44224,7 +44071,7 @@ exports.createClient = createClient;
44224
44071
 
44225
44072
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
44226
44073
 
44227
- },{"./@types/PushRules":76,"./@types/event":77,"./@types/partials":80,"./@types/requests":81,"./@types/search":82,"./autodiscovery":85,"./client":87,"./content-helpers":88,"./content-repo":89,"./crypto/store/indexeddb-crypto-store":111,"./crypto/store/memory-crypto-store":113,"./errors":122,"./filter":125,"./http-api":126,"./interactive-auth":128,"./models/event":137,"./models/event-timeline":136,"./models/event-timeline-set":135,"./models/group":138,"./models/room":143,"./models/room-member":140,"./models/room-state":141,"./models/room-summary":142,"./models/user":147,"./scheduler":151,"./service-types":152,"./store/indexeddb":155,"./store/memory":156,"./store/session/webstorage":157,"./sync-accumulator":159,"./timeline-window":161,"./webrtc/call":163}],131:[function(require,module,exports){
44074
+ },{"./@types/PushRules":76,"./@types/event":78,"./@types/partials":81,"./@types/requests":82,"./@types/search":83,"./autodiscovery":86,"./client":88,"./content-helpers":89,"./content-repo":90,"./crypto/store/indexeddb-crypto-store":112,"./crypto/store/memory-crypto-store":114,"./errors":123,"./filter":126,"./http-api":127,"./interactive-auth":129,"./models/beacon":134,"./models/event":139,"./models/event-timeline":138,"./models/event-timeline-set":137,"./models/room":144,"./models/room-member":141,"./models/room-state":142,"./models/room-summary":143,"./models/user":148,"./scheduler":152,"./service-types":153,"./store/indexeddb":156,"./store/memory":157,"./store/session/webstorage":158,"./sync-accumulator":160,"./timeline-window":162,"./webrtc/call":164}],132:[function(require,module,exports){
44228
44075
  "use strict";
44229
44076
  /*
44230
44077
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -44442,7 +44289,7 @@ class MSC3089Branch {
44442
44289
  }
44443
44290
  exports.MSC3089Branch = MSC3089Branch;
44444
44291
 
44445
- },{"../@types/event":77,"./event-timeline":136}],132:[function(require,module,exports){
44292
+ },{"../@types/event":78,"./event-timeline":138}],133:[function(require,module,exports){
44446
44293
  "use strict";
44447
44294
  /*
44448
44295
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -44962,7 +44809,114 @@ class MSC3089TreeSpace {
44962
44809
  }
44963
44810
  exports.MSC3089TreeSpace = MSC3089TreeSpace;
44964
44811
 
44965
- },{"../@types/event":77,"../crypto/algorithms/megolm":100,"../logger":129,"../utils":162,"./MSC3089Branch":131,"p-retry":57}],133:[function(require,module,exports){
44812
+ },{"../@types/event":78,"../crypto/algorithms/megolm":101,"../logger":130,"../utils":163,"./MSC3089Branch":132,"p-retry":57}],134:[function(require,module,exports){
44813
+ "use strict";
44814
+ /*
44815
+ Copyright 2022 The Matrix.org Foundation C.I.C.
44816
+
44817
+ Licensed under the Apache License, Version 2.0 (the "License");
44818
+ you may not use this file except in compliance with the License.
44819
+ You may obtain a copy of the License at
44820
+
44821
+ http://www.apache.org/licenses/LICENSE-2.0
44822
+
44823
+ Unless required by applicable law or agreed to in writing, software
44824
+ distributed under the License is distributed on an "AS IS" BASIS,
44825
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44826
+ See the License for the specific language governing permissions and
44827
+ limitations under the License.
44828
+ */
44829
+ Object.defineProperty(exports, "__esModule", { value: true });
44830
+ exports.Beacon = exports.isBeaconInfoEventType = exports.isTimestampInDuration = exports.BeaconEvent = void 0;
44831
+ const beacon_1 = require("../@types/beacon");
44832
+ const content_helpers_1 = require("../content-helpers");
44833
+ const typed_event_emitter_1 = require("./typed-event-emitter");
44834
+ var BeaconEvent;
44835
+ (function (BeaconEvent) {
44836
+ BeaconEvent["New"] = "Beacon.new";
44837
+ BeaconEvent["Update"] = "Beacon.update";
44838
+ BeaconEvent["LivenessChange"] = "Beacon.LivenessChange";
44839
+ BeaconEvent["Destroy"] = "Destroy";
44840
+ })(BeaconEvent = exports.BeaconEvent || (exports.BeaconEvent = {}));
44841
+ const isTimestampInDuration = (startTimestamp, durationMs, timestamp) => timestamp >= startTimestamp && startTimestamp + durationMs >= timestamp;
44842
+ exports.isTimestampInDuration = isTimestampInDuration;
44843
+ const isBeaconInfoEventType = (type) => type.startsWith(beacon_1.M_BEACON_INFO.name) ||
44844
+ type.startsWith(beacon_1.M_BEACON_INFO.altName);
44845
+ exports.isBeaconInfoEventType = isBeaconInfoEventType;
44846
+ // https://github.com/matrix-org/matrix-spec-proposals/pull/3489
44847
+ class Beacon extends typed_event_emitter_1.TypedEventEmitter {
44848
+ constructor(rootEvent) {
44849
+ super();
44850
+ this.rootEvent = rootEvent;
44851
+ this.setBeaconInfo(this.rootEvent);
44852
+ this.roomId = this.rootEvent.getRoomId();
44853
+ }
44854
+ get isLive() {
44855
+ return this._isLive;
44856
+ }
44857
+ get identifier() {
44858
+ return this.beaconInfoEventType;
44859
+ }
44860
+ get beaconInfoId() {
44861
+ return this.rootEvent.getId();
44862
+ }
44863
+ get beaconInfoOwner() {
44864
+ return this.rootEvent.getStateKey();
44865
+ }
44866
+ get beaconInfoEventType() {
44867
+ return this.rootEvent.getType();
44868
+ }
44869
+ get beaconInfo() {
44870
+ return this._beaconInfo;
44871
+ }
44872
+ update(beaconInfoEvent) {
44873
+ if (beaconInfoEvent.getType() !== this.beaconInfoEventType) {
44874
+ throw new Error('Invalid updating event');
44875
+ }
44876
+ this.rootEvent = beaconInfoEvent;
44877
+ this.setBeaconInfo(this.rootEvent);
44878
+ this.emit(BeaconEvent.Update, beaconInfoEvent, this);
44879
+ }
44880
+ destroy() {
44881
+ if (this.livenessWatchInterval) {
44882
+ clearInterval(this.livenessWatchInterval);
44883
+ }
44884
+ this._isLive = false;
44885
+ this.emit(BeaconEvent.Destroy, this.identifier);
44886
+ }
44887
+ /**
44888
+ * Monitor liveness of a beacon
44889
+ * Emits BeaconEvent.LivenessChange when beacon expires
44890
+ */
44891
+ monitorLiveness() {
44892
+ var _a, _b;
44893
+ if (this.livenessWatchInterval) {
44894
+ clearInterval(this.livenessWatchInterval);
44895
+ }
44896
+ if (this.isLive) {
44897
+ const expiryInMs = (((_a = this._beaconInfo) === null || _a === void 0 ? void 0 : _a.timestamp) + ((_b = this._beaconInfo) === null || _b === void 0 ? void 0 : _b.timeout) + 1) - Date.now();
44898
+ if (expiryInMs > 1) {
44899
+ this.livenessWatchInterval = setInterval(this.checkLiveness.bind(this), expiryInMs);
44900
+ }
44901
+ }
44902
+ }
44903
+ setBeaconInfo(event) {
44904
+ this._beaconInfo = (0, content_helpers_1.parseBeaconInfoContent)(event.getContent());
44905
+ this.checkLiveness();
44906
+ }
44907
+ checkLiveness() {
44908
+ var _a, _b, _c;
44909
+ const prevLiveness = this.isLive;
44910
+ this._isLive = ((_a = this._beaconInfo) === null || _a === void 0 ? void 0 : _a.live) &&
44911
+ (0, exports.isTimestampInDuration)((_b = this._beaconInfo) === null || _b === void 0 ? void 0 : _b.timestamp, (_c = this._beaconInfo) === null || _c === void 0 ? void 0 : _c.timeout, Date.now());
44912
+ if (prevLiveness !== this.isLive) {
44913
+ this.emit(BeaconEvent.LivenessChange, this.isLive, this);
44914
+ }
44915
+ }
44916
+ }
44917
+ exports.Beacon = Beacon;
44918
+
44919
+ },{"../@types/beacon":77,"../content-helpers":89,"./typed-event-emitter":147}],135:[function(require,module,exports){
44966
44920
  "use strict";
44967
44921
  /*
44968
44922
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -45001,6 +44955,7 @@ class EventContext {
45001
44955
  * @constructor
45002
44956
  */
45003
44957
  constructor(ourEvent) {
44958
+ this.ourEvent = ourEvent;
45004
44959
  this.ourEventIndex = 0;
45005
44960
  this.paginateTokens = {
45006
44961
  [event_timeline_1.Direction.Backward]: null,
@@ -45076,7 +45031,7 @@ class EventContext {
45076
45031
  }
45077
45032
  exports.EventContext = EventContext;
45078
45033
 
45079
- },{"./event-timeline":136}],134:[function(require,module,exports){
45034
+ },{"./event-timeline":138}],136:[function(require,module,exports){
45080
45035
  "use strict";
45081
45036
  /*
45082
45037
  Copyright 2015 - 2022 The Matrix.org Foundation C.I.C.
@@ -45116,7 +45071,7 @@ var EventStatus;
45116
45071
  EventStatus["CANCELLED"] = "cancelled";
45117
45072
  })(EventStatus = exports.EventStatus || (exports.EventStatus = {}));
45118
45073
 
45119
- },{}],135:[function(require,module,exports){
45074
+ },{}],137:[function(require,module,exports){
45120
45075
  "use strict";
45121
45076
  /*
45122
45077
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -45881,7 +45836,7 @@ exports.EventTimelineSet = EventTimelineSet;
45881
45836
  * @param {boolean} resetAllTimelines True if all timelines were reset.
45882
45837
  */
45883
45838
 
45884
- },{"../logger":129,"./event":137,"./event-timeline":136,"./relations":139,"./room":143,"./typed-event-emitter":146}],136:[function(require,module,exports){
45839
+ },{"../logger":130,"./event":139,"./event-timeline":138,"./relations":140,"./room":144,"./typed-event-emitter":147}],138:[function(require,module,exports){
45885
45840
  "use strict";
45886
45841
  /*
45887
45842
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -46273,7 +46228,7 @@ EventTimeline.BACKWARDS = Direction.Backward;
46273
46228
  */
46274
46229
  EventTimeline.FORWARDS = Direction.Forward;
46275
46230
 
46276
- },{"../@types/event":77,"./room-state":141}],137:[function(require,module,exports){
46231
+ },{"../@types/event":78,"./room-state":142}],139:[function(require,module,exports){
46277
46232
  "use strict";
46278
46233
  /*
46279
46234
  Copyright 2015 - 2022 The Matrix.org Foundation C.I.C.
@@ -46415,7 +46370,7 @@ class MatrixEvent extends typed_event_emitter_1.TypedEventEmitter {
46415
46370
  this.target = null;
46416
46371
  this.status = null;
46417
46372
  this.error = null;
46418
- this.forwardLooking = true;
46373
+ this.forwardLooking = true; // only state events may be backwards looking
46419
46374
  /* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
46420
46375
  * `Crypto` will set this the `VerificationRequest` for the event
46421
46376
  * so it can be easily accessed from the timeline.
@@ -46599,7 +46554,7 @@ class MatrixEvent extends typed_event_emitter_1.TypedEventEmitter {
46599
46554
  get threadRootId() {
46600
46555
  var _a, _b;
46601
46556
  const relatesTo = (_a = this.getWireContent()) === null || _a === void 0 ? void 0 : _a["m.relates_to"];
46602
- if ((relatesTo === null || relatesTo === void 0 ? void 0 : relatesTo.rel_type) === event_1.RelationType.Thread) {
46557
+ if ((relatesTo === null || relatesTo === void 0 ? void 0 : relatesTo.rel_type) === thread_1.THREAD_RELATION_TYPE.name) {
46603
46558
  return relatesTo.event_id;
46604
46559
  }
46605
46560
  else {
@@ -46618,7 +46573,7 @@ class MatrixEvent extends typed_event_emitter_1.TypedEventEmitter {
46618
46573
  get isThreadRoot() {
46619
46574
  var _a;
46620
46575
  const threadDetails = this
46621
- .getServerAggregatedRelation(event_1.RelationType.Thread);
46576
+ .getServerAggregatedRelation(thread_1.THREAD_RELATION_TYPE.name);
46622
46577
  // Bundled relationships only returned when the sync response is limited
46623
46578
  // hence us having to check both bundled relation and inspect the thread
46624
46579
  // model
@@ -47620,119 +47575,7 @@ const REDACT_KEEP_CONTENT_MAP = {
47620
47575
  * error occurred.
47621
47576
  */
47622
47577
 
47623
- },{"../@types/event":77,"../ReEmitter":84,"../logger":129,"../utils":162,"./event-status":134,"./thread":145,"./typed-event-emitter":146,"matrix-events-sdk":49}],138:[function(require,module,exports){
47624
- "use strict";
47625
-
47626
- var _typeof = require("@babel/runtime/helpers/typeof");
47627
-
47628
- Object.defineProperty(exports, "__esModule", {
47629
- value: true
47630
- });
47631
- exports.Group = Group;
47632
-
47633
- var _events = require("events");
47634
-
47635
- var utils = _interopRequireWildcard(require("../utils"));
47636
-
47637
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
47638
-
47639
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47640
-
47641
- /*
47642
- Copyright 2017 New Vector Ltd
47643
- Copyright 2019 The Matrix.org Foundation C.I.C.
47644
-
47645
- Licensed under the Apache License, Version 2.0 (the "License");
47646
- you may not use this file except in compliance with the License.
47647
- You may obtain a copy of the License at
47648
-
47649
- http://www.apache.org/licenses/LICENSE-2.0
47650
-
47651
- Unless required by applicable law or agreed to in writing, software
47652
- distributed under the License is distributed on an "AS IS" BASIS,
47653
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47654
- See the License for the specific language governing permissions and
47655
- limitations under the License.
47656
- */
47657
-
47658
- /**
47659
- * @module models/group
47660
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
47661
- */
47662
- // eslint-disable-next-line no-restricted-imports
47663
-
47664
- /**
47665
- * Construct a new Group.
47666
- *
47667
- * @param {string} groupId The ID of this group.
47668
- *
47669
- * @prop {string} groupId The ID of this group.
47670
- * @prop {string} name The human-readable display name for this group.
47671
- * @prop {string} avatarUrl The mxc URL for this group's avatar.
47672
- * @prop {string} myMembership The logged in user's membership of this group
47673
- * @prop {Object} inviter Infomation about the user who invited the logged in user
47674
- * to the group, if myMembership is 'invite'.
47675
- * @prop {string} inviter.userId The user ID of the inviter
47676
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
47677
- */
47678
- function Group(groupId) {
47679
- this.groupId = groupId;
47680
- this.name = null;
47681
- this.avatarUrl = null;
47682
- this.myMembership = null;
47683
- this.inviter = null;
47684
- }
47685
-
47686
- utils.inherits(Group, _events.EventEmitter);
47687
-
47688
- Group.prototype.setProfile = function (name, avatarUrl) {
47689
- if (this.name === name && this.avatarUrl === avatarUrl) return;
47690
- this.name = name || this.groupId;
47691
- this.avatarUrl = avatarUrl;
47692
- this.emit("Group.profile", this);
47693
- };
47694
-
47695
- Group.prototype.setMyMembership = function (membership) {
47696
- if (this.myMembership === membership) return;
47697
- this.myMembership = membership;
47698
- this.emit("Group.myMembership", this);
47699
- };
47700
- /**
47701
- * Sets the 'inviter' property. This does not emit an event (the inviter
47702
- * will only change when the user is revited / reinvited to a room),
47703
- * so set this before setting myMembership.
47704
- * @param {Object} inviter Infomation about who invited us to the room
47705
- */
47706
-
47707
-
47708
- Group.prototype.setInviter = function (inviter) {
47709
- this.inviter = inviter;
47710
- };
47711
- /**
47712
- * Fires whenever a group's profile information is updated.
47713
- * This means the 'name' and 'avatarUrl' properties.
47714
- * @event module:client~MatrixClient#"Group.profile"
47715
- * @param {Group} group The group whose profile was updated.
47716
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
47717
- * @example
47718
- * matrixClient.on("Group.profile", function(group){
47719
- * var name = group.name;
47720
- * });
47721
- */
47722
-
47723
- /**
47724
- * Fires whenever the logged in user's membership status of
47725
- * the group is updated.
47726
- * @event module:client~MatrixClient#"Group.myMembership"
47727
- * @param {Group} group The group in which the user's membership changed
47728
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
47729
- * @example
47730
- * matrixClient.on("Group.myMembership", function(group){
47731
- * var myMembership = group.myMembership;
47732
- * });
47733
- */
47734
-
47735
- },{"../utils":162,"@babel/runtime/helpers/typeof":12,"events":25}],139:[function(require,module,exports){
47578
+ },{"../@types/event":78,"../ReEmitter":85,"../logger":130,"../utils":163,"./event-status":136,"./thread":146,"./typed-event-emitter":147,"matrix-events-sdk":49}],140:[function(require,module,exports){
47736
47579
  "use strict";
47737
47580
  /*
47738
47581
  Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
@@ -48095,7 +47938,7 @@ class Relations extends typed_event_emitter_1.TypedEventEmitter {
48095
47938
  }
48096
47939
  exports.Relations = Relations;
48097
47940
 
48098
- },{"../@types/event":77,"../logger":129,"./event":137,"./typed-event-emitter":146}],140:[function(require,module,exports){
47941
+ },{"../@types/event":78,"../logger":130,"./event":139,"./typed-event-emitter":147}],141:[function(require,module,exports){
48099
47942
  "use strict";
48100
47943
  /*
48101
47944
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -48496,7 +48339,7 @@ function calculateDisplayName(selfUserId, displayName, roomState, disambiguate)
48496
48339
  * });
48497
48340
  */
48498
48341
 
48499
- },{"../@types/event":77,"../content-repo":89,"../logger":129,"../utils":162,"./typed-event-emitter":146}],141:[function(require,module,exports){
48342
+ },{"../@types/event":78,"../content-repo":90,"../logger":130,"../utils":163,"./typed-event-emitter":147}],142:[function(require,module,exports){
48500
48343
  "use strict";
48501
48344
  /*
48502
48345
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -48543,6 +48386,8 @@ const utils = __importStar(require("../utils"));
48543
48386
  const event_1 = require("../@types/event");
48544
48387
  const partials_1 = require("../@types/partials");
48545
48388
  const typed_event_emitter_1 = require("./typed-event-emitter");
48389
+ const beacon_1 = require("./beacon");
48390
+ const ReEmitter_1 = require("../ReEmitter");
48546
48391
  // possible statuses for out-of-band member loading
48547
48392
  var OobStatus;
48548
48393
  (function (OobStatus) {
@@ -48556,6 +48401,7 @@ var RoomStateEvent;
48556
48401
  RoomStateEvent["Members"] = "RoomState.members";
48557
48402
  RoomStateEvent["NewMember"] = "RoomState.newMember";
48558
48403
  RoomStateEvent["Update"] = "RoomState.update";
48404
+ RoomStateEvent["BeaconLiveness"] = "RoomState.BeaconLiveness";
48559
48405
  })(RoomStateEvent = exports.RoomStateEvent || (exports.RoomStateEvent = {}));
48560
48406
  class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48561
48407
  /**
@@ -48596,6 +48442,7 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48596
48442
  super();
48597
48443
  this.roomId = roomId;
48598
48444
  this.oobMemberFlags = oobMemberFlags;
48445
+ this.reEmitter = new ReEmitter_1.TypedReEmitter(this);
48599
48446
  this.sentinels = {}; // userId: RoomMember
48600
48447
  // stores fuzzy matches to a list of userIDs (applies utils.removeHiddenChars to keys)
48601
48448
  this.displayNameToUserIds = {};
@@ -48615,6 +48462,8 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48615
48462
  this.members = {}; // userId: RoomMember
48616
48463
  this.events = new Map(); // Map<eventType, Map<stateKey, MatrixEvent>>
48617
48464
  this.paginationToken = null;
48465
+ this.beacons = new Map();
48466
+ this.liveBeaconIds = [];
48618
48467
  this.updateModifiedTime();
48619
48468
  }
48620
48469
  /**
@@ -48719,6 +48568,10 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48719
48568
  const event = this.events.get(eventType).get(stateKey);
48720
48569
  return event ? event : null;
48721
48570
  }
48571
+ get hasLiveBeacons() {
48572
+ var _a;
48573
+ return !!((_a = this.liveBeaconIds) === null || _a === void 0 ? void 0 : _a.length);
48574
+ }
48722
48575
  /**
48723
48576
  * Creates a copy of this room state so that mutations to either won't affect the other.
48724
48577
  * @return {RoomState} the copy of the room state
@@ -48790,6 +48643,9 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48790
48643
  if (!event.isState()) {
48791
48644
  return;
48792
48645
  }
48646
+ if ((0, beacon_1.isBeaconInfoEventType)(event.getType())) {
48647
+ this.setBeacon(event);
48648
+ }
48793
48649
  const lastStateEvent = this.getStateEventMatching(event);
48794
48650
  this.setStateEvent(event);
48795
48651
  if (event.getType() === event_1.EventType.RoomMember) {
@@ -48798,6 +48654,7 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48798
48654
  }
48799
48655
  this.emit(RoomStateEvent.Events, event, this, lastStateEvent);
48800
48656
  });
48657
+ this.onBeaconLivenessChange();
48801
48658
  // update higher level data structures. This needs to be done AFTER the
48802
48659
  // core event dict as these structures may depend on other state events in
48803
48660
  // the given array (e.g. disambiguating display names in one go to do both
@@ -48878,6 +48735,50 @@ class RoomState extends typed_event_emitter_1.TypedEventEmitter {
48878
48735
  }
48879
48736
  this.events.get(event.getType()).set(event.getStateKey(), event);
48880
48737
  }
48738
+ /**
48739
+ * @experimental
48740
+ */
48741
+ setBeacon(event) {
48742
+ if (this.beacons.has(event.getType())) {
48743
+ const beacon = this.beacons.get(event.getType());
48744
+ if (event.isRedacted()) {
48745
+ beacon.destroy();
48746
+ this.beacons.delete(event.getType());
48747
+ return;
48748
+ }
48749
+ return beacon.update(event);
48750
+ }
48751
+ if (event.isRedacted()) {
48752
+ return;
48753
+ }
48754
+ const beacon = new beacon_1.Beacon(event);
48755
+ this.reEmitter.reEmit(beacon, [
48756
+ beacon_1.BeaconEvent.New,
48757
+ beacon_1.BeaconEvent.Update,
48758
+ beacon_1.BeaconEvent.Destroy,
48759
+ beacon_1.BeaconEvent.LivenessChange,
48760
+ ]);
48761
+ this.emit(beacon_1.BeaconEvent.New, event, beacon);
48762
+ beacon.on(beacon_1.BeaconEvent.LivenessChange, this.onBeaconLivenessChange.bind(this));
48763
+ this.beacons.set(beacon.beaconInfoEventType, beacon);
48764
+ }
48765
+ /**
48766
+ * @experimental
48767
+ * Check liveness of room beacons
48768
+ * emit RoomStateEvent.BeaconLiveness when
48769
+ * roomstate.hasLiveBeacons has changed
48770
+ */
48771
+ onBeaconLivenessChange() {
48772
+ var _a;
48773
+ const prevHasLiveBeacons = !!((_a = this.liveBeaconIds) === null || _a === void 0 ? void 0 : _a.length);
48774
+ this.liveBeaconIds = Array.from(this.beacons.values())
48775
+ .filter(beacon => beacon.isLive)
48776
+ .map(beacon => beacon.beaconInfoId);
48777
+ const hasLiveBeacons = !!this.liveBeaconIds.length;
48778
+ if (prevHasLiveBeacons !== hasLiveBeacons) {
48779
+ this.emit(RoomStateEvent.BeaconLiveness, this, hasLiveBeacons);
48780
+ }
48781
+ }
48881
48782
  getStateEventMatching(event) {
48882
48783
  var _a, _b;
48883
48784
  return (_b = (_a = this.events.get(event.getType())) === null || _a === void 0 ? void 0 : _a.get(event.getStateKey())) !== null && _b !== void 0 ? _b : null;
@@ -49284,7 +49185,7 @@ exports.RoomState = RoomState;
49284
49185
  * });
49285
49186
  */
49286
49187
 
49287
- },{"../@types/event":77,"../@types/partials":80,"../logger":129,"../utils":162,"./room-member":140,"./typed-event-emitter":146}],142:[function(require,module,exports){
49188
+ },{"../@types/event":78,"../@types/partials":81,"../ReEmitter":85,"../logger":130,"../utils":163,"./beacon":134,"./room-member":141,"./typed-event-emitter":147}],143:[function(require,module,exports){
49288
49189
  "use strict";
49289
49190
  /*
49290
49191
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -49323,7 +49224,7 @@ class RoomSummary {
49323
49224
  }
49324
49225
  exports.RoomSummary = RoomSummary;
49325
49226
 
49326
- },{}],143:[function(require,module,exports){
49227
+ },{}],144:[function(require,module,exports){
49327
49228
  "use strict";
49328
49229
  /*
49329
49230
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -49386,6 +49287,7 @@ const logger_1 = require("../logger");
49386
49287
  const ReEmitter_1 = require("../ReEmitter");
49387
49288
  const event_2 = require("../@types/event");
49388
49289
  const client_1 = require("../client");
49290
+ const filter_1 = require("../filter");
49389
49291
  const thread_1 = require("./thread");
49390
49292
  const http_api_1 = require("../http-api");
49391
49293
  const typed_event_emitter_1 = require("./typed-event-emitter");
@@ -49504,6 +49406,7 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
49504
49406
  this.receipts = {}; // { receipt_type: { user_id: IReceipt } }
49505
49407
  this.receiptCacheByEventId = {}; // { event_id: ICachedReceipt[] }
49506
49408
  this.notificationCounts = {};
49409
+ this.threadsTimelineSets = [];
49507
49410
  // any filtered timeline sets we're maintaining for this room
49508
49411
  this.filteredTimelineSets = {}; // filter_id: timelineSet
49509
49412
  // read by megolm via getter; boolean value - null indicates "use global value"
@@ -49548,6 +49451,8 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
49548
49451
  * @experimental
49549
49452
  */
49550
49453
  this.visibilityEvents = new Map();
49454
+ this.threadTimelineSetsPromise = null;
49455
+ this.threadsReady = false;
49551
49456
  // In some cases, we add listeners for every displayed Matrix event, so it's
49552
49457
  // common to have quite a few more than the default limit.
49553
49458
  this.setMaxListeners(100);
@@ -49585,6 +49490,27 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
49585
49490
  this.membersPromise = null;
49586
49491
  }
49587
49492
  }
49493
+ createThreadsTimelineSets() {
49494
+ var _a;
49495
+ return __awaiter(this, void 0, void 0, function* () {
49496
+ if (this.threadTimelineSetsPromise) {
49497
+ return this.threadTimelineSetsPromise;
49498
+ }
49499
+ if ((_a = this.client) === null || _a === void 0 ? void 0 : _a.supportsExperimentalThreads) {
49500
+ try {
49501
+ this.threadTimelineSetsPromise = Promise.all([
49502
+ this.createThreadTimelineSet(),
49503
+ this.createThreadTimelineSet(thread_1.ThreadFilterType.My),
49504
+ ]);
49505
+ const timelineSets = yield this.threadTimelineSetsPromise;
49506
+ this.threadsTimelineSets.push(...timelineSets);
49507
+ }
49508
+ catch (e) {
49509
+ this.threadTimelineSetsPromise = null;
49510
+ }
49511
+ }
49512
+ });
49513
+ }
49588
49514
  /**
49589
49515
  * Bulk decrypt critical events in a room
49590
49516
  *
@@ -50145,17 +50071,14 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50145
50071
  return this.getUnfilteredTimelineSet().addTimeline();
50146
50072
  }
50147
50073
  /**
50148
- * Get an event which is stored in our unfiltered timeline set or in a thread
50074
+ * Get an event which is stored in our unfiltered timeline set, or in a thread
50149
50075
  *
50150
- * @param {string} eventId event ID to look for
50076
+ * @param {string} eventId event ID to look for
50151
50077
  * @return {?module:models/event.MatrixEvent} the given event, or undefined if unknown
50152
50078
  */
50153
50079
  findEventById(eventId) {
50154
50080
  let event = this.getUnfilteredTimelineSet().findEventById(eventId);
50155
- if (event) {
50156
- return event;
50157
- }
50158
- else {
50081
+ if (!event) {
50159
50082
  const threads = this.getThreads();
50160
50083
  for (let i = 0; i < threads.length; i++) {
50161
50084
  const thread = threads[i];
@@ -50165,6 +50088,7 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50165
50088
  }
50166
50089
  }
50167
50090
  }
50091
+ return event;
50168
50092
  }
50169
50093
  /**
50170
50094
  * Get one of the notification counts for this room
@@ -50449,18 +50373,20 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50449
50373
  * @param {*} opts.storageToken Optional.
50450
50374
  * @return {EventTimelineSet} The timelineSet
50451
50375
  */
50452
- getOrCreateFilteredTimelineSet(filter, { prepopulateTimeline = true } = {}) {
50376
+ getOrCreateFilteredTimelineSet(filter, { prepopulateTimeline = true, useSyncEvents = true, pendingEvents = true, } = {}) {
50453
50377
  if (this.filteredTimelineSets[filter.filterId]) {
50454
50378
  return this.filteredTimelineSets[filter.filterId];
50455
50379
  }
50456
- const opts = Object.assign({ filter: filter }, this.opts);
50380
+ const opts = Object.assign({ filter, pendingEvents }, this.opts);
50457
50381
  const timelineSet = new event_timeline_set_1.EventTimelineSet(this, opts);
50458
50382
  this.reEmitter.reEmit(timelineSet, [
50459
50383
  RoomEvent.Timeline,
50460
50384
  RoomEvent.TimelineReset,
50461
50385
  ]);
50462
- this.filteredTimelineSets[filter.filterId] = timelineSet;
50463
- this.timelineSets.push(timelineSet);
50386
+ if (useSyncEvents) {
50387
+ this.filteredTimelineSets[filter.filterId] = timelineSet;
50388
+ this.timelineSets.push(timelineSet);
50389
+ }
50464
50390
  const unfilteredLiveTimeline = this.getLiveTimeline();
50465
50391
  // Not all filter are possible to replicate client-side only
50466
50392
  // When that's the case we do not want to prepopulate from the live timeline
@@ -50482,7 +50408,7 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50482
50408
  }
50483
50409
  timelineSet.getLiveTimeline().setPaginationToken(timeline.getPaginationToken(event_timeline_1.EventTimeline.BACKWARDS), event_timeline_1.EventTimeline.BACKWARDS);
50484
50410
  }
50485
- else {
50411
+ else if (useSyncEvents) {
50486
50412
  const livePaginationToken = unfilteredLiveTimeline.getPaginationToken(event_timeline_1.Direction.Forward);
50487
50413
  timelineSet
50488
50414
  .getLiveTimeline()
@@ -50497,6 +50423,109 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50497
50423
  // );
50498
50424
  return timelineSet;
50499
50425
  }
50426
+ getThreadListFilter(filterType = thread_1.ThreadFilterType.All) {
50427
+ return __awaiter(this, void 0, void 0, function* () {
50428
+ const myUserId = this.client.getUserId();
50429
+ const filter = new filter_1.Filter(myUserId);
50430
+ const definition = {
50431
+ "room": {
50432
+ "timeline": {
50433
+ [thread_1.FILTER_RELATED_BY_REL_TYPES.name]: [thread_1.THREAD_RELATION_TYPE.name],
50434
+ },
50435
+ },
50436
+ };
50437
+ if (filterType === thread_1.ThreadFilterType.My) {
50438
+ definition.room.timeline[thread_1.FILTER_RELATED_BY_SENDERS.name] = [myUserId];
50439
+ }
50440
+ filter.setDefinition(definition);
50441
+ const filterId = yield this.client.getOrCreateFilter(`THREAD_PANEL_${this.roomId}_${filterType}`, filter);
50442
+ filter.filterId = filterId;
50443
+ return filter;
50444
+ });
50445
+ }
50446
+ createThreadTimelineSet(filterType) {
50447
+ return __awaiter(this, void 0, void 0, function* () {
50448
+ let timelineSet;
50449
+ if (thread_1.Thread.hasServerSideSupport) {
50450
+ const filter = yield this.getThreadListFilter(filterType);
50451
+ timelineSet = this.getOrCreateFilteredTimelineSet(filter, {
50452
+ prepopulateTimeline: false,
50453
+ useSyncEvents: false,
50454
+ pendingEvents: false,
50455
+ });
50456
+ }
50457
+ else {
50458
+ timelineSet = new event_timeline_set_1.EventTimelineSet(this, {
50459
+ pendingEvents: false,
50460
+ });
50461
+ Array.from(this.threads)
50462
+ .forEach(([, thread]) => {
50463
+ if (thread.length === 0)
50464
+ return;
50465
+ const currentUserParticipated = thread.events.some(event => {
50466
+ return event.getSender() === this.client.getUserId();
50467
+ });
50468
+ if (filterType !== thread_1.ThreadFilterType.My || currentUserParticipated) {
50469
+ timelineSet.getLiveTimeline().addEvent(thread.rootEvent, false);
50470
+ }
50471
+ });
50472
+ }
50473
+ return timelineSet;
50474
+ });
50475
+ }
50476
+ fetchRoomThreads() {
50477
+ return __awaiter(this, void 0, void 0, function* () {
50478
+ if (this.threadsReady) {
50479
+ return;
50480
+ }
50481
+ const allThreadsFilter = yield this.getThreadListFilter();
50482
+ const { chunk: events } = yield this.client.createMessagesRequest(this.roomId, "", Number.MAX_SAFE_INTEGER, event_timeline_1.Direction.Backward, allThreadsFilter);
50483
+ if (!events.length)
50484
+ return;
50485
+ // Sorted by last_reply origin_server_ts
50486
+ const threadRoots = events
50487
+ .map(this.client.getEventMapper())
50488
+ .sort((eventA, eventB) => {
50489
+ /**
50490
+ * `origin_server_ts` in a decentralised world is far from ideal
50491
+ * but for lack of any better, we will have to use this
50492
+ * Long term the sorting should be handled by homeservers and this
50493
+ * is only meant as a short term patch
50494
+ */
50495
+ const threadAMetadata = eventA
50496
+ .getServerAggregatedRelation(event_2.RelationType.Thread);
50497
+ const threadBMetadata = eventB
50498
+ .getServerAggregatedRelation(event_2.RelationType.Thread);
50499
+ return threadAMetadata.latest_event.origin_server_ts - threadBMetadata.latest_event.origin_server_ts;
50500
+ });
50501
+ let latestMyThreadsRootEvent;
50502
+ const roomState = this.getLiveTimeline().getState(event_timeline_1.EventTimeline.FORWARDS);
50503
+ for (const rootEvent of threadRoots) {
50504
+ this.threadsTimelineSets[0].addLiveEvent(rootEvent, event_timeline_set_1.DuplicateStrategy.Ignore, false, roomState);
50505
+ const threadRelationship = rootEvent
50506
+ .getServerAggregatedRelation(event_2.RelationType.Thread);
50507
+ if (threadRelationship.current_user_participated) {
50508
+ this.threadsTimelineSets[1].addLiveEvent(rootEvent, event_timeline_set_1.DuplicateStrategy.Ignore, false, roomState);
50509
+ latestMyThreadsRootEvent = rootEvent;
50510
+ }
50511
+ if (!this.getThread(rootEvent.getId())) {
50512
+ this.createThread(rootEvent, [], true);
50513
+ }
50514
+ }
50515
+ this.client.decryptEventIfNeeded(threadRoots[threadRoots.length - 1]);
50516
+ if (latestMyThreadsRootEvent) {
50517
+ this.client.decryptEventIfNeeded(latestMyThreadsRootEvent);
50518
+ }
50519
+ this.threadsReady = true;
50520
+ this.on(thread_1.ThreadEvent.NewReply, this.onThreadNewReply);
50521
+ });
50522
+ }
50523
+ onThreadNewReply(thread) {
50524
+ for (const timelineSet of this.threadsTimelineSets) {
50525
+ timelineSet.removeEvent(thread.id);
50526
+ timelineSet.addLiveEvent(thread.rootEvent);
50527
+ }
50528
+ }
50500
50529
  /**
50501
50530
  * Forget the timelineSet for this room with the given filter
50502
50531
  *
@@ -50510,41 +50539,67 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50510
50539
  this.timelineSets.splice(i, 1);
50511
50540
  }
50512
50541
  }
50513
- findThreadForEvent(event) {
50514
- if (!event) {
50515
- return null;
50542
+ eventShouldLiveIn(event, events, roots) {
50543
+ var _a;
50544
+ // A thread root is always shown in both timelines
50545
+ if (event.isThreadRoot || (roots === null || roots === void 0 ? void 0 : roots.has(event.getId()))) {
50546
+ return {
50547
+ shouldLiveInRoom: true,
50548
+ shouldLiveInThread: true,
50549
+ threadId: event.getId(),
50550
+ };
50516
50551
  }
50552
+ // A thread relation is always only shown in a thread
50517
50553
  if (event.isThreadRelation) {
50518
- return this.threads.get(event.threadRootId);
50554
+ return {
50555
+ shouldLiveInRoom: false,
50556
+ shouldLiveInThread: true,
50557
+ threadId: event.relationEventId,
50558
+ };
50519
50559
  }
50520
- else if (event.isThreadRoot) {
50521
- return this.threads.get(event.getId());
50560
+ const parentEventId = event.getAssociatedId();
50561
+ const parentEvent = (_a = this.findEventById(parentEventId)) !== null && _a !== void 0 ? _a : events === null || events === void 0 ? void 0 : events.find(e => e.getId() === parentEventId);
50562
+ // Treat relations and redactions as extensions of their parents so evaluate parentEvent instead
50563
+ if (parentEvent && (event.isRelation() || event.isRedaction())) {
50564
+ return this.eventShouldLiveIn(parentEvent, events, roots);
50522
50565
  }
50523
- else {
50524
- const parentEvent = this.findEventById(event.getAssociatedId());
50525
- return this.findThreadForEvent(parentEvent);
50566
+ // Edge case where we know the event is a relation but don't have the parentEvent
50567
+ if (roots === null || roots === void 0 ? void 0 : roots.has(event.relationEventId)) {
50568
+ return {
50569
+ shouldLiveInRoom: true,
50570
+ shouldLiveInThread: true,
50571
+ threadId: event.relationEventId,
50572
+ };
50573
+ }
50574
+ // A reply directly to a thread response is shown as part of the thread only, this is to provide a better
50575
+ // experience when communicating with users using clients without full threads support
50576
+ if (parentEvent === null || parentEvent === void 0 ? void 0 : parentEvent.isThreadRelation) {
50577
+ return {
50578
+ shouldLiveInRoom: false,
50579
+ shouldLiveInThread: true,
50580
+ threadId: parentEvent.threadRootId,
50581
+ };
50526
50582
  }
50583
+ // We've exhausted all scenarios, can safely assume that this event should live in the room timeline only
50584
+ return {
50585
+ shouldLiveInRoom: true,
50586
+ shouldLiveInThread: false,
50587
+ };
50527
50588
  }
50528
- /**
50529
- * Add an event to a thread's timeline. Will fire "Thread.update"
50530
- * @experimental
50531
- */
50532
- addThreadedEvent(event, toStartOfTimeline) {
50589
+ findThreadForEvent(event) {
50590
+ if (!event)
50591
+ return null;
50592
+ const { threadId } = this.eventShouldLiveIn(event);
50593
+ return threadId ? this.getThread(threadId) : null;
50594
+ }
50595
+ createThreadFetchRoot(threadId, events, toStartOfTimeline) {
50533
50596
  return __awaiter(this, void 0, void 0, function* () {
50534
- let thread = this.findThreadForEvent(event);
50535
- if (thread) {
50536
- thread.addEvent(event, toStartOfTimeline);
50537
- }
50538
- else {
50539
- const events = [event];
50540
- let rootEvent = this.findEventById(event.threadRootId);
50541
- // If the rootEvent does not exist in the current sync, then look for
50542
- // it over the network
50597
+ let thread = this.getThread(threadId);
50598
+ if (!thread) {
50599
+ let rootEvent = this.findEventById(threadId);
50600
+ // If the rootEvent does not exist in the local stores, then fetch it from the server.
50543
50601
  try {
50544
- let eventData;
50545
- if (event.threadRootId) {
50546
- eventData = yield this.client.fetchRoomEvent(this.roomId, event.threadRootId);
50547
- }
50602
+ const eventData = yield this.client.fetchRoomEvent(this.roomId, threadId);
50548
50603
  if (!rootEvent) {
50549
50604
  rootEvent = new event_1.MatrixEvent(eventData);
50550
50605
  }
@@ -50553,17 +50608,36 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50553
50608
  }
50554
50609
  }
50555
50610
  finally {
50556
- // The root event might be not be visible to the person requesting
50557
- // it. If it wasn't fetched successfully the thread will work
50558
- // in "limited" mode and won't benefit from all the APIs a homeserver
50559
- // can provide to enhance the thread experience
50560
- thread = this.createThread(rootEvent, events);
50611
+ // The root event might be not be visible to the person requesting it.
50612
+ // If it wasn't fetched successfully the thread will work in "limited" mode and won't
50613
+ // benefit from all the APIs a homeserver can provide to enhance the thread experience
50614
+ thread = this.createThread(rootEvent, events, toStartOfTimeline);
50615
+ if (thread) {
50616
+ rootEvent.setThread(thread);
50617
+ }
50561
50618
  }
50562
50619
  }
50620
+ return thread;
50621
+ });
50622
+ }
50623
+ /**
50624
+ * Add an event to a thread's timeline. Will fire "Thread.update"
50625
+ * @experimental
50626
+ */
50627
+ addThreadedEvent(event, toStartOfTimeline) {
50628
+ return __awaiter(this, void 0, void 0, function* () {
50629
+ this.applyRedaction(event);
50630
+ let thread = this.findThreadForEvent(event);
50631
+ if (thread) {
50632
+ yield thread.addEvent(event, toStartOfTimeline);
50633
+ }
50634
+ else {
50635
+ thread = yield this.createThreadFetchRoot(event.threadRootId, [event], toStartOfTimeline);
50636
+ }
50563
50637
  this.emit(thread_1.ThreadEvent.Update, thread);
50564
50638
  });
50565
50639
  }
50566
- createThread(rootEvent, events = []) {
50640
+ createThread(rootEvent, events = [], toStartOfTimeline) {
50567
50641
  var _a;
50568
50642
  if (rootEvent) {
50569
50643
  const tl = this.getTimelineForEvent(rootEvent.getId());
@@ -50577,33 +50651,35 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50577
50651
  room: this,
50578
50652
  client: this.client,
50579
50653
  });
50580
- // If we managed to create a thread and figure out its `id`
50581
- // then we can use it
50654
+ // If we managed to create a thread and figure out its `id` then we can use it
50582
50655
  if (thread.id) {
50583
50656
  this.threads.set(thread.id, thread);
50584
50657
  this.reEmitter.reEmit(thread, [
50585
50658
  thread_1.ThreadEvent.Update,
50659
+ thread_1.ThreadEvent.NewReply,
50586
50660
  RoomEvent.Timeline,
50587
50661
  RoomEvent.TimelineReset,
50588
50662
  ]);
50589
50663
  if (!this.lastThread || ((_a = this.lastThread.rootEvent) === null || _a === void 0 ? void 0 : _a.localTimestamp) < (rootEvent === null || rootEvent === void 0 ? void 0 : rootEvent.localTimestamp)) {
50590
50664
  this.lastThread = thread;
50591
50665
  }
50592
- this.emit(thread_1.ThreadEvent.New, thread);
50666
+ this.emit(thread_1.ThreadEvent.New, thread, toStartOfTimeline);
50667
+ if (this.threadsReady) {
50668
+ this.threadsTimelineSets.forEach(timelineSet => {
50669
+ if (thread.rootEvent) {
50670
+ if (thread_1.Thread.hasServerSideSupport) {
50671
+ timelineSet.addLiveEvent(thread.rootEvent);
50672
+ }
50673
+ else {
50674
+ timelineSet.addEventToTimeline(thread.rootEvent, timelineSet.getLiveTimeline(), toStartOfTimeline);
50675
+ }
50676
+ }
50677
+ });
50678
+ }
50593
50679
  return thread;
50594
50680
  }
50595
50681
  }
50596
- /**
50597
- * Add an event to the end of this room's live timelines. Will fire
50598
- * "Room.timeline".
50599
- *
50600
- * @param {MatrixEvent} event Event to be added
50601
- * @param {string?} duplicateStrategy 'ignore' or 'replace'
50602
- * @param {boolean} fromCache whether the sync response came from cache
50603
- * @fires module:client~MatrixClient#event:"Room.timeline"
50604
- * @private
50605
- */
50606
- addLiveEvent(event, duplicateStrategy, fromCache = false) {
50682
+ applyRedaction(event) {
50607
50683
  if (event.isRedaction()) {
50608
50684
  const redactId = event.event.redacts;
50609
50685
  // if we know about this event, redact its contents now.
@@ -50636,6 +50712,19 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50636
50712
  // clients can say "so and so redacted an event" if they wish to. Also
50637
50713
  // this may be needed to trigger an update.
50638
50714
  }
50715
+ }
50716
+ /**
50717
+ * Add an event to the end of this room's live timelines. Will fire
50718
+ * "Room.timeline".
50719
+ *
50720
+ * @param {MatrixEvent} event Event to be added
50721
+ * @param {string?} duplicateStrategy 'ignore' or 'replace'
50722
+ * @param {boolean} fromCache whether the sync response came from cache
50723
+ * @fires module:client~MatrixClient#event:"Room.timeline"
50724
+ * @private
50725
+ */
50726
+ addLiveEvent(event, duplicateStrategy, fromCache = false) {
50727
+ this.applyRedaction(event);
50639
50728
  // Implement MSC3531: hiding messages.
50640
50729
  if (event.isVisibilityEvent()) {
50641
50730
  // This event changes the visibility of another event, record
@@ -50785,11 +50874,10 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50785
50874
  * @param {module:models/event.MatrixEvent} event the relation event that needs to be aggregated.
50786
50875
  */
50787
50876
  aggregateNonLiveRelation(event) {
50788
- const thread = this.findThreadForEvent(event);
50789
- if (thread) {
50790
- thread.timelineSet.aggregateRelations(event);
50791
- }
50792
- if ((thread === null || thread === void 0 ? void 0 : thread.id) === event.getAssociatedId() || !thread) {
50877
+ const { shouldLiveInRoom, threadId } = this.eventShouldLiveIn(event);
50878
+ const thread = this.getThread(threadId);
50879
+ thread === null || thread === void 0 ? void 0 : thread.timelineSet.aggregateRelations(event);
50880
+ if (shouldLiveInRoom) {
50793
50881
  // TODO: We should consider whether this means it would be a better
50794
50882
  // design to lift the relations handling up to the room instead.
50795
50883
  for (let i = 0; i < this.timelineSets.length; i++) {
@@ -50837,11 +50925,10 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50837
50925
  // replace the event source (this will preserve the plaintext payload if
50838
50926
  // any, which is good, because we don't want to try decoding it again).
50839
50927
  localEvent.handleRemoteEcho(remoteEvent.event);
50840
- const thread = this.findThreadForEvent(remoteEvent);
50841
- if (thread) {
50842
- thread.timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
50843
- }
50844
- if ((thread === null || thread === void 0 ? void 0 : thread.id) === remoteEvent.getAssociatedId() || !thread) {
50928
+ const { shouldLiveInRoom, threadId } = this.eventShouldLiveIn(remoteEvent);
50929
+ const thread = this.getThread(threadId);
50930
+ thread === null || thread === void 0 ? void 0 : thread.timelineSet.handleRemoteEcho(localEvent, oldEventId, newEventId);
50931
+ if (shouldLiveInRoom) {
50845
50932
  for (let i = 0; i < this.timelineSets.length; i++) {
50846
50933
  const timelineSet = this.timelineSets[i];
50847
50934
  // if it's already in the timeline, update the timeline map. If it's not, add it.
@@ -50894,11 +50981,10 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50894
50981
  if (newStatus == event_status_1.EventStatus.SENT) {
50895
50982
  // update the event id
50896
50983
  event.replaceLocalEventId(newEventId);
50897
- const thread = this.findThreadForEvent(event);
50898
- if (thread) {
50899
- thread.timelineSet.replaceEventId(oldEventId, newEventId);
50900
- }
50901
- if ((thread === null || thread === void 0 ? void 0 : thread.id) === event.getAssociatedId() || !thread) {
50984
+ const { shouldLiveInRoom, threadId } = this.eventShouldLiveIn(event);
50985
+ const thread = this.getThread(threadId);
50986
+ thread === null || thread === void 0 ? void 0 : thread.timelineSet.replaceEventId(oldEventId, newEventId);
50987
+ if (shouldLiveInRoom) {
50902
50988
  // if the event was already in the timeline (which will be the case if
50903
50989
  // opts.pendingEventOrdering==chronological), we need to update the
50904
50990
  // timeline map.
@@ -50910,12 +50996,10 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50910
50996
  else if (newStatus == event_status_1.EventStatus.CANCELLED) {
50911
50997
  // remove it from the pending event list, or the timeline.
50912
50998
  if (this.pendingEventList) {
50913
- const idx = this.pendingEventList.findIndex(ev => ev.getId() === oldEventId);
50914
- if (idx !== -1) {
50915
- const [removedEvent] = this.pendingEventList.splice(idx, 1);
50916
- if (removedEvent.isRedaction()) {
50917
- this.revertRedactionLocalEcho(removedEvent);
50918
- }
50999
+ const removedEvent = this.getPendingEvent(oldEventId);
51000
+ this.removePendingEvent(oldEventId);
51001
+ if (removedEvent.isRedaction()) {
51002
+ this.revertRedactionLocalEcho(removedEvent);
50919
51003
  }
50920
51004
  }
50921
51005
  this.removeEvent(oldEventId);
@@ -50958,30 +51042,23 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
50958
51042
  * @throws If <code>duplicateStrategy</code> is not falsey, 'replace' or 'ignore'.
50959
51043
  */
50960
51044
  addLiveEvents(events, duplicateStrategy, fromCache = false) {
50961
- let i;
50962
51045
  if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) {
50963
51046
  throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'");
50964
51047
  }
50965
51048
  // sanity check that the live timeline is still live
50966
- for (i = 0; i < this.timelineSets.length; i++) {
51049
+ for (let i = 0; i < this.timelineSets.length; i++) {
50967
51050
  const liveTimeline = this.timelineSets[i].getLiveTimeline();
50968
51051
  if (liveTimeline.getPaginationToken(event_timeline_1.EventTimeline.FORWARDS)) {
50969
51052
  throw new Error("live timeline " + i + " is no longer live - it has a pagination token " +
50970
51053
  "(" + liveTimeline.getPaginationToken(event_timeline_1.EventTimeline.FORWARDS) + ")");
50971
51054
  }
50972
51055
  if (liveTimeline.getNeighbouringTimeline(event_timeline_1.EventTimeline.FORWARDS)) {
50973
- throw new Error("live timeline " + i + " is no longer live - " +
50974
- "it has a neighbouring timeline");
51056
+ throw new Error(`live timeline ${i} is no longer live - it has a neighbouring timeline`);
50975
51057
  }
50976
51058
  }
50977
- for (i = 0; i < events.length; i++) {
50978
- // TODO: We should have a filter to say "only add state event
50979
- // types X Y Z to the timeline".
51059
+ for (let i = 0; i < events.length; i++) {
51060
+ // TODO: We should have a filter to say "only add state event types X Y Z to the timeline".
50980
51061
  this.addLiveEvent(events[i], duplicateStrategy, fromCache);
50981
- const thread = this.findThreadForEvent(events[i]);
50982
- if (thread) {
50983
- thread.addEvent(events[i], true);
50984
- }
50985
51062
  }
50986
51063
  }
50987
51064
  /**
@@ -51330,7 +51407,7 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
51330
51407
  }
51331
51408
  /**
51332
51409
  * Returns the type of the room from the `m.room.create` event content or undefined if none is set
51333
- * @returns {?string} the type of the room. Currently only RoomType.Space is known.
51410
+ * @returns {?string} the type of the room.
51334
51411
  */
51335
51412
  getType() {
51336
51413
  const createEvent = this.currentState.getStateEvents(event_2.EventType.RoomCreate, "");
@@ -51350,6 +51427,20 @@ class Room extends typed_event_emitter_1.TypedEventEmitter {
51350
51427
  isSpaceRoom() {
51351
51428
  return this.getType() === event_2.RoomType.Space;
51352
51429
  }
51430
+ /**
51431
+ * Returns whether the room is a call-room as defined by MSC3417.
51432
+ * @returns {boolean} true if the room's type is RoomType.UnstableCall
51433
+ */
51434
+ isCallRoom() {
51435
+ return this.getType() === event_2.RoomType.UnstableCall;
51436
+ }
51437
+ /**
51438
+ * Returns whether the room is a video room.
51439
+ * @returns {boolean} true if the room's type is RoomType.ElementVideo
51440
+ */
51441
+ isElementVideoRoom() {
51442
+ return this.getType() === event_2.RoomType.ElementVideo;
51443
+ }
51353
51444
  /**
51354
51445
  * This is an internal method. Calculates the name of the room from the current
51355
51446
  * room state.
@@ -51755,7 +51846,7 @@ function memberNamesToRoomName(names, count = (names.length + 1)) {
51755
51846
  * @param {string} prevMembership The previous membership value
51756
51847
  */
51757
51848
 
51758
- },{"../@types/event":77,"../ReEmitter":84,"../client":87,"../content-repo":89,"../http-api":126,"../logger":129,"../utils":162,"./event":137,"./event-status":134,"./event-timeline":136,"./event-timeline-set":135,"./room-member":140,"./room-summary":142,"./thread":145,"./typed-event-emitter":146}],144:[function(require,module,exports){
51849
+ },{"../@types/event":78,"../ReEmitter":85,"../client":88,"../content-repo":90,"../filter":126,"../http-api":127,"../logger":130,"../utils":163,"./event":139,"./event-status":136,"./event-timeline":138,"./event-timeline-set":137,"./room-member":141,"./room-summary":143,"./thread":146,"./typed-event-emitter":147}],145:[function(require,module,exports){
51759
51850
  "use strict";
51760
51851
  /*
51761
51852
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -51801,19 +51892,23 @@ class SearchResult {
51801
51892
  */
51802
51893
  static fromJson(jsonObj, eventMapper) {
51803
51894
  const jsonContext = jsonObj.context || {};
51804
- const eventsBefore = jsonContext.events_before || [];
51805
- const eventsAfter = jsonContext.events_after || [];
51895
+ let eventsBefore = (jsonContext.events_before || []).map(eventMapper);
51896
+ let eventsAfter = (jsonContext.events_after || []).map(eventMapper);
51806
51897
  const context = new event_context_1.EventContext(eventMapper(jsonObj.result));
51898
+ // Filter out any contextual events which do not correspond to the same timeline (thread or room)
51899
+ const threadRootId = context.ourEvent.threadRootId;
51900
+ eventsBefore = eventsBefore.filter(e => e.threadRootId === threadRootId);
51901
+ eventsAfter = eventsAfter.filter(e => e.threadRootId === threadRootId);
51807
51902
  context.setPaginateToken(jsonContext.start, true);
51808
- context.addEvents(eventsBefore.map(eventMapper), true);
51809
- context.addEvents(eventsAfter.map(eventMapper), false);
51903
+ context.addEvents(eventsBefore, true);
51904
+ context.addEvents(eventsAfter, false);
51810
51905
  context.setPaginateToken(jsonContext.end, false);
51811
51906
  return new SearchResult(jsonObj.rank, context);
51812
51907
  }
51813
51908
  }
51814
51909
  exports.SearchResult = SearchResult;
51815
51910
 
51816
- },{"./event-context":133}],145:[function(require,module,exports){
51911
+ },{"./event-context":135}],146:[function(require,module,exports){
51817
51912
  "use strict";
51818
51913
  /*
51819
51914
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -51840,14 +51935,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
51840
51935
  });
51841
51936
  };
51842
51937
  Object.defineProperty(exports, "__esModule", { value: true });
51843
- exports.Thread = exports.ThreadEvent = void 0;
51938
+ exports.ThreadFilterType = exports.THREAD_RELATION_TYPE = exports.FILTER_RELATED_BY_REL_TYPES = exports.FILTER_RELATED_BY_SENDERS = exports.Thread = exports.ThreadEvent = void 0;
51844
51939
  const matrix_1 = require("../matrix");
51845
51940
  const ReEmitter_1 = require("../ReEmitter");
51846
- const event_1 = require("../@types/event");
51847
- const event_2 = require("./event");
51941
+ const event_1 = require("./event");
51848
51942
  const event_timeline_1 = require("./event-timeline");
51849
51943
  const event_timeline_set_1 = require("./event-timeline-set");
51850
51944
  const typed_event_emitter_1 = require("./typed-event-emitter");
51945
+ const NamespacedValue_1 = require("../NamespacedValue");
51946
+ const logger_1 = require("../logger");
51851
51947
  var ThreadEvent;
51852
51948
  (function (ThreadEvent) {
51853
51949
  ThreadEvent["New"] = "Thread.new";
@@ -51860,7 +51956,7 @@ var ThreadEvent;
51860
51956
  */
51861
51957
  class Thread extends typed_event_emitter_1.TypedEventEmitter {
51862
51958
  constructor(rootEvent, opts) {
51863
- var _a, _b, _c;
51959
+ var _a, _b, _c, _d;
51864
51960
  super();
51865
51961
  this.rootEvent = rootEvent;
51866
51962
  this._currentUserParticipated = false;
@@ -51883,27 +51979,22 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
51883
51979
  matrix_1.RoomEvent.Timeline,
51884
51980
  matrix_1.RoomEvent.TimelineReset,
51885
51981
  ]);
51886
- if (Thread.hasServerSideSupport === undefined) {
51887
- Thread.serverSupportPromise = this.client.doesServerSupportUnstableFeature("org.matrix.msc3440");
51888
- Thread.serverSupportPromise.then((serverSupportsThread) => {
51889
- Thread.hasServerSideSupport = serverSupportsThread;
51890
- }).catch(() => {
51891
- Thread.serverSupportPromise = null;
51892
- });
51893
- }
51894
- // If we weren't able to find the root event, it's probably missing
51982
+ // If we weren't able to find the root event, it's probably missing,
51895
51983
  // and we define the thread ID from one of the thread relation
51896
- if (!rootEvent) {
51897
- this.id = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.initialEvents) === null || _a === void 0 ? void 0 : _a.find(event => event.isThreadRelation)) === null || _b === void 0 ? void 0 : _b.relationEventId;
51898
- }
51899
- else {
51900
- this.id = rootEvent.getId();
51901
- }
51984
+ this.id = (_a = rootEvent === null || rootEvent === void 0 ? void 0 : rootEvent.getId()) !== null && _a !== void 0 ? _a : (_c = (_b = opts === null || opts === void 0 ? void 0 : opts.initialEvents) === null || _b === void 0 ? void 0 : _b.find(event => event.isThreadRelation)) === null || _c === void 0 ? void 0 : _c.relationEventId;
51902
51985
  this.initialiseThread(this.rootEvent);
51903
- (_c = opts === null || opts === void 0 ? void 0 : opts.initialEvents) === null || _c === void 0 ? void 0 : _c.forEach(event => this.addEvent(event, false));
51986
+ (_d = opts === null || opts === void 0 ? void 0 : opts.initialEvents) === null || _d === void 0 ? void 0 : _d.forEach(event => this.addEvent(event, false));
51904
51987
  this.room.on(matrix_1.RoomEvent.LocalEchoUpdated, this.onEcho);
51905
51988
  this.room.on(matrix_1.RoomEvent.Timeline, this.onEcho);
51906
51989
  }
51990
+ static setServerSideSupport(hasServerSideSupport, useStable) {
51991
+ Thread.hasServerSideSupport = hasServerSideSupport;
51992
+ if (!useStable) {
51993
+ exports.FILTER_RELATED_BY_SENDERS.setPreferUnstable(true);
51994
+ exports.FILTER_RELATED_BY_REL_TYPES.setPreferUnstable(true);
51995
+ exports.THREAD_RELATION_TYPE.setPreferUnstable(true);
51996
+ }
51997
+ }
51907
51998
  get roomState() {
51908
51999
  return this.room.getLiveTimeline().getState(event_timeline_1.EventTimeline.FORWARDS);
51909
52000
  }
@@ -51931,9 +52022,6 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
51931
52022
  addEvent(event, toStartOfTimeline) {
51932
52023
  var _a;
51933
52024
  return __awaiter(this, void 0, void 0, function* () {
51934
- if (Thread.hasServerSideSupport === undefined) {
51935
- yield Thread.serverSupportPromise;
51936
- }
51937
52025
  // Add all incoming events to the thread's timeline set when there's no server support
51938
52026
  if (!Thread.hasServerSideSupport) {
51939
52027
  // all the relevant membership info to hydrate events with a sender
@@ -51944,15 +52032,16 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
51944
52032
  this.addEventToTimeline(event, toStartOfTimeline);
51945
52033
  yield this.client.decryptEventIfNeeded(event, {});
51946
52034
  }
51947
- if (Thread.hasServerSideSupport && this.initialEventsFetched) {
51948
- if (event.localTimestamp > this.lastReply().localTimestamp) {
51949
- this.addEventToTimeline(event, false);
51950
- }
52035
+ else if (!toStartOfTimeline &&
52036
+ this.initialEventsFetched &&
52037
+ event.localTimestamp > this.lastReply().localTimestamp) {
52038
+ yield this.fetchEditsWhereNeeded(event);
52039
+ this.addEventToTimeline(event, false);
51951
52040
  }
51952
52041
  if (!this._currentUserParticipated && event.getSender() === this.client.getUserId()) {
51953
52042
  this._currentUserParticipated = true;
51954
52043
  }
51955
- const isThreadReply = ((_a = event.getRelation()) === null || _a === void 0 ? void 0 : _a.rel_type) === event_1.RelationType.Thread;
52044
+ const isThreadReply = ((_a = event.getRelation()) === null || _a === void 0 ? void 0 : _a.rel_type) === exports.THREAD_RELATION_TYPE.name;
51956
52045
  // If no thread support exists we want to count all thread relation
51957
52046
  // added as a reply. We can't rely on the bundled relationships count
51958
52047
  if (!Thread.hasServerSideSupport && isThreadReply) {
@@ -51961,7 +52050,9 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
51961
52050
  // There is a risk that the `localTimestamp` approximation will not be accurate
51962
52051
  // when threads are used over federation. That could results in the reply
51963
52052
  // count value drifting away from the value returned by the server
51964
- if (!this.lastEvent || (isThreadReply && event.localTimestamp > this.replyToEvent.localTimestamp)) {
52053
+ if (!this.lastEvent || (isThreadReply
52054
+ && (event.getId() !== this.lastEvent.getId())
52055
+ && (event.localTimestamp > this.lastEvent.localTimestamp))) {
51965
52056
  this.lastEvent = event;
51966
52057
  if (this.lastEvent.getId() !== this.id) {
51967
52058
  // This counting only works when server side support is enabled
@@ -51977,26 +52068,35 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
51977
52068
  });
51978
52069
  }
51979
52070
  initialiseThread(rootEvent) {
51980
- if (Thread.hasServerSideSupport === undefined) {
51981
- Thread.serverSupportPromise.then(() => {
51982
- this.initialiseThread(rootEvent);
51983
- });
51984
- return;
51985
- }
51986
- const bundledRelationship = rootEvent === null || rootEvent === void 0 ? void 0 : rootEvent.getServerAggregatedRelation(event_1.RelationType.Thread);
52071
+ const bundledRelationship = rootEvent === null || rootEvent === void 0 ? void 0 : rootEvent.getServerAggregatedRelation(exports.THREAD_RELATION_TYPE.name);
51987
52072
  if (Thread.hasServerSideSupport && bundledRelationship) {
51988
52073
  this.replyCount = bundledRelationship.count;
51989
52074
  this._currentUserParticipated = bundledRelationship.current_user_participated;
51990
- const event = new event_2.MatrixEvent(bundledRelationship.latest_event);
52075
+ const event = new event_1.MatrixEvent(bundledRelationship.latest_event);
51991
52076
  this.setEventMetadata(event);
52077
+ event.setThread(this);
51992
52078
  this.lastEvent = event;
52079
+ this.fetchEditsWhereNeeded(event);
51993
52080
  }
51994
52081
  }
52082
+ // XXX: Workaround for https://github.com/matrix-org/matrix-spec-proposals/pull/2676/files#r827240084
52083
+ fetchEditsWhereNeeded(...events) {
52084
+ return __awaiter(this, void 0, void 0, function* () {
52085
+ return Promise.all(events.filter(e => e.isEncrypted()).map((event) => {
52086
+ return this.client.relations(this.roomId, event.getId(), matrix_1.RelationType.Replace, event.getType(), {
52087
+ limit: 1,
52088
+ }).then(relations => {
52089
+ if (relations.events.length) {
52090
+ event.makeReplaced(relations.events[0]);
52091
+ }
52092
+ }).catch(e => {
52093
+ logger_1.logger.error("Failed to load edits for encrypted thread event", e);
52094
+ });
52095
+ }));
52096
+ });
52097
+ }
51995
52098
  fetchInitialEvents() {
51996
52099
  return __awaiter(this, void 0, void 0, function* () {
51997
- if (Thread.hasServerSideSupport === undefined) {
51998
- yield Thread.serverSupportPromise;
51999
- }
52000
52100
  if (!Thread.hasServerSideSupport) {
52001
52101
  this.initialEventsFetched = true;
52002
52102
  return null;
@@ -52019,6 +52119,11 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
52019
52119
  * Finds an event by ID in the current thread
52020
52120
  */
52021
52121
  findEventById(eventId) {
52122
+ var _a;
52123
+ // Check the lastEvent as it may have been created based on a bundled relationship and not in a timeline
52124
+ if (((_a = this.lastEvent) === null || _a === void 0 ? void 0 : _a.getId()) === eventId) {
52125
+ return this.lastEvent;
52126
+ }
52022
52127
  return this.timelineSet.findEventById(eventId);
52023
52128
  }
52024
52129
  /**
@@ -52053,7 +52158,7 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
52053
52158
  return this.liveTimeline.getEvents();
52054
52159
  }
52055
52160
  has(eventId) {
52056
- return this.timelineSet.findEventById(eventId) instanceof event_2.MatrixEvent;
52161
+ return this.timelineSet.findEventById(eventId) instanceof event_1.MatrixEvent;
52057
52162
  }
52058
52163
  get hasCurrentUserParticipated() {
52059
52164
  return this._currentUserParticipated;
@@ -52063,15 +52168,13 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
52063
52168
  }
52064
52169
  fetchEvents(opts = { limit: 20 }) {
52065
52170
  return __awaiter(this, void 0, void 0, function* () {
52066
- if (Thread.hasServerSideSupport === undefined) {
52067
- yield Thread.serverSupportPromise;
52068
- }
52069
- let { originalEvent, events, prevBatch, nextBatch, } = yield this.client.relations(this.room.roomId, this.id, event_1.RelationType.Thread, null, opts);
52171
+ let { originalEvent, events, prevBatch, nextBatch, } = yield this.client.relations(this.room.roomId, this.id, exports.THREAD_RELATION_TYPE.name, null, opts);
52070
52172
  // When there's no nextBatch returned with a `from` request we have reached
52071
52173
  // the end of the thread, and therefore want to return an empty one
52072
52174
  if (!opts.to && !nextBatch) {
52073
52175
  events = [...events, originalEvent];
52074
52176
  }
52177
+ yield this.fetchEditsWhereNeeded(...events);
52075
52178
  yield Promise.all(events.map(event => {
52076
52179
  this.setEventMetadata(event);
52077
52180
  return this.client.decryptEventIfNeeded(event);
@@ -52088,8 +52191,16 @@ class Thread extends typed_event_emitter_1.TypedEventEmitter {
52088
52191
  }
52089
52192
  }
52090
52193
  exports.Thread = Thread;
52091
-
52092
- },{"../@types/event":77,"../ReEmitter":84,"../matrix":130,"./event":137,"./event-timeline":136,"./event-timeline-set":135,"./typed-event-emitter":146}],146:[function(require,module,exports){
52194
+ exports.FILTER_RELATED_BY_SENDERS = new NamespacedValue_1.ServerControlledNamespacedValue("related_by_senders", "io.element.relation_senders");
52195
+ exports.FILTER_RELATED_BY_REL_TYPES = new NamespacedValue_1.ServerControlledNamespacedValue("related_by_rel_types", "io.element.relation_types");
52196
+ exports.THREAD_RELATION_TYPE = new NamespacedValue_1.ServerControlledNamespacedValue("m.thread", "io.element.thread");
52197
+ var ThreadFilterType;
52198
+ (function (ThreadFilterType) {
52199
+ ThreadFilterType[ThreadFilterType["My"] = 0] = "My";
52200
+ ThreadFilterType[ThreadFilterType["All"] = 1] = "All";
52201
+ })(ThreadFilterType = exports.ThreadFilterType || (exports.ThreadFilterType = {}));
52202
+
52203
+ },{"../NamespacedValue":84,"../ReEmitter":85,"../logger":130,"../matrix":131,"./event":139,"./event-timeline":138,"./event-timeline-set":137,"./typed-event-emitter":147}],147:[function(require,module,exports){
52093
52204
  "use strict";
52094
52205
  /*
52095
52206
  Copyright 2021 The Matrix.org Foundation C.I.C.
@@ -52166,7 +52277,7 @@ class TypedEventEmitter extends events_1.EventEmitter {
52166
52277
  }
52167
52278
  exports.TypedEventEmitter = TypedEventEmitter;
52168
52279
 
52169
- },{"events":25}],147:[function(require,module,exports){
52280
+ },{"events":25}],148:[function(require,module,exports){
52170
52281
  "use strict";
52171
52282
  /*
52172
52283
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -52424,7 +52535,7 @@ exports.User = User;
52424
52535
  * });
52425
52536
  */
52426
52537
 
52427
- },{"./typed-event-emitter":146}],148:[function(require,module,exports){
52538
+ },{"./typed-event-emitter":147}],149:[function(require,module,exports){
52428
52539
  "use strict";
52429
52540
  /*
52430
52541
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -52863,7 +52974,7 @@ PushProcessor.cachedGlobToRegex = {}; // $glob: RegExp
52863
52974
  * noise.
52864
52975
  */
52865
52976
 
52866
- },{"./@types/PushRules":76,"./logger":129,"./utils":162}],149:[function(require,module,exports){
52977
+ },{"./@types/PushRules":76,"./logger":130,"./utils":163}],150:[function(require,module,exports){
52867
52978
  "use strict";
52868
52979
  /*
52869
52980
  Copyright 2018 New Vector Ltd
@@ -52906,7 +53017,7 @@ function randomStringFrom(len, chars) {
52906
53017
  return ret;
52907
53018
  }
52908
53019
 
52909
- },{}],150:[function(require,module,exports){
53020
+ },{}],151:[function(require,module,exports){
52910
53021
  (function (global){(function (){
52911
53022
  "use strict";
52912
53023
  /*
@@ -53091,7 +53202,7 @@ function binarySearch(array, func) {
53091
53202
 
53092
53203
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
53093
53204
 
53094
- },{"./logger":129}],151:[function(require,module,exports){
53205
+ },{"./logger":130}],152:[function(require,module,exports){
53095
53206
  "use strict";
53096
53207
  /*
53097
53208
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -53413,7 +53524,7 @@ function debuglog(...args) {
53413
53524
  * @return {Promise} Resolved/rejected depending on the outcome of the request.
53414
53525
  */
53415
53526
 
53416
- },{"./@types/event":77,"./logger":129,"./utils":162}],152:[function(require,module,exports){
53527
+ },{"./@types/event":78,"./logger":130,"./utils":163}],153:[function(require,module,exports){
53417
53528
  "use strict";
53418
53529
  /*
53419
53530
  Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
@@ -53438,7 +53549,7 @@ var SERVICE_TYPES;
53438
53549
  SERVICE_TYPES["IM"] = "SERVICE_TYPE_IM";
53439
53550
  })(SERVICE_TYPES = exports.SERVICE_TYPES || (exports.SERVICE_TYPES = {}));
53440
53551
 
53441
- },{}],153:[function(require,module,exports){
53552
+ },{}],154:[function(require,module,exports){
53442
53553
  "use strict";
53443
53554
  /*
53444
53555
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -53651,7 +53762,6 @@ class LocalIndexedDBStoreBackend {
53651
53762
  this.syncAccumulator.accumulate({
53652
53763
  next_batch: syncData.nextBatch,
53653
53764
  rooms: syncData.roomsData,
53654
- groups: syncData.groupsData,
53655
53765
  account_data: {
53656
53766
  events: accountData,
53657
53767
  },
@@ -53819,7 +53929,7 @@ class LocalIndexedDBStoreBackend {
53819
53929
  yield Promise.all([
53820
53930
  this.persistUserPresenceEvents(userTuples),
53821
53931
  this.persistAccountData(syncData.accountData),
53822
- this.persistSyncData(syncData.nextBatch, syncData.roomsData, syncData.groupsData),
53932
+ this.persistSyncData(syncData.nextBatch, syncData.roomsData),
53823
53933
  ]);
53824
53934
  });
53825
53935
  }
@@ -53827,10 +53937,9 @@ class LocalIndexedDBStoreBackend {
53827
53937
  * Persist rooms /sync data along with the next batch token.
53828
53938
  * @param {string} nextBatch The next_batch /sync value.
53829
53939
  * @param {Object} roomsData The 'rooms' /sync data from a SyncAccumulator
53830
- * @param {Object} groupsData The 'groups' /sync data from a SyncAccumulator
53831
53940
  * @return {Promise} Resolves if the data was persisted.
53832
53941
  */
53833
- persistSyncData(nextBatch, roomsData, groupsData) {
53942
+ persistSyncData(nextBatch, roomsData) {
53834
53943
  logger_1.logger.log("Persisting sync data up to", nextBatch);
53835
53944
  return utils.promiseTry(() => {
53836
53945
  const txn = this.db.transaction(["sync"], "readwrite");
@@ -53839,7 +53948,6 @@ class LocalIndexedDBStoreBackend {
53839
53948
  clobber: "-",
53840
53949
  nextBatch,
53841
53950
  roomsData,
53842
- groupsData,
53843
53951
  }); // put == UPSERT
53844
53952
  return txnAsPromise(txn).then();
53845
53953
  });
@@ -53958,7 +54066,7 @@ class LocalIndexedDBStoreBackend {
53958
54066
  }
53959
54067
  exports.LocalIndexedDBStoreBackend = LocalIndexedDBStoreBackend;
53960
54068
 
53961
- },{"../indexeddb-helpers":127,"../logger":129,"../sync-accumulator":159,"../utils":162}],154:[function(require,module,exports){
54069
+ },{"../indexeddb-helpers":128,"../logger":130,"../sync-accumulator":160,"../utils":163}],155:[function(require,module,exports){
53962
54070
  "use strict";
53963
54071
  /*
53964
54072
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -54126,7 +54234,7 @@ class RemoteIndexedDBStoreBackend {
54126
54234
  }
54127
54235
  exports.RemoteIndexedDBStoreBackend = RemoteIndexedDBStoreBackend;
54128
54236
 
54129
- },{"../logger":129,"../utils":162}],155:[function(require,module,exports){
54237
+ },{"../logger":130,"../utils":163}],156:[function(require,module,exports){
54130
54238
  "use strict";
54131
54239
  /*
54132
54240
  Copyright 2017 - 2021 Vector Creations Ltd
@@ -54421,7 +54529,7 @@ class IndexedDBStore extends memory_1.MemoryStore {
54421
54529
  }
54422
54530
  exports.IndexedDBStore = IndexedDBStore;
54423
54531
 
54424
- },{"../logger":129,"../models/event":137,"../models/typed-event-emitter":146,"../models/user":147,"./indexeddb-local-backend":153,"./indexeddb-remote-backend":154,"./memory":156}],156:[function(require,module,exports){
54532
+ },{"../logger":130,"../models/event":139,"../models/typed-event-emitter":147,"../models/user":148,"./indexeddb-local-backend":154,"./indexeddb-remote-backend":155,"./memory":157}],157:[function(require,module,exports){
54425
54533
  "use strict";
54426
54534
  /*
54427
54535
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -54459,7 +54567,6 @@ function isValidFilterId(filterId) {
54459
54567
  class MemoryStore {
54460
54568
  constructor(opts = {}) {
54461
54569
  this.rooms = {}; // roomId: Room
54462
- this.groups = {}; // groupId: Group
54463
54570
  this.users = {}; // userId: User
54464
54571
  this.syncToken = null;
54465
54572
  // userId: {
@@ -54514,31 +54621,6 @@ class MemoryStore {
54514
54621
  setSyncToken(token) {
54515
54622
  this.syncToken = token;
54516
54623
  }
54517
- /**
54518
- * Store the given room.
54519
- * @param {Group} group The group to be stored
54520
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
54521
- */
54522
- storeGroup(group) {
54523
- this.groups[group.groupId] = group;
54524
- }
54525
- /**
54526
- * Retrieve a group by its group ID.
54527
- * @param {string} groupId The group ID.
54528
- * @return {Group} The group or null.
54529
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
54530
- */
54531
- getGroup(groupId) {
54532
- return this.groups[groupId] || null;
54533
- }
54534
- /**
54535
- * Retrieve all known groups.
54536
- * @return {Group[]} A list of groups, which may be empty.
54537
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
54538
- */
54539
- getGroups() {
54540
- return Object.values(this.groups);
54541
- }
54542
54624
  /**
54543
54625
  * Store the given room.
54544
54626
  * @param {Room} room The room to be stored. All properties must be stored.
@@ -54820,7 +54902,7 @@ class MemoryStore {
54820
54902
  }
54821
54903
  exports.MemoryStore = MemoryStore;
54822
54904
 
54823
- },{"../models/room-state":141,"../models/user":147}],157:[function(require,module,exports){
54905
+ },{"../models/room-state":142,"../models/user":148}],158:[function(require,module,exports){
54824
54906
  "use strict";
54825
54907
 
54826
54908
  var _typeof = require("@babel/runtime/helpers/typeof");
@@ -55105,7 +55187,7 @@ function debuglog() {
55105
55187
  }
55106
55188
  }
55107
55189
 
55108
- },{"../../logger":129,"../../utils":162,"@babel/runtime/helpers/typeof":12}],158:[function(require,module,exports){
55190
+ },{"../../logger":130,"../../utils":163,"@babel/runtime/helpers/typeof":12}],159:[function(require,module,exports){
55109
55191
  "use strict";
55110
55192
  /*
55111
55193
  Copyright 2015 - 2021 The Matrix.org Foundation C.I.C.
@@ -55151,29 +55233,6 @@ class StubStore {
55151
55233
  setSyncToken(token) {
55152
55234
  this.fromToken = token;
55153
55235
  }
55154
- /**
55155
- * No-op.
55156
- * @param {Group} group
55157
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
55158
- */
55159
- storeGroup(group) { }
55160
- /**
55161
- * No-op.
55162
- * @param {string} groupId
55163
- * @return {null}
55164
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
55165
- */
55166
- getGroup(groupId) {
55167
- return null;
55168
- }
55169
- /**
55170
- * No-op.
55171
- * @return {Array} An empty array.
55172
- * @deprecated groups/communities never made it to the spec and support for them is being discontinued.
55173
- */
55174
- getGroups() {
55175
- return [];
55176
- }
55177
55236
  /**
55178
55237
  * No-op.
55179
55238
  * @param {Room} room
@@ -55354,7 +55413,7 @@ class StubStore {
55354
55413
  }
55355
55414
  exports.StubStore = StubStore;
55356
55415
 
55357
- },{}],159:[function(require,module,exports){
55416
+ },{}],160:[function(require,module,exports){
55358
55417
  "use strict";
55359
55418
  /*
55360
55419
  Copyright 2017 - 2021 The Matrix.org Foundation C.I.C.
@@ -55416,17 +55475,10 @@ class SyncAccumulator {
55416
55475
  // coherent /sync response and know at what point they should be
55417
55476
  // streaming from without losing events.
55418
55477
  this.nextBatch = null;
55419
- // { ('invite'|'join'|'leave'): $groupId: { ... sync 'group' data } }
55420
- this.groups = {
55421
- invite: {},
55422
- join: {},
55423
- leave: {},
55424
- };
55425
55478
  this.opts.maxTimelineEntries = this.opts.maxTimelineEntries || 50;
55426
55479
  }
55427
55480
  accumulate(syncResponse, fromDatabase = false) {
55428
55481
  this.accumulateRooms(syncResponse, fromDatabase);
55429
- this.accumulateGroups(syncResponse);
55430
55482
  this.accumulateAccountData(syncResponse);
55431
55483
  this.nextBatch = syncResponse.next_batch;
55432
55484
  }
@@ -55688,36 +55740,6 @@ class SyncAccumulator {
55688
55740
  }
55689
55741
  }
55690
55742
  }
55691
- /**
55692
- * Accumulate incremental /sync group data.
55693
- * @param {Object} syncResponse the complete /sync JSON
55694
- */
55695
- accumulateGroups(syncResponse) {
55696
- if (!syncResponse.groups) {
55697
- return;
55698
- }
55699
- if (syncResponse.groups.invite) {
55700
- Object.keys(syncResponse.groups.invite).forEach((groupId) => {
55701
- this.accumulateGroup(groupId, Category.Invite, syncResponse.groups.invite[groupId]);
55702
- });
55703
- }
55704
- if (syncResponse.groups.join) {
55705
- Object.keys(syncResponse.groups.join).forEach((groupId) => {
55706
- this.accumulateGroup(groupId, Category.Join, syncResponse.groups.join[groupId]);
55707
- });
55708
- }
55709
- if (syncResponse.groups.leave) {
55710
- Object.keys(syncResponse.groups.leave).forEach((groupId) => {
55711
- this.accumulateGroup(groupId, Category.Leave, syncResponse.groups.leave[groupId]);
55712
- });
55713
- }
55714
- }
55715
- accumulateGroup(groupId, category, data) {
55716
- for (const cat of [Category.Invite, Category.Leave, Category.Join]) {
55717
- delete this.groups[cat][groupId];
55718
- }
55719
- this.groups[category][groupId] = data;
55720
- }
55721
55743
  /**
55722
55744
  * Return everything under the 'rooms' key from a /sync response which
55723
55745
  * represents all room data that should be stored. This should be paired
@@ -55868,7 +55890,6 @@ class SyncAccumulator {
55868
55890
  return {
55869
55891
  nextBatch: this.nextBatch,
55870
55892
  roomsData: data,
55871
- groupsData: this.groups,
55872
55893
  accountData: accData,
55873
55894
  };
55874
55895
  }
@@ -55887,7 +55908,7 @@ function setState(eventMap, event) {
55887
55908
  eventMap[event.type][event.state_key] = event;
55888
55909
  }
55889
55910
 
55890
- },{"./logger":129,"./utils":162}],160:[function(require,module,exports){
55911
+ },{"./logger":130,"./utils":163}],161:[function(require,module,exports){
55891
55912
  (function (global){(function (){
55892
55913
  "use strict";
55893
55914
  /*
@@ -55945,7 +55966,6 @@ exports.SyncApi = exports.SyncState = void 0;
55945
55966
  */
55946
55967
  const user_1 = require("./models/user");
55947
55968
  const room_1 = require("./models/room");
55948
- const group_1 = require("./models/group");
55949
55969
  const utils = __importStar(require("./utils"));
55950
55970
  const filter_1 = require("./filter");
55951
55971
  const event_timeline_1 = require("./models/event-timeline");
@@ -55953,11 +55973,11 @@ const pushprocessor_1 = require("./pushprocessor");
55953
55973
  const logger_1 = require("./logger");
55954
55974
  const errors_1 = require("./errors");
55955
55975
  const client_1 = require("./client");
55956
- const sync_accumulator_1 = require("./sync-accumulator");
55957
55976
  const http_api_1 = require("./http-api");
55958
55977
  const event_1 = require("./@types/event");
55959
55978
  const room_state_1 = require("./models/room-state");
55960
55979
  const room_member_1 = require("./models/room-member");
55980
+ const beacon_1 = require("./models/beacon");
55961
55981
  const DEBUG = true;
55962
55982
  // /sync requests allow you to set a timeout= but the request may continue
55963
55983
  // beyond that and wedge forever, so we need to track how long we are willing
@@ -56080,20 +56100,6 @@ class SyncApi {
56080
56100
  this.registerStateListeners(room);
56081
56101
  return room;
56082
56102
  }
56083
- /**
56084
- * @param {string} groupId
56085
- * @return {Group}
56086
- */
56087
- createGroup(groupId) {
56088
- const client = this.client;
56089
- const group = new group_1.Group(groupId);
56090
- client.reEmitter.reEmit(group, [
56091
- client_1.ClientEvent.GroupProfile,
56092
- client_1.ClientEvent.GroupMyMembership,
56093
- ]);
56094
- client.store.storeGroup(group);
56095
- return group;
56096
- }
56097
56103
  /**
56098
56104
  * @param {Room} room
56099
56105
  * @private
@@ -56108,6 +56114,10 @@ class SyncApi {
56108
56114
  room_state_1.RoomStateEvent.Members,
56109
56115
  room_state_1.RoomStateEvent.NewMember,
56110
56116
  room_state_1.RoomStateEvent.Update,
56117
+ beacon_1.BeaconEvent.New,
56118
+ beacon_1.BeaconEvent.Update,
56119
+ beacon_1.BeaconEvent.Destroy,
56120
+ beacon_1.BeaconEvent.LivenessChange,
56111
56121
  ]);
56112
56122
  room.currentState.on(room_state_1.RoomStateEvent.NewMember, function (event, state, member) {
56113
56123
  member.user = client.getUser(member.userId);
@@ -56147,16 +56157,14 @@ class SyncApi {
56147
56157
  qps.filter = filterId;
56148
56158
  return client.http.authedRequest(// TODO types
56149
56159
  undefined, http_api_1.Method.Get, "/sync", qps, undefined, localTimeoutMs);
56150
- }).then((data) => {
56160
+ }).then((data) => __awaiter(this, void 0, void 0, function* () {
56151
56161
  var _a;
56152
56162
  let leaveRooms = [];
56153
56163
  if ((_a = data.rooms) === null || _a === void 0 ? void 0 : _a.leave) {
56154
56164
  leaveRooms = this.mapSyncResponseToRoomArray(data.rooms.leave);
56155
56165
  }
56156
- const rooms = [];
56157
- leaveRooms.forEach((leaveObj) => __awaiter(this, void 0, void 0, function* () {
56166
+ return Promise.all(leaveRooms.map((leaveObj) => __awaiter(this, void 0, void 0, function* () {
56158
56167
  const room = leaveObj.room;
56159
- rooms.push(room);
56160
56168
  if (!leaveObj.isBrandNewRoom) {
56161
56169
  // the intention behind syncLeftRooms is to add in rooms which were
56162
56170
  // *omitted* from the initial /sync. Rooms the user were joined to
@@ -56170,20 +56178,18 @@ class SyncApi {
56170
56178
  }
56171
56179
  leaveObj.timeline = leaveObj.timeline || {};
56172
56180
  const events = this.mapSyncEventsFormat(leaveObj.timeline, room);
56173
- const [timelineEvents, threadedEvents] = this.client.partitionThreadedEvents(events);
56174
56181
  const stateEvents = this.mapSyncEventsFormat(leaveObj.state, room);
56175
56182
  // set the back-pagination token. Do this *before* adding any
56176
56183
  // events so that clients can start back-paginating.
56177
56184
  room.getLiveTimeline().setPaginationToken(leaveObj.timeline.prev_batch, event_timeline_1.EventTimeline.BACKWARDS);
56178
- this.processRoomEvents(room, stateEvents, timelineEvents);
56179
- yield this.processThreadEvents(room, threadedEvents, false);
56185
+ yield this.processRoomEvents(room, stateEvents, events);
56180
56186
  room.recalculate();
56181
56187
  client.store.storeRoom(room);
56182
56188
  client.emit(client_1.ClientEvent.Room, room);
56183
56189
  this.processEventsForNotifs(room, events);
56184
- }));
56185
- return rooms;
56186
- });
56190
+ return room;
56191
+ })));
56192
+ }));
56187
56193
  }
56188
56194
  /**
56189
56195
  * Peek into a room. This will result in the room in question being synced so it
@@ -56587,7 +56593,6 @@ class SyncApi {
56587
56593
  const data = {
56588
56594
  next_batch: nextSyncToken,
56589
56595
  rooms: savedSync.roomsData,
56590
- groups: savedSync.groupsData,
56591
56596
  account_data: {
56592
56597
  events: savedSync.accountData,
56593
56598
  },
@@ -56596,7 +56601,7 @@ class SyncApi {
56596
56601
  yield this.processSyncResponse(syncEventData, data);
56597
56602
  }
56598
56603
  catch (e) {
56599
- logger_1.logger.error("Error processing cached sync", e.stack || e);
56604
+ logger_1.logger.error("Error processing cached sync", e);
56600
56605
  }
56601
56606
  // Don't emit a prepared if we've bailed because the store is invalid:
56602
56607
  // in this case the client will not be usable until stopped & restarted
@@ -56664,7 +56669,7 @@ class SyncApi {
56664
56669
  catch (e) {
56665
56670
  // log the exception with stack if we have it, else fall back
56666
56671
  // to the plain description
56667
- logger_1.logger.error("Caught /sync error", e.stack || e);
56672
+ logger_1.logger.error("Caught /sync error", e);
56668
56673
  // Emit the exception for client handling
56669
56674
  this.client.emit(client_1.ClientEvent.SyncUnexpectedError, e);
56670
56675
  }
@@ -56801,6 +56806,7 @@ class SyncApi {
56801
56806
  * @param {Object} data The response from /sync
56802
56807
  */
56803
56808
  processSyncResponse(syncEventData, data) {
56809
+ var _a;
56804
56810
  return __awaiter(this, void 0, void 0, function* () {
56805
56811
  const client = this.client;
56806
56812
  // data looks like:
@@ -56840,20 +56846,7 @@ class SyncApi {
56840
56846
  // timeline: { events: [], prev_batch: $token }
56841
56847
  // }
56842
56848
  // }
56843
- // },
56844
- // groups: {
56845
- // invite: {
56846
- // $groupId: {
56847
- // inviter: $inviter,
56848
- // profile: {
56849
- // avatar_url: $avatarUrl,
56850
- // name: $groupName,
56851
- // },
56852
- // },
56853
- // },
56854
- // join: {},
56855
- // leave: {},
56856
- // },
56849
+ // }
56857
56850
  // }
56858
56851
  // TODO-arch:
56859
56852
  // - Each event we pass through needs to be emitted via 'event', can we
@@ -56897,8 +56890,7 @@ class SyncApi {
56897
56890
  });
56898
56891
  }
56899
56892
  // handle to-device events
56900
- if (data.to_device && Array.isArray(data.to_device.events) &&
56901
- data.to_device.events.length > 0) {
56893
+ if (Array.isArray((_a = data.to_device) === null || _a === void 0 ? void 0 : _a.events) && data.to_device.events.length > 0) {
56902
56894
  const cancelledKeyVerificationTxns = [];
56903
56895
  data.to_device.events
56904
56896
  .map(client.getEventMapper())
@@ -56941,17 +56933,6 @@ class SyncApi {
56941
56933
  // no more to-device events: we can stop polling with a short timeout.
56942
56934
  this.catchingUp = false;
56943
56935
  }
56944
- if (data.groups) {
56945
- if (data.groups.invite) {
56946
- this.processGroupSyncEntry(data.groups.invite, sync_accumulator_1.Category.Invite);
56947
- }
56948
- if (data.groups.join) {
56949
- this.processGroupSyncEntry(data.groups.join, sync_accumulator_1.Category.Join);
56950
- }
56951
- if (data.groups.leave) {
56952
- this.processGroupSyncEntry(data.groups.leave, sync_accumulator_1.Category.Leave);
56953
- }
56954
- }
56955
56936
  // the returned json structure is a bit crap, so make it into a
56956
56937
  // nicer form (array) after applying sanity to make sure we don't fail
56957
56938
  // on missing keys (on the off chance)
@@ -56971,10 +56952,10 @@ class SyncApi {
56971
56952
  }
56972
56953
  this.notifEvents = [];
56973
56954
  // Handle invites
56974
- inviteRooms.forEach((inviteObj) => {
56955
+ yield utils.promiseMapSeries(inviteRooms, (inviteObj) => __awaiter(this, void 0, void 0, function* () {
56975
56956
  const room = inviteObj.room;
56976
56957
  const stateEvents = this.mapSyncEventsFormat(inviteObj.invite_state, room);
56977
- this.processRoomEvents(room, stateEvents);
56958
+ yield this.processRoomEvents(room, stateEvents);
56978
56959
  if (inviteObj.isBrandNewRoom) {
56979
56960
  room.recalculate();
56980
56961
  client.store.storeRoom(room);
@@ -56984,7 +56965,7 @@ class SyncApi {
56984
56965
  client.emit(client_1.ClientEvent.Event, e);
56985
56966
  });
56986
56967
  room.updateMyMembership("invite");
56987
- });
56968
+ }));
56988
56969
  // Handle joins
56989
56970
  yield utils.promiseMapSeries(joinRooms, (joinObj) => __awaiter(this, void 0, void 0, function* () {
56990
56971
  const room = joinObj.room;
@@ -57059,9 +57040,7 @@ class SyncApi {
57059
57040
  this.registerStateListeners(room);
57060
57041
  }
57061
57042
  }
57062
- const [timelineEvents, threadedEvents] = this.client.partitionThreadedEvents(events);
57063
- this.processRoomEvents(room, stateEvents, timelineEvents, syncEventData.fromCache);
57064
- yield this.processThreadEvents(room, threadedEvents, false);
57043
+ yield this.processRoomEvents(room, stateEvents, events, syncEventData.fromCache);
57065
57044
  // set summary after processing events,
57066
57045
  // because it will trigger a name calculation
57067
57046
  // which needs the room state to be up to date
@@ -57096,8 +57075,7 @@ class SyncApi {
57096
57075
  }
57097
57076
  });
57098
57077
  yield utils.promiseMapSeries(stateEvents, processRoomEvent);
57099
- yield utils.promiseMapSeries(timelineEvents, processRoomEvent);
57100
- yield utils.promiseMapSeries(threadedEvents, processRoomEvent);
57078
+ yield utils.promiseMapSeries(events, processRoomEvent);
57101
57079
  ephemeralEvents.forEach(function (e) {
57102
57080
  client.emit(client_1.ClientEvent.Event, e);
57103
57081
  });
@@ -57111,14 +57089,12 @@ class SyncApi {
57111
57089
  room.decryptCriticalEvents();
57112
57090
  }));
57113
57091
  // Handle leaves (e.g. kicked rooms)
57114
- leaveRooms.forEach((leaveObj) => __awaiter(this, void 0, void 0, function* () {
57092
+ yield utils.promiseMapSeries(leaveRooms, (leaveObj) => __awaiter(this, void 0, void 0, function* () {
57115
57093
  const room = leaveObj.room;
57116
57094
  const stateEvents = this.mapSyncEventsFormat(leaveObj.state, room);
57117
57095
  const events = this.mapSyncEventsFormat(leaveObj.timeline, room);
57118
57096
  const accountDataEvents = this.mapSyncEventsFormat(leaveObj.account_data);
57119
- const [timelineEvents, threadedEvents] = this.client.partitionThreadedEvents(events);
57120
- this.processRoomEvents(room, stateEvents, timelineEvents);
57121
- yield this.processThreadEvents(room, threadedEvents, false);
57097
+ yield this.processRoomEvents(room, stateEvents, events);
57122
57098
  room.addAccountData(accountDataEvents);
57123
57099
  room.recalculate();
57124
57100
  if (leaveObj.isBrandNewRoom) {
@@ -57129,10 +57105,7 @@ class SyncApi {
57129
57105
  stateEvents.forEach(function (e) {
57130
57106
  client.emit(client_1.ClientEvent.Event, e);
57131
57107
  });
57132
- timelineEvents.forEach(function (e) {
57133
- client.emit(client_1.ClientEvent.Event, e);
57134
- });
57135
- threadedEvents.forEach(function (e) {
57108
+ events.forEach(function (e) {
57136
57109
  client.emit(client_1.ClientEvent.Event, e);
57137
57110
  });
57138
57111
  accountDataEvents.forEach(function (e) {
@@ -57254,32 +57227,6 @@ class SyncApi {
57254
57227
  }
57255
57228
  });
57256
57229
  }
57257
- /**
57258
- * @param {Object} groupsSection Groups section object, eg. response.groups.invite
57259
- * @param {string} sectionName Which section this is ('invite', 'join' or 'leave')
57260
- */
57261
- processGroupSyncEntry(groupsSection, sectionName) {
57262
- // Processes entries from 'groups' section of the sync stream
57263
- for (const groupId of Object.keys(groupsSection)) {
57264
- const groupInfo = groupsSection[groupId];
57265
- let group = this.client.store.getGroup(groupId);
57266
- const isBrandNew = group === null;
57267
- if (group === null) {
57268
- group = this.createGroup(groupId);
57269
- }
57270
- if (groupInfo.profile) {
57271
- group.setProfile(groupInfo.profile.name, groupInfo.profile.avatar_url);
57272
- }
57273
- if (groupInfo.inviter) {
57274
- group.setInviter({ userId: groupInfo.inviter });
57275
- }
57276
- group.setMyMembership(sectionName);
57277
- if (isBrandNew) {
57278
- // Now we've filled in all the fields, emit the Group event
57279
- this.client.emit(client_1.ClientEvent.Group, group);
57280
- }
57281
- }
57282
- }
57283
57230
  /**
57284
57231
  * @param {Object} obj
57285
57232
  * @return {Object[]}
@@ -57368,62 +57315,66 @@ class SyncApi {
57368
57315
  * @param {Room} room
57369
57316
  * @param {MatrixEvent[]} stateEventList A list of state events. This is the state
57370
57317
  * at the *START* of the timeline list if it is supplied.
57371
- * @param {MatrixEvent[]} [timelineEventList] A list of timeline events. Lower index
57318
+ * @param {MatrixEvent[]} [timelineEventList] A list of timeline events, including threaded. Lower index
57372
57319
  * @param {boolean} fromCache whether the sync response came from cache
57373
57320
  * is earlier in time. Higher index is later.
57374
57321
  */
57375
57322
  processRoomEvents(room, stateEventList, timelineEventList, fromCache = false) {
57376
- // If there are no events in the timeline yet, initialise it with
57377
- // the given state events
57378
- const liveTimeline = room.getLiveTimeline();
57379
- const timelineWasEmpty = liveTimeline.getEvents().length == 0;
57380
- if (timelineWasEmpty) {
57381
- // Passing these events into initialiseState will freeze them, so we need
57382
- // to compute and cache the push actions for them now, otherwise sync dies
57383
- // with an attempt to assign to read only property.
57384
- // XXX: This is pretty horrible and is assuming all sorts of behaviour from
57385
- // these functions that it shouldn't be. We should probably either store the
57386
- // push actions cache elsewhere so we can freeze MatrixEvents, or otherwise
57387
- // find some solution where MatrixEvents are immutable but allow for a cache
57388
- // field.
57389
- for (const ev of stateEventList) {
57390
- this.client.getPushActionsForEvent(ev);
57391
- }
57392
- liveTimeline.initialiseState(stateEventList);
57393
- }
57394
- this.resolveInvites(room);
57395
- // recalculate the room name at this point as adding events to the timeline
57396
- // may make notifications appear which should have the right name.
57397
- // XXX: This looks suspect: we'll end up recalculating the room once here
57398
- // and then again after adding events (processSyncResponse calls it after
57399
- // calling us) even if no state events were added. It also means that if
57400
- // one of the room events in timelineEventList is something that needs
57401
- // a recalculation (like m.room.name) we won't recalculate until we've
57402
- // finished adding all the events, which will cause the notification to have
57403
- // the old room name rather than the new one.
57404
- room.recalculate();
57405
- // If the timeline wasn't empty, we process the state events here: they're
57406
- // defined as updates to the state before the start of the timeline, so this
57407
- // starts to roll the state forward.
57408
- // XXX: That's what we *should* do, but this can happen if we were previously
57409
- // peeking in a room, in which case we obviously do *not* want to add the
57410
- // state events here onto the end of the timeline. Historically, the js-sdk
57411
- // has just set these new state events on the old and new state. This seems
57412
- // very wrong because there could be events in the timeline that diverge the
57413
- // state, in which case this is going to leave things out of sync. However,
57414
- // for now I think it;s best to behave the same as the code has done previously.
57415
- if (!timelineWasEmpty) {
57416
- // XXX: As above, don't do this...
57417
- //room.addLiveEvents(stateEventList || []);
57418
- // Do this instead...
57419
- room.oldState.setStateEvents(stateEventList || []);
57420
- room.currentState.setStateEvents(stateEventList || []);
57421
- }
57422
- // execute the timeline events. This will continue to diverge the current state
57423
- // if the timeline has any state events in it.
57424
- // This also needs to be done before running push rules on the events as they need
57425
- // to be decorated with sender etc.
57426
- room.addLiveEvents(timelineEventList || [], null, fromCache);
57323
+ return __awaiter(this, void 0, void 0, function* () {
57324
+ // If there are no events in the timeline yet, initialise it with
57325
+ // the given state events
57326
+ const liveTimeline = room.getLiveTimeline();
57327
+ const timelineWasEmpty = liveTimeline.getEvents().length == 0;
57328
+ if (timelineWasEmpty) {
57329
+ // Passing these events into initialiseState will freeze them, so we need
57330
+ // to compute and cache the push actions for them now, otherwise sync dies
57331
+ // with an attempt to assign to read only property.
57332
+ // XXX: This is pretty horrible and is assuming all sorts of behaviour from
57333
+ // these functions that it shouldn't be. We should probably either store the
57334
+ // push actions cache elsewhere so we can freeze MatrixEvents, or otherwise
57335
+ // find some solution where MatrixEvents are immutable but allow for a cache
57336
+ // field.
57337
+ for (const ev of stateEventList) {
57338
+ this.client.getPushActionsForEvent(ev);
57339
+ }
57340
+ liveTimeline.initialiseState(stateEventList);
57341
+ }
57342
+ this.resolveInvites(room);
57343
+ // recalculate the room name at this point as adding events to the timeline
57344
+ // may make notifications appear which should have the right name.
57345
+ // XXX: This looks suspect: we'll end up recalculating the room once here
57346
+ // and then again after adding events (processSyncResponse calls it after
57347
+ // calling us) even if no state events were added. It also means that if
57348
+ // one of the room events in timelineEventList is something that needs
57349
+ // a recalculation (like m.room.name) we won't recalculate until we've
57350
+ // finished adding all the events, which will cause the notification to have
57351
+ // the old room name rather than the new one.
57352
+ room.recalculate();
57353
+ // If the timeline wasn't empty, we process the state events here: they're
57354
+ // defined as updates to the state before the start of the timeline, so this
57355
+ // starts to roll the state forward.
57356
+ // XXX: That's what we *should* do, but this can happen if we were previously
57357
+ // peeking in a room, in which case we obviously do *not* want to add the
57358
+ // state events here onto the end of the timeline. Historically, the js-sdk
57359
+ // has just set these new state events on the old and new state. This seems
57360
+ // very wrong because there could be events in the timeline that diverge the
57361
+ // state, in which case this is going to leave things out of sync. However,
57362
+ // for now I think it;s best to behave the same as the code has done previously.
57363
+ if (!timelineWasEmpty) {
57364
+ // XXX: As above, don't do this...
57365
+ //room.addLiveEvents(stateEventList || []);
57366
+ // Do this instead...
57367
+ room.oldState.setStateEvents(stateEventList || []);
57368
+ room.currentState.setStateEvents(stateEventList || []);
57369
+ }
57370
+ // Execute the timeline events. This will continue to diverge the current state
57371
+ // if the timeline has any state events in it.
57372
+ // This also needs to be done before running push rules on the events as they need
57373
+ // to be decorated with sender etc.
57374
+ const [mainTimelineEvents, threadedEvents] = this.client.partitionThreadedEvents(room, timelineEventList || []);
57375
+ room.addLiveEvents(mainTimelineEvents, null, fromCache);
57376
+ yield this.processThreadEvents(room, threadedEvents, false);
57377
+ });
57427
57378
  }
57428
57379
  /**
57429
57380
  * @experimental
@@ -57498,7 +57449,7 @@ function createNewUser(client, userId) {
57498
57449
 
57499
57450
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
57500
57451
 
57501
- },{"./@types/event":77,"./client":87,"./errors":122,"./filter":125,"./http-api":126,"./logger":129,"./models/event-timeline":136,"./models/group":138,"./models/room":143,"./models/room-member":140,"./models/room-state":141,"./models/user":147,"./pushprocessor":148,"./sync-accumulator":159,"./utils":162}],161:[function(require,module,exports){
57452
+ },{"./@types/event":78,"./client":88,"./errors":123,"./filter":126,"./http-api":127,"./logger":130,"./models/beacon":134,"./models/event-timeline":138,"./models/room":144,"./models/room-member":141,"./models/room-state":142,"./models/user":148,"./pushprocessor":149,"./utils":163}],162:[function(require,module,exports){
57502
57453
  "use strict";
57503
57454
  /*
57504
57455
  Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
@@ -57596,13 +57547,8 @@ class TimelineWindow {
57596
57547
  eventIndex = events.length;
57597
57548
  }
57598
57549
  else {
57599
- for (let i = 0; i < events.length; i++) {
57600
- if (events[i].getId() == initialEventId) {
57601
- eventIndex = i;
57602
- break;
57603
- }
57604
- }
57605
- if (eventIndex === undefined) {
57550
+ eventIndex = events.findIndex(e => e.getId() === initialEventId);
57551
+ if (eventIndex < 0) {
57606
57552
  throw new Error("getEventTimeline result didn't include requested event");
57607
57553
  }
57608
57554
  }
@@ -57612,19 +57558,16 @@ class TimelineWindow {
57612
57558
  this.end = new TimelineIndex(timeline, endIndex - timeline.getBaseIndex());
57613
57559
  this.eventCount = endIndex - startIndex;
57614
57560
  };
57615
- // We avoid delaying the resolution of the promise by a reactor tick if
57616
- // we already have the data we need, which is important to keep room-switching
57617
- // feeling snappy.
57618
- //
57561
+ // We avoid delaying the resolution of the promise by a reactor tick if we already have the data we need,
57562
+ // which is important to keep room-switching feeling snappy.
57619
57563
  if (initialEventId) {
57620
57564
  const timeline = this.timelineSet.getTimelineForEvent(initialEventId);
57621
57565
  if (timeline) {
57622
57566
  // hot-path optimization to save a reactor tick by replicating the sync check getTimelineForEvent does.
57623
57567
  initFields(timeline);
57624
- return Promise.resolve(timeline);
57568
+ return Promise.resolve();
57625
57569
  }
57626
- const prom = this.client.getEventTimeline(this.timelineSet, initialEventId);
57627
- return prom.then(initFields);
57570
+ return this.client.getEventTimeline(this.timelineSet, initialEventId).then(initFields);
57628
57571
  }
57629
57572
  else {
57630
57573
  const tl = this.timelineSet.getLiveTimeline();
@@ -57714,7 +57657,7 @@ class TimelineWindow {
57714
57657
  }
57715
57658
  }
57716
57659
  return Boolean(tl.timeline.getNeighbouringTimeline(direction) ||
57717
- tl.timeline.getPaginationToken(direction));
57660
+ tl.timeline.getPaginationToken(direction) !== null);
57718
57661
  }
57719
57662
  /**
57720
57663
  * Attempt to extend the window
@@ -57760,7 +57703,7 @@ class TimelineWindow {
57760
57703
  }
57761
57704
  // try making a pagination request
57762
57705
  const token = tl.timeline.getPaginationToken(direction);
57763
- if (!token) {
57706
+ if (token === null) {
57764
57707
  debuglog("TimelineWindow: no token");
57765
57708
  return Promise.resolve(false);
57766
57709
  }
@@ -57964,7 +57907,7 @@ class TimelineIndex {
57964
57907
  }
57965
57908
  exports.TimelineIndex = TimelineIndex;
57966
57909
 
57967
- },{"./logger":129,"./models/event-timeline":136}],162:[function(require,module,exports){
57910
+ },{"./logger":130,"./models/event-timeline":138}],163:[function(require,module,exports){
57968
57911
  "use strict";
57969
57912
  /*
57970
57913
  Copyright 2015, 2016 OpenMarket Ltd
@@ -58649,7 +58592,7 @@ function recursivelyAssign(target, source, ignoreNullish = false) {
58649
58592
  }
58650
58593
  exports.recursivelyAssign = recursivelyAssign;
58651
58594
 
58652
- },{"p-retry":57,"unhomoglyph":73}],163:[function(require,module,exports){
58595
+ },{"p-retry":57,"unhomoglyph":73}],164:[function(require,module,exports){
58653
58596
  (function (process){(function (){
58654
58597
  "use strict";
58655
58598
  /*
@@ -60656,7 +60599,7 @@ exports.createNewMatrixCall = createNewMatrixCall;
60656
60599
 
60657
60600
  }).call(this)}).call(this,require('_process'))
60658
60601
 
60659
- },{"../@types/event":77,"../logger":129,"../models/typed-event-emitter":146,"../randomstring":149,"../utils":162,"./callEventTypes":165,"./callFeed":166,"_process":58}],164:[function(require,module,exports){
60602
+ },{"../@types/event":78,"../logger":130,"../models/typed-event-emitter":147,"../randomstring":150,"../utils":163,"./callEventTypes":166,"./callFeed":167,"_process":58}],165:[function(require,module,exports){
60660
60603
  "use strict";
60661
60604
  /*
60662
60605
  Copyright 2020 The Matrix.org Foundation C.I.C.
@@ -60951,7 +60894,7 @@ class CallEventHandler {
60951
60894
  }
60952
60895
  exports.CallEventHandler = CallEventHandler;
60953
60896
 
60954
- },{"../@types/event":77,"../client":87,"../logger":129,"../models/event":137,"../models/room":143,"../sync":160,"./call":163}],165:[function(require,module,exports){
60897
+ },{"../@types/event":78,"../client":88,"../logger":130,"../models/event":139,"../models/room":144,"../sync":161,"./call":164}],166:[function(require,module,exports){
60955
60898
  "use strict";
60956
60899
  // allow non-camelcase as these are events type that go onto the wire
60957
60900
  /* eslint-disable camelcase */
@@ -60966,7 +60909,7 @@ var SDPStreamMetadataPurpose;
60966
60909
  })(SDPStreamMetadataPurpose = exports.SDPStreamMetadataPurpose || (exports.SDPStreamMetadataPurpose = {}));
60967
60910
  /* eslint-enable camelcase */
60968
60911
 
60969
- },{}],166:[function(require,module,exports){
60912
+ },{}],167:[function(require,module,exports){
60970
60913
  "use strict";
60971
60914
  /*
60972
60915
  Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
@@ -61166,7 +61109,7 @@ class CallFeed extends typed_event_emitter_1.TypedEventEmitter {
61166
61109
  }
61167
61110
  exports.CallFeed = CallFeed;
61168
61111
 
61169
- },{"../models/typed-event-emitter":146}],167:[function(require,module,exports){
61112
+ },{"../models/typed-event-emitter":147}],168:[function(require,module,exports){
61170
61113
  "use strict";
61171
61114
  /*
61172
61115
  Copyright 2015, 2016 OpenMarket Ltd
@@ -61450,5 +61393,5 @@ class MediaHandler {
61450
61393
  }
61451
61394
  exports.MediaHandler = MediaHandler;
61452
61395
 
61453
- },{"../logger":129,"./call":163}]},{},[86])
61396
+ },{"../logger":130,"./call":164}]},{},[87])
61454
61397
  //# sourceMappingURL=browser-matrix.js.map