mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 04:21:57 +03:00
Use an algorithmic comparator for room list ops
Not all algorithms are timestamp based.
This commit is contained in:
parent
80b44f0292
commit
8e3fea9d0f
1 changed files with 9 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue