@@ -35,6 +35,7 @@ import { SettingLevel } from "../../settings/SettingLevel";
3535import { MARKED_UNREAD_TYPE_STABLE , MARKED_UNREAD_TYPE_UNSTABLE } from "../../utils/notifications" ;
3636import { getChangedOverrideRoomMutePushRules } from "../room-list/utils/roomMute" ;
3737import { Action } from "../../dispatcher/actions" ;
38+ import { SectionSorter } from "./skip-list/sorters/SectionSorter.ts" ;
3839
3940/**
4041 * These are the filters passed to the room skip list.
@@ -131,24 +132,27 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
131132 /**
132133 * Resort the list of rooms using a different algorithm.
133134 * @param algorithm The sorting algorithm to use.
135+ * @param sections Which sections to group rooms into
134136 */
135- public resort ( algorithm : SortingAlgorithm ) : void {
137+ public resort ( algorithm : SortingAlgorithm , sections : ( FilterKey | null ) [ ] ) : void {
136138 if ( ! this . roomSkipList ) throw new Error ( "Cannot resort room list before skip list is created." ) ;
137139 if ( ! this . matrixClient ) throw new Error ( "Cannot resort room list without matrix client." ) ;
138- if ( this . roomSkipList . activeSortAlgorithm === algorithm ) return ;
139140 const sorter =
140141 algorithm === SortingAlgorithm . Alphabetic
141142 ? new AlphabeticSorter ( )
142143 : new RecencySorter ( this . matrixClient . getSafeUserId ( ) ) ;
143- this . roomSkipList . useNewSorter ( sorter , this . getRooms ( ) ) ;
144+ const sectionSorter = new SectionSorter ( sorter , sections ) ;
145+ if ( this . roomSkipList . activeSortAlgorithm === sectionSorter . type ) return ;
146+ this . roomSkipList . useNewSorter ( sectionSorter , this . getRooms ( ) ) ;
144147 this . emit ( LISTS_UPDATE_EVENT ) ;
145148 SettingsStore . setValue ( "RoomList.preferredSorting" , null , SettingLevel . DEVICE , algorithm ) ;
149+ SettingsStore . setValue ( "RoomList.sections" , null , SettingLevel . DEVICE , sections ) ;
146150 }
147151
148152 /**
149153 * Currently active sorting algorithm if the store is ready or undefined otherwise.
150154 */
151- public get activeSortAlgorithm ( ) : SortingAlgorithm | undefined {
155+ public get activeSortAlgorithm ( ) : string | undefined {
152156 return this . roomSkipList ?. activeSortAlgorithm ;
153157 }
154158
@@ -321,11 +325,12 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
321325 */
322326 private getPreferredSorter ( myUserId : string ) : Sorter {
323327 const preferred = SettingsStore . getValue ( "RoomList.preferredSorting" ) ;
328+ const sections = SettingsStore . getValue ( "RoomList.sections" ) ;
324329 switch ( preferred ) {
325330 case SortingAlgorithm . Alphabetic :
326- return new AlphabeticSorter ( ) ;
331+ return new SectionSorter ( new AlphabeticSorter ( ) , sections ) ;
327332 case SortingAlgorithm . Recency :
328- return new RecencySorter ( myUserId ) ;
333+ return new SectionSorter ( new RecencySorter ( myUserId ) , sections ) ;
329334 default :
330335 throw new Error ( `Got unknown sort preference from RoomList.preferredSorting setting` ) ;
331336 }
0 commit comments