From a04800f030998c5f9eb953c39fd62ae6970f1285 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:49:31 +0100 Subject: [PATCH 1/3] Fix issue where no unsubs are sent when switching rooms --- src/sliding-sync.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sliding-sync.ts b/src/sliding-sync.ts index b219dad1159..7287489d30e 100644 --- a/src/sliding-sync.ts +++ b/src/sliding-sync.ts @@ -397,6 +397,10 @@ export class SlidingSync extends TypedEventEmitter Date: Fri, 16 Dec 2022 13:30:40 +0100 Subject: [PATCH 2/3] Add tests for custom subscriptions --- spec/integ/sliding-sync.spec.ts | 96 +++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/spec/integ/sliding-sync.spec.ts b/spec/integ/sliding-sync.spec.ts index 4655ca0efd0..368ace4e80e 100644 --- a/spec/integ/sliding-sync.spec.ts +++ b/spec/integ/sliding-sync.spec.ts @@ -1418,6 +1418,102 @@ describe("SlidingSync", () => { await httpBackend!.flushAllExpected(); slidingSync.stop(); }); + + it("should not be possible to add/modify an already added custom subscription", async () => { + const slidingSync = new SlidingSync(proxyBaseUrl, [], defaultSub, client!, 1); + slidingSync.addCustomSubscription(customSubName1, customSub1); + slidingSync.addCustomSubscription(customSubName1, customSub2); + slidingSync.useCustomSubscription(roomA, customSubName1); + slidingSync.modifyRoomSubscriptions(new Set([roomA])); + + httpBackend! + .when("POST", syncUrl) + .check(function (req) { + const body = req.data; + logger.log("custom subs", body); + expect(body.room_subscriptions).toBeTruthy(); + expect(body.room_subscriptions[roomA]).toEqual(customSub1); + }) + .respond(200, { + pos: "b", + lists: [], + extensions: {}, + rooms: {}, + }); + slidingSync.start(); + await httpBackend!.flushAllExpected(); + slidingSync.stop(); + }); + + it("should change the custom subscription if they are different", async () => { + const slidingSync = new SlidingSync(proxyBaseUrl, [], defaultSub, client!, 1); + slidingSync.addCustomSubscription(customSubName1, customSub1); + slidingSync.addCustomSubscription(customSubName2, customSub2); + slidingSync.useCustomSubscription(roomA, customSubName1); + slidingSync.modifyRoomSubscriptions(new Set([roomA])); + + httpBackend! + .when("POST", syncUrl) + .check(function (req) { + const body = req.data; + logger.log("custom subs", body); + expect(body.room_subscriptions).toBeTruthy(); + expect(body.room_subscriptions[roomA]).toEqual(customSub1); + expect(body.unsubscribe_rooms).toBeUndefined(); + }) + .respond(200, { + pos: "b", + lists: [], + extensions: {}, + rooms: {}, + }); + slidingSync.start(); + await httpBackend!.flushAllExpected(); + + // using the same subscription doesn't unsub nor changes subscriptions + slidingSync.useCustomSubscription(roomA, customSubName1); + slidingSync.modifyRoomSubscriptions(new Set([roomA])); + + httpBackend! + .when("POST", syncUrl) + .check(function (req) { + const body = req.data; + logger.log("custom subs", body); + expect(body.room_subscriptions).toBeUndefined(); + expect(body.unsubscribe_rooms).toBeUndefined(); + }) + .respond(200, { + pos: "b", + lists: [], + extensions: {}, + rooms: {}, + }); + slidingSync.start(); + await httpBackend!.flushAllExpected(); + + // Changing the subscription works + slidingSync.useCustomSubscription(roomA, customSubName2); + slidingSync.modifyRoomSubscriptions(new Set([roomA])); + + httpBackend! + .when("POST", syncUrl) + .check(function (req) { + const body = req.data; + logger.log("custom subs", body); + expect(body.room_subscriptions).toBeTruthy(); + expect(body.room_subscriptions[roomA]).toEqual(customSub2); + expect(body.unsubscribe_rooms).toBeUndefined(); + }) + .respond(200, { + pos: "b", + lists: [], + extensions: {}, + rooms: {}, + }); + slidingSync.start(); + await httpBackend!.flushAllExpected(); + slidingSync.stop(); + }); }); describe("extensions", () => { From 3872c5f0992cca6a1ff6e37dc86d6112b72ed0fb Mon Sep 17 00:00:00 2001 From: Till <2353100+S7evinK@users.noreply.github.com> Date: Mon, 19 Dec 2022 11:54:20 +0100 Subject: [PATCH 3/3] Update src/sliding-sync.ts Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/sliding-sync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sliding-sync.ts b/src/sliding-sync.ts index 7287489d30e..3a2f6739135 100644 --- a/src/sliding-sync.ts +++ b/src/sliding-sync.ts @@ -397,7 +397,7 @@ export class SlidingSync extends TypedEventEmitter