Skip to content

Commit 52ce184

Browse files
committed
1 parent 1ab5460 commit 52ce184

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Diff for: spec/integ/matrix-client-syncing.spec.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MatrixEvent } from "../../src/models/event";
2+
import { RoomEvent } from "../../src/models/room";
23
import { EventTimeline } from "../../src/models/event-timeline";
34
import { EventType } from "../../src/@types/event";
45
import * as utils from "../test-utils/test-utils";
@@ -696,25 +697,33 @@ describe("MatrixClient syncing", function() {
696697

697698
const markerEventId = nextSyncData.rooms.join[roomOne].timeline.events[0].event_id;
698699

700+
// Only do the first sync
701+
httpBackend.when("GET", "/sync").respond(200, normalFirstSync);
702+
client.startClient();
703+
await Promise.all([
704+
httpBackend.flushAllExpected(),
705+
awaitSyncEvent(),
706+
]);
707+
708+
// Get the room after the first sync so the room is created
709+
const room = client.getRoom(roomOne);
710+
699711
let emitCount = 0;
700-
client.on("Room.historyImportedWithinTimeline", function(markerEvent, room) {
712+
room.on(RoomEvent.historyImportedWithinTimeline, function(markerEvent, room) {
701713
expect(markerEvent.getId()).toEqual(markerEventId);
702714
expect(room.roomId).toEqual(roomOne);
703715
emitCount += 1;
704716
});
705717

706-
httpBackend.when("GET", "/sync").respond(200, normalFirstSync);
718+
// Now do a subsequent sync with the marker event
707719
httpBackend.when("GET", "/sync").respond(200, nextSyncData);
708-
709-
client.startClient();
710720
await Promise.all([
711721
httpBackend.flushAllExpected(),
712-
awaitSyncEvent(2),
722+
awaitSyncEvent(),
713723
]);
714724

715-
const room = client.getRoom(roomOne);
716725
expect(room.getTimelineNeedsRefresh()).toEqual(true);
717-
// Make sure "Room.historyImportedWithinTimeline" was emitted
726+
// Make sure `RoomEvent.historyImportedWithinTimeline` was emitted
718727
expect(emitCount).toEqual(1);
719728
expect(room.getLastMarkerEventIdProcessed()).toEqual(markerEventId);
720729
});

Diff for: src/models/room.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export enum RoomEvent {
165165
LocalEchoUpdated = "Room.localEchoUpdated",
166166
Timeline = "Room.timeline",
167167
TimelineReset = "Room.timelineReset",
168-
TimelineRefresh = "RoomEvent.TimelineRefresh",
168+
TimelineRefresh = "Room.TimelineRefresh",
169169
historyImportedWithinTimeline = "Room.historyImportedWithinTimeline",
170170
}
171171

Diff for: src/sync.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,22 @@ const BUFFER_PERIOD_MS = 80 * 1000;
7070
const FAILED_SYNC_ERROR_THRESHOLD = 3;
7171

7272
export enum SyncState {
73+
/** Emitted after we try to sync more than `FAILED_SYNC_ERROR_THRESHOLD`
74+
* times and are still failing. Or when we enounter a hard error like the
75+
* token being invalid. */
7376
Error = "ERROR",
77+
/** Emitted after the first sync events are ready (this could even be sync
78+
* events from the cache) */
7479
Prepared = "PREPARED",
80+
/** Emitted when the sync loop is no longer running */
7581
Stopped = "STOPPED",
82+
/** Emitted after each sync request happens */
7683
Syncing = "SYNCING",
84+
/** Emitted after a connectivity error and we're ready to start syncing again */
7785
Catchup = "CATCHUP",
86+
/** Emitted for each time we try reconnecting. Will switch to `Error` after
87+
* we reach the `FAILED_SYNC_ERROR_THRESHOLD`
88+
*/
7889
Reconnecting = "RECONNECTING",
7990
}
8091

@@ -210,7 +221,6 @@ export class SyncApi {
210221
RoomEvent.Receipt,
211222
RoomEvent.Tags,
212223
RoomEvent.LocalEchoUpdated,
213-
RoomEvent.historyImportedWithinTimeline,
214224
RoomEvent.AccountData,
215225
RoomEvent.MyMembership,
216226
RoomEvent.Timeline,

0 commit comments

Comments
 (0)