Skip to content

Commit 9f6b42d

Browse files
authored
Merge pull request #2801 from matrix-org/kegan/ss-api-changes
Sliding sync: add include_old_rooms; remove is_tombstoned
2 parents 9f2f08d + 2e56c34 commit 9f6b42d

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

spec/integ/sliding-sync.spec.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,91 @@ describe("SlidingSync", () => {
806806
await listPromise;
807807
slidingSync.stop();
808808
});
809+
810+
// Regression test to make sure things like DELETE 0 INSERT 0 work correctly and we don't
811+
// end up losing room IDs.
812+
it("should handle insertions with a spurious DELETE correctly", async () => {
813+
slidingSync = new SlidingSync(proxyBaseUrl, [
814+
{
815+
ranges: [[0, 20]],
816+
},
817+
], {}, client!, 1);
818+
// initially start with nothing
819+
httpBackend!.when("POST", syncUrl).respond(200, {
820+
pos: "a",
821+
lists: [{
822+
count: 0,
823+
ops: [],
824+
}],
825+
});
826+
slidingSync.start();
827+
await httpBackend!.flushAllExpected();
828+
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({});
829+
830+
// insert a room
831+
httpBackend!.when("POST", syncUrl).respond(200, {
832+
pos: "b",
833+
lists: [{
834+
count: 1,
835+
ops: [
836+
{
837+
op: "DELETE", index: 0,
838+
},
839+
{
840+
op: "INSERT", index: 0, room_id: roomA,
841+
},
842+
],
843+
}],
844+
});
845+
await httpBackend!.flushAllExpected();
846+
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
847+
0: roomA,
848+
});
849+
850+
// insert another room
851+
httpBackend!.when("POST", syncUrl).respond(200, {
852+
pos: "c",
853+
lists: [{
854+
count: 1,
855+
ops: [
856+
{
857+
op: "DELETE", index: 1,
858+
},
859+
{
860+
op: "INSERT", index: 0, room_id: roomB,
861+
},
862+
],
863+
}],
864+
});
865+
await httpBackend!.flushAllExpected();
866+
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
867+
0: roomB,
868+
1: roomA,
869+
});
870+
871+
// insert a final room
872+
httpBackend!.when("POST", syncUrl).respond(200, {
873+
pos: "c",
874+
lists: [{
875+
count: 1,
876+
ops: [
877+
{
878+
op: "DELETE", index: 2,
879+
},
880+
{
881+
op: "INSERT", index: 0, room_id: roomC,
882+
},
883+
],
884+
}],
885+
});
886+
await httpBackend!.flushAllExpected();
887+
expect(slidingSync.getListData(0)!.roomIndexToRoomId).toEqual({
888+
0: roomC,
889+
1: roomB,
890+
2: roomA,
891+
});
892+
slidingSync.stop();
893+
});
809894
});
810895

811896
describe("transaction IDs", () => {

src/sliding-sync.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const BUFFER_PERIOD_MS = 10 * 1000;
3333
export interface MSC3575RoomSubscription {
3434
required_state?: string[][];
3535
timeline_limit?: number;
36+
include_old_rooms?: MSC3575RoomSubscription;
3637
}
3738

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

0 commit comments

Comments
 (0)