From 80b44f0292ff36b87389c7b72a6b498de8c9b5bc Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 4 Mar 2020 12:05:47 -0700 Subject: [PATCH 1/2] Always calculate the category of a room All the update triggers for the RoomListStore go through the `setRoomCategory` function, so by returning early we're not actually calculating where a room should be in the list. --- src/stores/RoomListStore.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 561d865b66..aec307d28e 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -479,12 +479,6 @@ class RoomListStore extends Store { _setRoomCategory(room, category) { if (!room) return; // This should only happen in tests - if (!this._state.orderImportantFirst) { - // XXX bail here early to avoid https://github.com/vector-im/riot-web/issues/9216 - // this may mean that category updates are missed whilst not ordering by importance first - return; - } - const listsClone = {}; // Micro optimization: Support lazily loading the last timestamp in a room From 8e3fea9d0fb1a6b097754b656c2c5e8d1dcdb7ae Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 4 Mar 2020 12:09:05 -0700 Subject: [PATCH 2/2] Use an algorithmic comparator for room list ops Not all algorithms are timestamp based. --- src/stores/RoomListStore.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index aec307d28e..89edc9a8ef 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -372,6 +372,14 @@ class RoomListStore extends Store { _slotRoomIntoList(room, category, tag, existingEntries, newList, lastTimestampFn) { const targetCategoryIndex = CATEGORY_ORDER.indexOf(category); + let categoryComparator = (a, b) => lastTimestampFn(a.room) >= lastTimestampFn(b.room); + const sortAlgorithm = getListAlgorithm(tag, this._state.algorithm); + if (sortAlgorithm === ALGO_RECENT) { + categoryComparator = (a, b) => this._recentsComparator(a, b, lastTimestampFn); + } else if (sortAlgorithm === ALGO_ALPHABETIC) { + categoryComparator = (a, b) => this._lexicographicalComparator(a, b); + } + // The slotting algorithm works by trying to position the room in the most relevant // category of the list (red > grey > etc). To accomplish this, we need to consider // a couple cases: the category existing in the list but having other rooms in it and @@ -449,7 +457,7 @@ class RoomListStore extends Store { // based on most recent timestamp. const changedBoundary = entryCategoryIndex > targetCategoryIndex; const currentCategory = entryCategoryIndex === targetCategoryIndex; - if (changedBoundary || (currentCategory && lastTimestampFn(room) >= lastTimestampFn(entry.room))) { + if (changedBoundary || (currentCategory && categoryComparator({room}, entry) <= 0)) { if (changedBoundary) { // If we changed a boundary, then we've gone too far - go to the top of the last // section instead.