Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 8e3fea9

Browse files
committed
Use an algorithmic comparator for room list ops
Not all algorithms are timestamp based.
1 parent 80b44f0 commit 8e3fea9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/stores/RoomListStore.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ class RoomListStore extends Store {
372372
_slotRoomIntoList(room, category, tag, existingEntries, newList, lastTimestampFn) {
373373
const targetCategoryIndex = CATEGORY_ORDER.indexOf(category);
374374

375+
let categoryComparator = (a, b) => lastTimestampFn(a.room) >= lastTimestampFn(b.room);
376+
const sortAlgorithm = getListAlgorithm(tag, this._state.algorithm);
377+
if (sortAlgorithm === ALGO_RECENT) {
378+
categoryComparator = (a, b) => this._recentsComparator(a, b, lastTimestampFn);
379+
} else if (sortAlgorithm === ALGO_ALPHABETIC) {
380+
categoryComparator = (a, b) => this._lexicographicalComparator(a, b);
381+
}
382+
375383
// The slotting algorithm works by trying to position the room in the most relevant
376384
// category of the list (red > grey > etc). To accomplish this, we need to consider
377385
// a couple cases: the category existing in the list but having other rooms in it and
@@ -449,7 +457,7 @@ class RoomListStore extends Store {
449457
// based on most recent timestamp.
450458
const changedBoundary = entryCategoryIndex > targetCategoryIndex;
451459
const currentCategory = entryCategoryIndex === targetCategoryIndex;
452-
if (changedBoundary || (currentCategory && lastTimestampFn(room) >= lastTimestampFn(entry.room))) {
460+
if (changedBoundary || (currentCategory && categoryComparator({room}, entry) <= 0)) {
453461
if (changedBoundary) {
454462
// If we changed a boundary, then we've gone too far - go to the top of the last
455463
// section instead.

0 commit comments

Comments
 (0)