Skip to content

Commit

Permalink
Remove event remitters
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Apr 19, 2022
1 parent 1ab5460 commit 52ce184
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
23 changes: 16 additions & 7 deletions spec/integ/matrix-client-syncing.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MatrixEvent } from "../../src/models/event";
import { RoomEvent } from "../../src/models/room";
import { EventTimeline } from "../../src/models/event-timeline";
import { EventType } from "../../src/@types/event";
import * as utils from "../test-utils/test-utils";
Expand Down Expand Up @@ -696,25 +697,33 @@ describe("MatrixClient syncing", function() {

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

// Only do the first sync
httpBackend.when("GET", "/sync").respond(200, normalFirstSync);
client.startClient();
await Promise.all([
httpBackend.flushAllExpected(),
awaitSyncEvent(),
]);

// Get the room after the first sync so the room is created
const room = client.getRoom(roomOne);

let emitCount = 0;
client.on("Room.historyImportedWithinTimeline", function(markerEvent, room) {
room.on(RoomEvent.historyImportedWithinTimeline, function(markerEvent, room) {
expect(markerEvent.getId()).toEqual(markerEventId);
expect(room.roomId).toEqual(roomOne);
emitCount += 1;
});

httpBackend.when("GET", "/sync").respond(200, normalFirstSync);
// Now do a subsequent sync with the marker event
httpBackend.when("GET", "/sync").respond(200, nextSyncData);

client.startClient();
await Promise.all([
httpBackend.flushAllExpected(),
awaitSyncEvent(2),
awaitSyncEvent(),
]);

const room = client.getRoom(roomOne);
expect(room.getTimelineNeedsRefresh()).toEqual(true);
// Make sure "Room.historyImportedWithinTimeline" was emitted
// Make sure `RoomEvent.historyImportedWithinTimeline` was emitted
expect(emitCount).toEqual(1);
expect(room.getLastMarkerEventIdProcessed()).toEqual(markerEventId);
});
Expand Down
2 changes: 1 addition & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export enum RoomEvent {
LocalEchoUpdated = "Room.localEchoUpdated",
Timeline = "Room.timeline",
TimelineReset = "Room.timelineReset",
TimelineRefresh = "RoomEvent.TimelineRefresh",
TimelineRefresh = "Room.TimelineRefresh",
historyImportedWithinTimeline = "Room.historyImportedWithinTimeline",
}

Expand Down
12 changes: 11 additions & 1 deletion src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,22 @@ const BUFFER_PERIOD_MS = 80 * 1000;
const FAILED_SYNC_ERROR_THRESHOLD = 3;

export enum SyncState {
/** Emitted after we try to sync more than `FAILED_SYNC_ERROR_THRESHOLD`
* times and are still failing. Or when we enounter a hard error like the
* token being invalid. */
Error = "ERROR",
/** Emitted after the first sync events are ready (this could even be sync
* events from the cache) */
Prepared = "PREPARED",
/** Emitted when the sync loop is no longer running */
Stopped = "STOPPED",
/** Emitted after each sync request happens */
Syncing = "SYNCING",
/** Emitted after a connectivity error and we're ready to start syncing again */
Catchup = "CATCHUP",
/** Emitted for each time we try reconnecting. Will switch to `Error` after
* we reach the `FAILED_SYNC_ERROR_THRESHOLD`
*/
Reconnecting = "RECONNECTING",
}

Expand Down Expand Up @@ -210,7 +221,6 @@ export class SyncApi {
RoomEvent.Receipt,
RoomEvent.Tags,
RoomEvent.LocalEchoUpdated,
RoomEvent.historyImportedWithinTimeline,
RoomEvent.AccountData,
RoomEvent.MyMembership,
RoomEvent.Timeline,
Expand Down

0 comments on commit 52ce184

Please sign in to comment.