From 45a415f8bf12c9d7806c190b8d07c478d14e16e0 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 13 Feb 2019 20:16:47 -0700 Subject: [PATCH] Protection around lack of room for tests --- src/stores/RoomListStore.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index e38a592f7a..9a764cd493 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -246,6 +246,8 @@ class RoomListStore extends Store { } _setRoomCategory(room, category) { + if (!room) return; // This should only happen in tests + const listsClone = {}; const targetCategoryIndex = CATEGORY_ORDER.indexOf(category); const targetTimestamp = this._tsOfNewestEvent(room); @@ -419,6 +421,8 @@ class RoomListStore extends Store { case "recent": comparator = (entryA, entryB) => { return this._recentsComparator(entryA, entryB, (room) => { + if (!room) return Number.MAX_SAFE_INTEGER; // Should only happen in tests + if (latestEventTsCache[room.roomId]) { return latestEventTsCache[room.roomId]; } @@ -452,7 +456,7 @@ class RoomListStore extends Store { _tsOfNewestEvent(room) { // Apparently we can have rooms without timelines, at least under testing // environments. Just return MAX_INT when this happens. - if (!room.timeline) return Number.MAX_SAFE_INTEGER; + if (!room || !room.timeline) return Number.MAX_SAFE_INTEGER; for (let i = room.timeline.length - 1; i >= 0; --i) { const ev = room.timeline[i];