@@ -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 { UnreadSorter } from "./skip-list/sorters/UnreadSorter" ;
3839
3940/**
4041 * These are the filters passed to the room skip list.
@@ -136,10 +137,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
136137 if ( ! this . roomSkipList ) throw new Error ( "Cannot resort room list before skip list is created." ) ;
137138 if ( ! this . matrixClient ) throw new Error ( "Cannot resort room list without matrix client." ) ;
138139 if ( this . roomSkipList . activeSortAlgorithm === algorithm ) return ;
139- const sorter =
140- algorithm === SortingAlgorithm . Alphabetic
141- ? new AlphabeticSorter ( )
142- : new RecencySorter ( this . matrixClient . getSafeUserId ( ) ) ;
140+ const sorter = this . getSorterFromSortingAlgorithm ( algorithm , this . matrixClient . getSafeUserId ( ) ) ;
143141 this . roomSkipList . useNewSorter ( sorter , this . getRooms ( ) ) ;
144142 this . emit ( LISTS_UPDATE_EVENT ) ;
145143 SettingsStore . setValue ( "RoomList.preferredSorting" , null , SettingLevel . DEVICE , algorithm ) ;
@@ -321,13 +319,25 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
321319 */
322320 private getPreferredSorter ( myUserId : string ) : Sorter {
323321 const preferred = SettingsStore . getValue ( "RoomList.preferredSorting" ) ;
324- switch ( preferred ) {
322+ return this . getSorterFromSortingAlgorithm ( preferred , myUserId ) ;
323+ }
324+
325+ /**
326+ * Get a sorter instance from the sorting algorithm enum value.
327+ * @param algorithm The sorting algorithm
328+ * @param myUserId The user-id of the current user
329+ * @returns the sorter instance
330+ */
331+ private getSorterFromSortingAlgorithm ( algorithm : SortingAlgorithm , myUserId : string ) : Sorter {
332+ switch ( algorithm ) {
325333 case SortingAlgorithm . Alphabetic :
326334 return new AlphabeticSorter ( ) ;
327335 case SortingAlgorithm . Recency :
328336 return new RecencySorter ( myUserId ) ;
337+ case SortingAlgorithm . Unread :
338+ return new UnreadSorter ( myUserId ) ;
329339 default :
330- throw new Error ( `Got unknown sort preference from RoomList.preferredSorting setting ` ) ;
340+ throw new Error ( `Unknown sorting algorithm: ${ algorithm } ` ) ;
331341 }
332342 }
333343
0 commit comments