@unwanted/matrix-sdk-mini 34.12.0-7 → 34.12.0-9

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 (64) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/autodiscovery.js +3 -3
  3. package/lib/autodiscovery.js.map +1 -1
  4. package/lib/client.d.ts.map +1 -1
  5. package/lib/client.js +21 -21
  6. package/lib/client.js.map +1 -1
  7. package/lib/content-repo.js +2 -2
  8. package/lib/content-repo.js.map +1 -1
  9. package/lib/embedded.d.ts.map +1 -1
  10. package/lib/embedded.js +35 -2
  11. package/lib/embedded.js.map +1 -1
  12. package/lib/http-api/prefix.d.ts +6 -7
  13. package/lib/http-api/prefix.d.ts.map +1 -1
  14. package/lib/http-api/prefix.js +6 -7
  15. package/lib/http-api/prefix.js.map +1 -1
  16. package/lib/models/event-timeline-set.d.ts +6 -10
  17. package/lib/models/event-timeline-set.d.ts.map +1 -1
  18. package/lib/models/event-timeline-set.js +28 -36
  19. package/lib/models/event-timeline-set.js.map +1 -1
  20. package/lib/models/event-timeline.d.ts +7 -2
  21. package/lib/models/event-timeline.d.ts.map +1 -1
  22. package/lib/models/event-timeline.js +8 -9
  23. package/lib/models/event-timeline.js.map +1 -1
  24. package/lib/models/event.d.ts.map +1 -1
  25. package/lib/models/event.js +1 -1
  26. package/lib/models/event.js.map +1 -1
  27. package/lib/models/room-state.d.ts +2 -13
  28. package/lib/models/room-state.d.ts.map +1 -1
  29. package/lib/models/room-state.js +2 -30
  30. package/lib/models/room-state.js.map +1 -1
  31. package/lib/models/room.d.ts +2 -2
  32. package/lib/models/room.d.ts.map +1 -1
  33. package/lib/models/room.js +27 -14
  34. package/lib/models/room.js.map +1 -1
  35. package/lib/models/thread.d.ts.map +1 -1
  36. package/lib/models/thread.js +5 -3
  37. package/lib/models/thread.js.map +1 -1
  38. package/lib/sliding-sync-sdk.d.ts +1 -1
  39. package/lib/sliding-sync-sdk.d.ts.map +1 -1
  40. package/lib/sliding-sync-sdk.js +15 -13
  41. package/lib/sliding-sync-sdk.js.map +1 -1
  42. package/lib/sync-accumulator.d.ts +6 -4
  43. package/lib/sync-accumulator.d.ts.map +1 -1
  44. package/lib/sync-accumulator.js +23 -12
  45. package/lib/sync-accumulator.js.map +1 -1
  46. package/lib/sync.d.ts +10 -1
  47. package/lib/sync.d.ts.map +1 -1
  48. package/lib/sync.js +95 -44
  49. package/lib/sync.js.map +1 -1
  50. package/package.json +7 -7
  51. package/src/autodiscovery.ts +3 -3
  52. package/src/client.ts +20 -21
  53. package/src/content-repo.ts +2 -2
  54. package/src/embedded.ts +35 -2
  55. package/src/http-api/prefix.ts +6 -8
  56. package/src/models/event-timeline-set.ts +17 -38
  57. package/src/models/event-timeline.ts +10 -5
  58. package/src/models/event.ts +3 -1
  59. package/src/models/room-state.ts +2 -29
  60. package/src/models/room.ts +18 -6
  61. package/src/models/thread.ts +4 -2
  62. package/src/sliding-sync-sdk.ts +8 -11
  63. package/src/sync-accumulator.ts +33 -16
  64. package/src/sync.ts +113 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unwanted/matrix-sdk-mini",
3
- "version": "34.12.0-7",
3
+ "version": "34.12.0-9",
4
4
  "description": "Matrix Client-Server mini SDK for Javascript",
5
5
  "engines": {
6
6
  "node": ">=20.0.0"
@@ -59,7 +59,7 @@
59
59
  "matrix-widget-api": "^1.10.0",
60
60
  "oidc-client-ts": "^3.0.1",
61
61
  "p-retry": "4",
62
- "sdp-transform": "^2.14.1",
62
+ "sdp-transform": "^2.15.0",
63
63
  "unhomoglyph": "^1.0.6",
64
64
  "uuid": "11"
65
65
  },
@@ -98,7 +98,7 @@
98
98
  "eslint-import-resolver-typescript": "^3.5.1",
99
99
  "eslint-plugin-import": "^2.26.0",
100
100
  "eslint-plugin-jest": "^28.0.0",
101
- "eslint-plugin-jsdoc": "^50.0.0",
101
+ "eslint-plugin-jsdoc": "^50.6.0",
102
102
  "eslint-plugin-matrix-org": "^2.0.1",
103
103
  "eslint-plugin-n": "^14.0.0",
104
104
  "eslint-plugin-tsdoc": "^0.3.0",
@@ -111,15 +111,15 @@
111
111
  "jest-environment-jsdom": "^29.0.0",
112
112
  "jest-localstorage-mock": "^2.4.6",
113
113
  "jest-mock": "^29.0.0",
114
- "knip": "^5.0.0",
114
+ "knip": "^5.38.1",
115
115
  "lint-staged": "^15.0.2",
116
116
  "matrix-mock-request": "^2.5.0",
117
117
  "node-fetch": "^2.7.0",
118
- "prettier": "3.3.3",
118
+ "prettier": "3.4.1",
119
119
  "rimraf": "^6.0.0",
120
120
  "ts-node": "^10.9.2",
121
121
  "typedoc": "^0.26.0",
122
- "typedoc-plugin-coverage": "^3.0.0",
122
+ "typedoc-plugin-coverage": "^3.4.0",
123
123
  "typedoc-plugin-mdn-links": "^3.0.3",
124
124
  "typedoc-plugin-missing-exports": "^3.0.0",
125
125
  "typescript": "^5.4.2"
@@ -130,4 +130,4 @@
130
130
  "relativePaths": true
131
131
  },
132
132
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
133
- }
133
+ }
@@ -17,7 +17,7 @@ limitations under the License.
17
17
 
18
18
  import { IClientWellKnown, IWellKnownConfig, IServerVersions } from "./client.ts";
19
19
  import { logger } from "./logger.ts";
20
- import { MatrixError, Method, timeoutSignal, VersionsPrefix } from "./http-api/index.ts";
20
+ import { MatrixError, Method, timeoutSignal } from "./http-api/index.ts";
21
21
  import { SUPPORTED_MATRIX_VERSIONS } from "./version-support.ts";
22
22
 
23
23
  // Dev note: Auto discovery is part of the spec.
@@ -179,7 +179,7 @@ export class AutoDiscovery {
179
179
  }
180
180
 
181
181
  // Step 3: Make sure the homeserver URL points to a homeserver.
182
- const hsVersions = await this.fetchWellKnownObject<IServerVersions>(`${hsUrl}${VersionsPrefix}`);
182
+ const hsVersions = await this.fetchWellKnownObject<IServerVersions>(`${hsUrl}/_matrix/client/versions`);
183
183
  if (!hsVersions || !Array.isArray(hsVersions.raw?.["versions"])) {
184
184
  logger.error("Invalid /versions response");
185
185
  clientConfig["m.homeserver"].error = AutoDiscovery.ERROR_INVALID_HOMESERVER;
@@ -244,7 +244,7 @@ export class AutoDiscovery {
244
244
 
245
245
  // Step 5b: Verify there is an identity server listening on the provided
246
246
  // URL.
247
- const isResponse = await this.fetchWellKnownObject(`${isUrl}/im/_matrix/identity/v2`);
247
+ const isResponse = await this.fetchWellKnownObject(`${isUrl}/_matrix/identity/v2`);
248
248
  if (!isResponse?.raw || isResponse.action !== AutoDiscoveryAction.SUCCESS) {
249
249
  logger.error("Invalid /v2 response");
250
250
  failingClientConfig["m.identity_server"].error = AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER;
package/src/client.ts CHANGED
@@ -60,7 +60,6 @@ import {
60
60
  Upload,
61
61
  UploadOpts,
62
62
  UploadResponse,
63
- VersionsPrefix,
64
63
  } from "./http-api/index.ts";
65
64
  import { User, UserEvent, UserEventHandlerMap } from "./models/user.ts";
66
65
  import { getHttpUriForMxc } from "./content-repo.ts";
@@ -1694,7 +1693,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
1694
1693
  });
1695
1694
  const options =
1696
1695
  msc3391DeleteAccountDataServerSupport === ServerSupport.Unstable
1697
- ? { prefix: "/im/_matrix/client/unstable/org.matrix.msc3391" }
1696
+ ? { prefix: "/_matrix/client/unstable/org.matrix.msc3391" }
1698
1697
  : undefined;
1699
1698
  return await this.http.authedRequest(Method.Delete, path, undefined, undefined, options);
1700
1699
  }
@@ -3457,7 +3456,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3457
3456
  room.partitionThreadedEvents(matrixEvents);
3458
3457
 
3459
3458
  this.processAggregatedTimelineEvents(room, timelineEvents);
3460
- room.addEventsToTimeline(timelineEvents, true, room.getLiveTimeline());
3459
+ room.addEventsToTimeline(timelineEvents, true, true, room.getLiveTimeline());
3461
3460
  this.processThreadEvents(room, threadedEvents, true);
3462
3461
  unknownRelations.forEach((event) => room.relations.aggregateChildEvent(event));
3463
3462
 
@@ -3569,7 +3568,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3569
3568
  }
3570
3569
 
3571
3570
  const [timelineEvents, threadedEvents, unknownRelations] = timelineSet.room.partitionThreadedEvents(events);
3572
- timelineSet.addEventsToTimeline(timelineEvents, true, timeline, res.start);
3571
+ timelineSet.addEventsToTimeline(timelineEvents, true, false, timeline, res.start);
3573
3572
  // The target event is not in a thread but process the contextual events, so we can show any threads around it.
3574
3573
  this.processThreadEvents(timelineSet.room, threadedEvents, true);
3575
3574
  this.processAggregatedTimelineEvents(timelineSet.room, timelineEvents);
@@ -3663,10 +3662,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3663
3662
  timeline.initialiseState(res.state.map(mapper));
3664
3663
  }
3665
3664
 
3666
- timelineSet.addEventsToTimeline(events, true, timeline, resNewer.next_batch);
3665
+ timelineSet.addEventsToTimeline(events, true, false, timeline, resNewer.next_batch);
3667
3666
  if (!resOlder.next_batch) {
3668
3667
  const originalEvent = await this.fetchRoomEvent(timelineSet.room.roomId, thread.id);
3669
- timelineSet.addEventsToTimeline([mapper(originalEvent)], true, timeline, null);
3668
+ timelineSet.addEventsToTimeline([mapper(originalEvent)], true, false, timeline, null);
3670
3669
  }
3671
3670
  timeline.setPaginationToken(resOlder.next_batch ?? null, Direction.Backward);
3672
3671
  timeline.setPaginationToken(resNewer.next_batch ?? null, Direction.Forward);
@@ -3720,10 +3719,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3720
3719
  const timeline = timelineSet.getLiveTimeline();
3721
3720
  timeline.getState(EventTimeline.BACKWARDS)!.setUnknownStateEvents(res.state.map(mapper));
3722
3721
 
3723
- timelineSet.addEventsToTimeline(events, true, timeline, null);
3722
+ timelineSet.addEventsToTimeline(events, true, false, timeline, null);
3724
3723
  if (!resOlder.next_batch) {
3725
3724
  const originalEvent = await this.fetchRoomEvent(timelineSet.room.roomId, thread.id);
3726
- timelineSet.addEventsToTimeline([mapper(originalEvent)], true, timeline, null);
3725
+ timelineSet.addEventsToTimeline([mapper(originalEvent)], true, false, timeline, null);
3727
3726
  }
3728
3727
  timeline.setPaginationToken(resOlder.next_batch ?? null, Direction.Backward);
3729
3728
  timeline.setPaginationToken(null, Direction.Forward);
@@ -3900,7 +3899,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3900
3899
  prefix:
3901
3900
  Thread.hasServerSideListSupport === FeatureSupport.Stable
3902
3901
  ? ClientPrefix.V1
3903
- : "/im/_matrix/client/unstable/org.matrix.msc3856",
3902
+ : "/_matrix/client/unstable/org.matrix.msc3856",
3904
3903
  };
3905
3904
 
3906
3905
  return this.http
@@ -3986,7 +3985,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3986
3985
  // No need to partition events for threads here, everything lives
3987
3986
  // in the notification timeline set
3988
3987
  const timelineSet = eventTimeline.getTimelineSet();
3989
- timelineSet.addEventsToTimeline(matrixEvents, backwards, eventTimeline, token);
3988
+ timelineSet.addEventsToTimeline(matrixEvents, backwards, false, eventTimeline, token);
3990
3989
  this.processAggregatedTimelineEvents(timelineSet.room, matrixEvents);
3991
3990
 
3992
3991
  // if we've hit the end of the timeline, we need to stop trying to
@@ -4029,7 +4028,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4029
4028
  const matrixEvents = res.chunk.filter(noUnsafeEventProps).map(this.getEventMapper());
4030
4029
 
4031
4030
  const timelineSet = eventTimeline.getTimelineSet();
4032
- timelineSet.addEventsToTimeline(matrixEvents, backwards, eventTimeline, token);
4031
+ timelineSet.addEventsToTimeline(matrixEvents, backwards, false, eventTimeline, token);
4033
4032
  this.processAggregatedTimelineEvents(room, matrixEvents);
4034
4033
  this.processThreadRoots(room, matrixEvents, backwards);
4035
4034
 
@@ -4077,12 +4076,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4077
4076
  const newToken = res.next_batch;
4078
4077
 
4079
4078
  const timelineSet = eventTimeline.getTimelineSet();
4080
- timelineSet.addEventsToTimeline(matrixEvents, backwards, eventTimeline, newToken ?? null);
4079
+ timelineSet.addEventsToTimeline(matrixEvents, backwards, false, eventTimeline, newToken ?? null);
4081
4080
  if (!newToken && backwards) {
4082
4081
  const originalEvent =
4083
4082
  thread.rootEvent ??
4084
4083
  mapper(await this.fetchRoomEvent(eventTimeline.getRoomId() ?? "", thread.id));
4085
- timelineSet.addEventsToTimeline([originalEvent], true, eventTimeline, null);
4084
+ timelineSet.addEventsToTimeline([originalEvent], true, false, eventTimeline, null);
4086
4085
  }
4087
4086
  this.processAggregatedTimelineEvents(timelineSet.room, matrixEvents);
4088
4087
 
@@ -4121,7 +4120,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4121
4120
 
4122
4121
  const timelineSet = eventTimeline.getTimelineSet();
4123
4122
  const [timelineEvents, , unknownRelations] = room.partitionThreadedEvents(matrixEvents);
4124
- timelineSet.addEventsToTimeline(timelineEvents, backwards, eventTimeline, token);
4123
+ timelineSet.addEventsToTimeline(timelineEvents, backwards, false, eventTimeline, token);
4125
4124
  this.processAggregatedTimelineEvents(room, timelineEvents);
4126
4125
  this.processThreadRoots(
4127
4126
  room,
@@ -5020,7 +5019,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
5020
5019
 
5021
5020
  // We send an authenticated request as of MSC4026
5022
5021
  this.serverVersionsPromise = this.http
5023
- .authedRequest<IServerVersions>(Method.Get, VersionsPrefix, undefined, undefined, {
5022
+ .authedRequest<IServerVersions>(Method.Get, "/_matrix/client/versions", undefined, undefined, {
5024
5023
  prefix: "",
5025
5024
  })
5026
5025
  .catch((e) => {
@@ -5219,7 +5218,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
5219
5218
  case SERVICE_TYPES.IS:
5220
5219
  return this.http.getUrl("/terms", undefined, IdentityPrefix.V2, baseUrl);
5221
5220
  case SERVICE_TYPES.IM:
5222
- return this.http.getUrl("/terms", undefined, "/im/_matrix/integrations/v1", baseUrl);
5221
+ return this.http.getUrl("/terms", undefined, "/_matrix/integrations/v1", baseUrl);
5223
5222
  default:
5224
5223
  throw new Error("Unsupported service type");
5225
5224
  }
@@ -6056,7 +6055,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
6056
6055
  if (await this.doesServerSupportUnstableFeature("uk.tcpip.msc4133.stable")) {
6057
6056
  return ClientPrefix.V3;
6058
6057
  }
6059
- return "/im/_matrix/client/unstable/uk.tcpip.msc4133";
6058
+ return "/_matrix/client/unstable/uk.tcpip.msc4133";
6060
6059
  }
6061
6060
 
6062
6061
  /**
@@ -7175,7 +7174,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7175
7174
  if (e.errcode === "M_UNRECOGNIZED") {
7176
7175
  // fall back to the prefixed hierarchy API.
7177
7176
  return this.http.authedRequest<IRoomHierarchy>(Method.Get, path, queryParams, undefined, {
7178
- prefix: "/im/_matrix/client/unstable/org.matrix.msc2946",
7177
+ prefix: "/_matrix/client/unstable/org.matrix.msc2946",
7179
7178
  });
7180
7179
  }
7181
7180
 
@@ -7269,7 +7268,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7269
7268
  const clientTimeout = req.clientTimeout;
7270
7269
  delete req.clientTimeout;
7271
7270
  return this.http.authedRequest<MSC3575SlidingSyncResponse>(Method.Post, "/sync", qps, req, {
7272
- prefix: "/im/_matrix/client/unstable/org.matrix.msc3575",
7271
+ prefix: "/_matrix/client/unstable/org.matrix.msc3575",
7273
7272
  baseUrl: proxyBaseUrl,
7274
7273
  localTimeoutMs: clientTimeout,
7275
7274
  abortSignal,
@@ -7301,7 +7300,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7301
7300
  */
7302
7301
  public async getRoomSummary(roomIdOrAlias: string, via?: string[]): Promise<RoomSummary> {
7303
7302
  const paramOpts = {
7304
- prefix: "/im/_matrix/client/unstable/im.nheko.summary",
7303
+ prefix: "/_matrix/client/unstable/im.nheko.summary",
7305
7304
  };
7306
7305
  try {
7307
7306
  const path = utils.encodeUri("/summary/$roomid", { $roomid: roomIdOrAlias });
@@ -7403,7 +7402,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
7403
7402
  (<MatrixError>err).httpStatus === 405)
7404
7403
  ) {
7405
7404
  return await this.http.authedRequest(Method.Get, path, queryParams, undefined, {
7406
- prefix: "/im/_matrix/client/unstable/org.matrix.msc3030",
7405
+ prefix: "/_matrix/client/unstable/org.matrix.msc3030",
7407
7406
  });
7408
7407
  }
7409
7408
 
@@ -91,9 +91,9 @@ export function getHttpUriForMxc(
91
91
  const isThumbnailRequest = !!width || !!height || !!resizeMethod;
92
92
  const verb = isThumbnailRequest ? "thumbnail" : "download";
93
93
  if (useAuthentication) {
94
- prefix = `/im/_matrix/client/v1/media/${verb}`;
94
+ prefix = `/_matrix/client/v1/media/${verb}`;
95
95
  } else {
96
- prefix = `/im/_matrix/media/v3/${verb}`;
96
+ prefix = `/_matrix/media/v3/${verb}`;
97
97
  }
98
98
 
99
99
  const url = new URL(`${prefix}/${serverName}/${mediaId}`, baseUrl);
package/src/embedded.ts CHANGED
@@ -282,7 +282,13 @@ export class RoomWidgetClient extends MatrixClient {
282
282
  const rawEvents = await this.widgetApi.readStateEvents(eventType, undefined, stateKey, [this.roomId]);
283
283
  const events = rawEvents.map((rawEvent) => new MatrixEvent(rawEvent as Partial<IEvent>));
284
284
 
285
- await this.syncApi!.injectRoomEvents(this.room!, [], events);
285
+ if (this.syncApi instanceof SyncApi) {
286
+ // Passing undefined for `stateAfterEventList` allows will make `injectRoomEvents` run in legacy mode
287
+ // -> state events in `timelineEventList` will update the state.
288
+ await this.syncApi.injectRoomEvents(this.room!, undefined, events);
289
+ } else {
290
+ await this.syncApi!.injectRoomEvents(this.room!, events); // Sliding Sync
291
+ }
286
292
  events.forEach((event) => {
287
293
  this.emit(ClientEvent.Event, event);
288
294
  logger.info(`Backfilled event ${event.getId()} ${event.getType()} ${event.getStateKey()}`);
@@ -466,7 +472,34 @@ export class RoomWidgetClient extends MatrixClient {
466
472
 
467
473
  // Only inject once we have update the txId
468
474
  await this.updateTxId(event);
469
- await this.syncApi!.injectRoomEvents(this.room!, [], [event]);
475
+
476
+ // The widget API does not tell us whether a state event came from `state_after` or not so we assume legacy behaviour for now.
477
+ if (this.syncApi instanceof SyncApi) {
478
+ // The code will want to be something like:
479
+ // ```
480
+ // if (!params.addToTimeline && !params.addToState) {
481
+ // // Passing undefined for `stateAfterEventList` makes `injectRoomEvents` run in "legacy mode"
482
+ // // -> state events part of the `timelineEventList` parameter will update the state.
483
+ // this.injectRoomEvents(this.room!, [], undefined, [event]);
484
+ // } else {
485
+ // this.injectRoomEvents(this.room!, undefined, params.addToState ? [event] : [], params.addToTimeline ? [event] : []);
486
+ // }
487
+ // ```
488
+
489
+ // Passing undefined for `stateAfterEventList` allows will make `injectRoomEvents` run in legacy mode
490
+ // -> state events in `timelineEventList` will update the state.
491
+ await this.syncApi.injectRoomEvents(this.room!, [], undefined, [event]);
492
+ } else {
493
+ // The code will want to be something like:
494
+ // ```
495
+ // if (!params.addToTimeline && !params.addToState) {
496
+ // this.injectRoomEvents(this.room!, [], [event]);
497
+ // } else {
498
+ // this.injectRoomEvents(this.room!, params.addToState ? [event] : [], params.addToTimeline ? [event] : []);
499
+ // }
500
+ // ```
501
+ await this.syncApi!.injectRoomEvents(this.room!, [], [event]); // Sliding Sync
502
+ }
470
503
  this.emit(ClientEvent.Event, event);
471
504
  this.setSyncState(SyncState.Syncing);
472
505
  logger.info(`Received event ${event.getId()} ${event.getType()} ${event.getStateKey()}`);
@@ -18,33 +18,31 @@ export enum ClientPrefix {
18
18
  /**
19
19
  * A constant representing the URI path for Client-Server API endpoints versioned at v1.
20
20
  */
21
- V1 = "/im/_matrix/client/v1",
21
+ V1 = "/_matrix/client/v1",
22
22
  /**
23
23
  * A constant representing the URI path for Client-Server API endpoints versioned at v3.
24
24
  */
25
- V3 = "/im/_matrix/client/v3",
25
+ V3 = "/_matrix/client/v3",
26
26
  /**
27
27
  * A constant representing the URI path for as-yet unspecified Client-Server HTTP APIs.
28
28
  */
29
- Unstable = "/im/_matrix/client/unstable",
29
+ Unstable = "/_matrix/client/unstable",
30
30
  }
31
31
 
32
32
  export enum IdentityPrefix {
33
33
  /**
34
34
  * URI path for the v2 identity API
35
35
  */
36
- V2 = "/im/_matrix/identity/v2",
36
+ V2 = "/_matrix/identity/v2",
37
37
  }
38
38
 
39
39
  export enum MediaPrefix {
40
40
  /**
41
41
  * A constant representing the URI path for Client-Server API Media endpoints versioned at v1.
42
42
  */
43
- V1 = "/im/_matrix/media/v1",
43
+ V1 = "/_matrix/media/v1",
44
44
  /**
45
45
  * A constant representing the URI path for Client-Server API Media endpoints versioned at v3.
46
46
  */
47
- V3 = "/im/_matrix/media/v3",
47
+ V3 = "/_matrix/media/v3",
48
48
  }
49
-
50
- export const VersionsPrefix = "/im/_matrix/client/versions";
@@ -58,13 +58,13 @@ export interface IRoomTimelineData {
58
58
  }
59
59
 
60
60
  export interface IAddEventToTimelineOptions
61
- extends Pick<IAddEventOptions, "toStartOfTimeline" | "roomState" | "timelineWasEmpty"> {
61
+ extends Pick<IAddEventOptions, "toStartOfTimeline" | "roomState" | "timelineWasEmpty" | "addToState"> {
62
62
  /** Whether the sync response came from cache */
63
63
  fromCache?: boolean;
64
64
  }
65
65
 
66
66
  export interface IAddLiveEventOptions
67
- extends Pick<IAddEventToTimelineOptions, "fromCache" | "roomState" | "timelineWasEmpty"> {
67
+ extends Pick<IAddEventToTimelineOptions, "fromCache" | "roomState" | "timelineWasEmpty" | "addToState"> {
68
68
  /** Applies to events in the timeline only. If this is 'replace' then if a
69
69
  * duplicate is encountered, the event passed to this function will replace
70
70
  * the existing event in the timeline. If this is not specified, or is
@@ -391,6 +391,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
391
391
  public addEventsToTimeline(
392
392
  events: MatrixEvent[],
393
393
  toStartOfTimeline: boolean,
394
+ addToState: boolean,
394
395
  timeline: EventTimeline,
395
396
  paginationToken?: string | null,
396
397
  ): void {
@@ -495,6 +496,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
495
496
  // we don't know about this event yet. Just add it to the timeline.
496
497
  this.addEventToTimeline(event, timeline, {
497
498
  toStartOfTimeline,
499
+ addToState,
498
500
  });
499
501
  lastEventWasNew = true;
500
502
  didUpdate = true;
@@ -592,7 +594,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
592
594
  */
593
595
  public addLiveEvent(
594
596
  event: MatrixEvent,
595
- { duplicateStrategy, fromCache, roomState, timelineWasEmpty }: IAddLiveEventOptions = {},
597
+ { duplicateStrategy, fromCache, roomState, timelineWasEmpty, addToState }: IAddLiveEventOptions,
596
598
  ): void {
597
599
  if (this.filter) {
598
600
  const events = this.filter.filterRoomTimeline([event]);
@@ -630,6 +632,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
630
632
  fromCache,
631
633
  roomState,
632
634
  timelineWasEmpty,
635
+ addToState
633
636
  });
634
637
  }
635
638
 
@@ -649,40 +652,8 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
649
652
  public addEventToTimeline(
650
653
  event: MatrixEvent,
651
654
  timeline: EventTimeline,
652
- { toStartOfTimeline, fromCache, roomState, timelineWasEmpty }: IAddEventToTimelineOptions,
653
- ): void;
654
- /**
655
- * @deprecated In favor of the overload with `IAddEventToTimelineOptions`
656
- */
657
- public addEventToTimeline(
658
- event: MatrixEvent,
659
- timeline: EventTimeline,
660
- toStartOfTimeline: boolean,
661
- fromCache?: boolean,
662
- roomState?: RoomState,
663
- ): void;
664
- public addEventToTimeline(
665
- event: MatrixEvent,
666
- timeline: EventTimeline,
667
- toStartOfTimelineOrOpts: boolean | IAddEventToTimelineOptions,
668
- fromCache = false,
669
- roomState?: RoomState,
655
+ { toStartOfTimeline, fromCache = false, roomState, timelineWasEmpty, addToState }: IAddEventToTimelineOptions,
670
656
  ): void {
671
- let toStartOfTimeline = !!toStartOfTimelineOrOpts;
672
- let timelineWasEmpty: boolean | undefined;
673
- if (typeof toStartOfTimelineOrOpts === "object") {
674
- ({ toStartOfTimeline, fromCache = false, roomState, timelineWasEmpty } = toStartOfTimelineOrOpts);
675
- } else if (toStartOfTimelineOrOpts !== undefined) {
676
- // Deprecation warning
677
- // FIXME: Remove after 2023-06-01 (technical debt)
678
- logger.warn(
679
- "Overload deprecated: " +
680
- "`EventTimelineSet.addEventToTimeline(event, timeline, toStartOfTimeline, fromCache?, roomState?)` " +
681
- "is deprecated in favor of the overload with " +
682
- "`EventTimelineSet.addEventToTimeline(event, timeline, IAddEventToTimelineOptions)`",
683
- );
684
- }
685
-
686
657
  if (timeline.getTimelineSet() !== this) {
687
658
  throw new Error(`EventTimelineSet.addEventToTimeline: Timeline=${timeline.toString()} does not belong " +
688
659
  "in timelineSet(threadId=${this.thread?.id})`);
@@ -713,6 +684,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
713
684
  toStartOfTimeline,
714
685
  roomState,
715
686
  timelineWasEmpty,
687
+ addToState,
716
688
  });
717
689
  this._eventIdToTimeline.set(eventId, timeline);
718
690
 
@@ -741,7 +713,12 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
741
713
  * @remarks
742
714
  * Fires {@link RoomEvent.Timeline}
743
715
  */
744
- public insertEventIntoTimeline(event: MatrixEvent, timeline: EventTimeline, roomState: RoomState): void {
716
+ public insertEventIntoTimeline(
717
+ event: MatrixEvent,
718
+ timeline: EventTimeline,
719
+ roomState: RoomState,
720
+ addToState: boolean,
721
+ ): void {
745
722
  if (timeline.getTimelineSet() !== this) {
746
723
  throw new Error(`EventTimelineSet.insertEventIntoTimeline: Timeline=${timeline.toString()} does not belong " +
747
724
  "in timelineSet(threadId=${this.thread?.id})`);
@@ -777,6 +754,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
777
754
  fromCache: false,
778
755
  timelineWasEmpty: false,
779
756
  roomState,
757
+ addToState,
780
758
  });
781
759
  return;
782
760
  }
@@ -799,7 +777,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
799
777
  // If we got to the end of the loop, insertIndex points at the end of
800
778
  // the list.
801
779
 
802
- timeline.insertEvent(event, insertIndex, roomState);
780
+ timeline.insertEvent(event, insertIndex, roomState, addToState);
803
781
  this._eventIdToTimeline.set(eventId, timeline);
804
782
 
805
783
  const data: IRoomTimelineData = {
@@ -832,6 +810,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
832
810
  } else if (!this.filter || this.filter.filterRoomTimeline([localEvent]).length) {
833
811
  this.addEventToTimeline(localEvent, this.liveTimeline, {
834
812
  toStartOfTimeline: false,
813
+ addToState: false,
835
814
  });
836
815
  }
837
816
  }
@@ -35,6 +35,11 @@ export interface IAddEventOptions extends Pick<IMarkerFoundOptions, "timelineWas
35
35
  toStartOfTimeline: boolean;
36
36
  /** The state events to reconcile metadata from */
37
37
  roomState?: RoomState;
38
+ /** Whether to add timeline events to the state as was done in legacy sync v2.
39
+ * If true then timeline events will be added to the state.
40
+ * In sync v2 with org.matrix.msc4222.use_state_after and simplified sliding sync,
41
+ * all state arrives explicitly and timeline events should not be added. */
42
+ addToState: boolean;
38
43
  }
39
44
 
40
45
  export enum Direction {
@@ -127,7 +132,7 @@ export class EventTimeline {
127
132
  public constructor(private readonly eventTimelineSet: EventTimelineSet) {
128
133
  this.roomId = eventTimelineSet.room?.roomId ?? null;
129
134
  if (this.roomId) {
130
- this.startState = new RoomState(this.roomId, undefined, true);
135
+ this.startState = new RoomState(this.roomId);
131
136
  this.endState = new RoomState(this.roomId);
132
137
  }
133
138
 
@@ -362,7 +367,7 @@ export class EventTimeline {
362
367
  */
363
368
  public addEvent(
364
369
  event: MatrixEvent,
365
- { toStartOfTimeline, roomState, timelineWasEmpty }: IAddEventOptions = { toStartOfTimeline: false },
370
+ { toStartOfTimeline, roomState, timelineWasEmpty, addToState }: IAddEventOptions,
366
371
  ): void {
367
372
  if (!roomState) {
368
373
  roomState = toStartOfTimeline ? this.startState : this.endState;
@@ -374,7 +379,7 @@ export class EventTimeline {
374
379
  EventTimeline.setEventMetadata(event, roomState!, toStartOfTimeline);
375
380
 
376
381
  // modify state but only on unfiltered timelineSets
377
- if (event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
382
+ if (addToState && event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
378
383
  roomState?.setStateEvents([event], { timelineWasEmpty });
379
384
  // it is possible that the act of setting the state event means we
380
385
  // can set more metadata (specifically sender/target props), so try
@@ -417,14 +422,14 @@ export class EventTimeline {
417
422
  *
418
423
  * @internal
419
424
  */
420
- public insertEvent(event: MatrixEvent, insertIndex: number, roomState: RoomState): void {
425
+ public insertEvent(event: MatrixEvent, insertIndex: number, roomState: RoomState, addToState: boolean): void {
421
426
  const timelineSet = this.getTimelineSet();
422
427
 
423
428
  if (timelineSet.room) {
424
429
  EventTimeline.setEventMetadata(event, roomState, false);
425
430
 
426
431
  // modify state but only on unfiltered timelineSets
427
- if (event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
432
+ if (addToState && event.isState() && timelineSet.room.getUnfilteredTimelineSet() === timelineSet) {
428
433
  roomState.setStateEvents([event], {});
429
434
  // it is possible that the act of setting the state event means we
430
435
  // can set more metadata (specifically sender/target props), so try
@@ -965,7 +965,9 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
965
965
  const timeline = room.getLiveTimeline();
966
966
  // We use insertEventIntoTimeline to insert it in timestamp order,
967
967
  // because we don't know where it should go (until we have MSC4033).
968
- timeline.getTimelineSet().insertEventIntoTimeline(this, timeline, timeline.getState(EventTimeline.FORWARDS)!);
968
+ timeline
969
+ .getTimelineSet()
970
+ .insertEventIntoTimeline(this, timeline, timeline.getState(EventTimeline.FORWARDS)!, false);
969
971
  }
970
972
 
971
973
  /**
@@ -194,22 +194,11 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
194
194
  * As the timeline might get reset while they are loading, this state needs to be inherited
195
195
  * and shared when the room state is cloned for the new timeline.
196
196
  * This should only be passed from clone.
197
- * @param isStartTimelineState - Optional. This state is marked as a start state.
198
- * This is used to skip state insertions that are
199
- * in the wrong order. The order is determined by the `replaces_state` id.
200
- *
201
- * Example:
202
- * A current state events `replaces_state` value is `1`.
203
- * Trying to insert a state event with `event_id` `1` in its place would fail if isStartTimelineState = false.
204
- *
205
- * A current state events `event_id` is `2`.
206
- * Trying to insert a state event where its `replaces_state` value is `2` would fail if isStartTimelineState = true.
207
197
  */
208
198
 
209
199
  public constructor(
210
200
  public readonly roomId: string,
211
201
  private oobMemberFlags = { status: OobStatus.NotStarted },
212
- public readonly isStartTimelineState = false,
213
202
  ) {
214
203
  super();
215
204
  this.updateModifiedTime();
@@ -420,7 +409,7 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
420
409
  * Fires {@link RoomStateEvent.Events}
421
410
  * Fires {@link RoomStateEvent.Marker}
422
411
  */
423
- public setStateEvents(stateEvents: MatrixEvent[], options?: IMarkerFoundOptions): void {
412
+ public setStateEvents(stateEvents: MatrixEvent[], markerFoundOptions?: IMarkerFoundOptions): void {
424
413
  this.updateModifiedTime();
425
414
 
426
415
  // update the core event dict
@@ -432,22 +421,6 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
432
421
  }
433
422
 
434
423
  const lastStateEvent = this.getStateEventMatching(event);
435
-
436
- // Safety measure to not update the room (and emit the update) with older state.
437
- // The sync loop really should not send old events but it does very regularly.
438
- // Logging on return in those two conditions results in a large amount of logging. (on startup and when running element)
439
- const lastReplaceId = lastStateEvent?.event.unsigned?.replaces_state;
440
- const lastId = lastStateEvent?.event.event_id;
441
- const newReplaceId = event.event.unsigned?.replaces_state;
442
- const newId = event.event.event_id;
443
- if (this.isStartTimelineState) {
444
- // Add an event to the start of the timeline. Its replace id should not be the same as the one of the current/last start state event.
445
- if (newReplaceId && lastId && newReplaceId === lastId) return;
446
- } else {
447
- // Add an event to the end of the timeline. It should not be the same as the one replaced by the current/last end state event.
448
- if (lastReplaceId && newId && lastReplaceId === newId) return;
449
- }
450
-
451
424
  this.setStateEvent(event);
452
425
  if (event.getType() === EventType.RoomMember) {
453
426
  this.updateDisplayNameCache(event.getStateKey()!, event.getContent().displayname ?? "");
@@ -504,7 +477,7 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
504
477
  // assume all our sentinels are now out-of-date
505
478
  this.sentinels = {};
506
479
  } else if (UNSTABLE_MSC2716_MARKER.matches(event.getType())) {
507
- this.emit(RoomStateEvent.Marker, event, options);
480
+ this.emit(RoomStateEvent.Marker, event, markerFoundOptions);
508
481
  }
509
482
  });
510
483