@@ -372,6 +372,14 @@ class RoomListStore extends Store {
372
372
_slotRoomIntoList ( room , category , tag , existingEntries , newList , lastTimestampFn ) {
373
373
const targetCategoryIndex = CATEGORY_ORDER . indexOf ( category ) ;
374
374
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
+
375
383
// The slotting algorithm works by trying to position the room in the most relevant
376
384
// category of the list (red > grey > etc). To accomplish this, we need to consider
377
385
// a couple cases: the category existing in the list but having other rooms in it and
@@ -449,7 +457,7 @@ class RoomListStore extends Store {
449
457
// based on most recent timestamp.
450
458
const changedBoundary = entryCategoryIndex > targetCategoryIndex ;
451
459
const currentCategory = entryCategoryIndex === targetCategoryIndex ;
452
- if ( changedBoundary || ( currentCategory && lastTimestampFn ( room ) >= lastTimestampFn ( entry . room ) ) ) {
460
+ if ( changedBoundary || ( currentCategory && categoryComparator ( { room} , entry ) <= 0 ) ) {
453
461
if ( changedBoundary ) {
454
462
// If we changed a boundary, then we've gone too far - go to the top of the last
455
463
// section instead.
0 commit comments