Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding sync: add include_old_rooms; remove is_tombstoned #2801

Merged
merged 4 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions spec/integ/sliding-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,91 @@ describe("SlidingSync", () => {
await listPromise;
slidingSync.stop();
});

// Regression test to make sure things like DELETE 0 INSERT 0 work correctly and we don't
// end up losing room IDs.
it("should handle insertions with a spurious DELETE correctly", async () => {
slidingSync = new SlidingSync(proxyBaseUrl, [
{
ranges: [[0, 20]],
},
], {}, client!, 1);
// initially start with nothing
httpBackend!.when("POST", syncUrl).respond(200, {
pos: "a",
lists: [{
count: 0,
ops: [],
}],
});
slidingSync.start();
await httpBackend!.flushAllExpected();
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({});

// insert a room
httpBackend!.when("POST", syncUrl).respond(200, {
pos: "b",
lists: [{
count: 1,
ops: [
{
op: "DELETE", index: 0,
},
{
op: "INSERT", index: 0, room_id: roomA,
},
],
}],
});
await httpBackend!.flushAllExpected();
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
0: roomA,
});

// insert another room
httpBackend!.when("POST", syncUrl).respond(200, {
pos: "c",
lists: [{
count: 1,
ops: [
{
op: "DELETE", index: 1,
},
{
op: "INSERT", index: 0, room_id: roomB,
},
],
}],
});
await httpBackend!.flushAllExpected();
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
0: roomB,
1: roomA,
});

// insert a final room
httpBackend!.when("POST", syncUrl).respond(200, {
pos: "c",
lists: [{
count: 1,
ops: [
{
op: "DELETE", index: 2,
},
{
op: "INSERT", index: 0, room_id: roomC,
},
],
}],
});
await httpBackend!.flushAllExpected();
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
0: roomC,
1: roomB,
2: roomA,
});
slidingSync.stop();
});
});

describe("transaction IDs", () => {
Expand Down
8 changes: 6 additions & 2 deletions src/sliding-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const BUFFER_PERIOD_MS = 10 * 1000;
export interface MSC3575RoomSubscription {
required_state?: string[][];
timeline_limit?: number;
include_old_rooms?: MSC3575RoomSubscription;
}

/**
Expand All @@ -42,7 +43,6 @@ export interface MSC3575Filter {
is_dm?: boolean;
is_encrypted?: boolean;
is_invite?: boolean;
is_tombstoned?: boolean;
room_name_like?: string;
room_types?: string[];
not_room_types?: string[];
Expand Down Expand Up @@ -641,8 +641,12 @@ export class SlidingSync extends TypedEventEmitter<SlidingSyncEvent, SlidingSync
// starting at the gap so we can just shift each element in turn
this.shiftLeft(listIndex, op.index, gapIndex);
}
gapIndex = -1; // forget the gap, we don't need it anymore.
}
// forget the gap, we don't need it anymore. This is outside the check for
// a room being present in this index position because INSERTs always universally
// forget the gap, not conditionally based on the presence of a room in the INSERT
// position. Without this, DELETE 0; INSERT 0; would do the wrong thing.
gapIndex = -1;
this.lists[listIndex].roomIndexToRoomId[op.index] = op.room_id;
break;
}
Expand Down