diff --git a/src/SlidingSyncManager.ts b/src/SlidingSyncManager.ts index 4f21a69260..4a6c113253 100644 --- a/src/SlidingSyncManager.ts +++ b/src/SlidingSyncManager.ts @@ -322,11 +322,7 @@ export class SlidingSyncManager { // gradually request more over time, even on errors. await sleep(gapBetweenRequestsMs); } - const listData = this.slidingSync.getListData(SlidingSyncManager.ListSearch); - if (!listData) { - // we failed to do the first request, keep trying - continue; - } + const listData = this.slidingSync.getListData(SlidingSyncManager.ListSearch)!; hasMore = endIndex + 1 < listData.joinedCount; startIndex += batchSize; firstTime = false; diff --git a/test/stores/room-list/SlidingRoomListStore-test.ts b/test/stores/room-list/SlidingRoomListStore-test.ts index 5d322daafb..868a54ba78 100644 --- a/test/stores/room-list/SlidingRoomListStore-test.ts +++ b/test/stores/room-list/SlidingRoomListStore-test.ts @@ -290,4 +290,43 @@ describe("SlidingRoomListStore", () => { await p; expect(store.orderedLists[tagId].map((r) => r.roomId)).toEqual([roomC, roomA, roomB].map((r) => r.roomId)); }); + + it("gracefully handles unknown room IDs", async () => { + await store.start(); + const roomIdA = "!a:localhost"; + const roomIdB = "!b:localhost"; // does not exist + const roomIdC = "!c:localhost"; + const roomIndexToRoomId = { + 0: roomIdA, + 1: roomIdB, // does not exist + 2: roomIdC, + }; + const tagId = DefaultTagID.Favourite; + const joinCount = 10; + // seed the store with 2 rooms + const roomA = new Room(roomIdA, context.client!, context.client!.getUserId()); + const roomC = new Room(roomIdC, context.client!, context.client!.getUserId()); + mocked(context.client!.getRoom).mockImplementation((roomId: string) => { + switch (roomId) { + case roomIdA: + return roomA; + case roomIdC: + return roomC; + } + return null; + }); + mocked(context._SlidingSyncManager!.slidingSync.getListData).mockImplementation((key: string) => { + if (key !== tagId) { + return null; + } + return { + roomIndexToRoomId: roomIndexToRoomId, + joinedCount: joinCount, + }; + }); + let p = untilEmission(store, LISTS_UPDATE_EVENT); + context.slidingSyncManager.slidingSync.emit(SlidingSyncEvent.List, tagId, joinCount, roomIndexToRoomId); + await p; + expect(store.orderedLists[tagId]).toEqual([roomA, roomC]); + }); });