@@ -15,7 +15,6 @@ import type { FilterKey } from "./skip-list/filters";
1515import { AsyncStoreWithClient } from "../AsyncStoreWithClient" ;
1616import SettingsStore from "../../settings/SettingsStore" ;
1717import defaultDispatcher from "../../dispatcher/dispatcher" ;
18- import { RoomSkipList } from "./skip-list/RoomSkipList" ;
1918import { RecencySorter } from "./skip-list/sorters/RecencySorter" ;
2019import { AlphabeticSorter } from "./skip-list/sorters/AlphabeticSorter" ;
2120import { readReceiptChangeIsFor } from "../../utils/read-receipts" ;
@@ -36,6 +35,7 @@ import { Action } from "../../dispatcher/actions";
3635import { UnreadSorter } from "./skip-list/sorters/UnreadSorter" ;
3736import { getChangedOverrideRoomMutePushRules } from "./utils" ;
3837import { isRoomVisible } from "./isRoomVisible" ;
38+ import { type Section , SectionStore } from "./SectionStore" ;
3939
4040/**
4141 * These are the filters passed to the room skip list.
@@ -64,7 +64,7 @@ export type RoomsResult = {
6464 // The filter queried
6565 filterKeys ?: FilterKey [ ] ;
6666 // The resulting list of rooms
67- rooms : Room [ ] ;
67+ sections : Section [ ] ;
6868} ;
6969
7070export const LISTS_UPDATE_EVENT = RoomListStoreV3Event . ListsUpdate ;
@@ -75,7 +75,11 @@ export const LISTS_LOADED_EVENT = RoomListStoreV3Event.ListsLoaded;
7575 * This store is being actively developed so expect the methods to change in future.
7676 */
7777export class RoomListStoreV3Class extends AsyncStoreWithClient < EmptyObject > {
78- private roomSkipList ?: RoomSkipList ;
78+ /**
79+ * The section store holds the actual skip lists that are used to store rooms.
80+ */
81+ private sectionStore ?: SectionStore ;
82+
7983 private readonly msc3946ProcessDynamicPredecessor : boolean ;
8084
8185 public constructor ( dispatcher : MatrixDispatcher ) {
@@ -100,14 +104,14 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
100104 * Check whether the initial list of rooms has loaded.
101105 */
102106 public get isLoadingRooms ( ) : boolean {
103- return ! this . roomSkipList ?. initialized ;
107+ return ! this . sectionStore ?. initialized ;
104108 }
105109
106110 /**
107111 * Get a list of sorted rooms.
108112 */
109113 public getSortedRooms ( ) : Room [ ] {
110- if ( this . roomSkipList ?. initialized ) return Array . from ( this . roomSkipList ) ;
114+ if ( this . sectionStore ?. initialized ) return this . sectionStore . getSortedRooms ( ) ;
111115 else return [ ] ;
112116 }
113117
@@ -120,25 +124,32 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
120124 */
121125 public getSortedRoomsInActiveSpace ( filterKeys ?: FilterKey [ ] ) : RoomsResult {
122126 const spaceId = SpaceStore . instance . activeSpace ;
123- if ( this . roomSkipList ?. initialized )
127+ console . log (
128+ "Getting sorted rooms in active space with filters" ,
129+ filterKeys ,
130+ "and spaceId" ,
131+ spaceId ,
132+ this . sectionStore ?. getSections ( filterKeys ) ,
133+ ) ;
134+ if ( this . sectionStore ?. initialized )
124135 return {
125136 spaceId : spaceId ,
126137 filterKeys,
127- rooms : Array . from ( this . roomSkipList . getRoomsInActiveSpace ( filterKeys ) ) ,
138+ sections : this . sectionStore . getSections ( filterKeys ) ,
128139 } ;
129- else return { spaceId : spaceId , filterKeys, rooms : [ ] } ;
140+ else return { spaceId : spaceId , filterKeys, sections : [ ] } ;
130141 }
131142
132143 /**
133144 * Resort the list of rooms using a different algorithm.
134145 * @param algorithm The sorting algorithm to use.
135146 */
136147 public resort ( algorithm : SortingAlgorithm ) : void {
137- if ( ! this . roomSkipList ) throw new Error ( "Cannot resort room list before skip list is created." ) ;
148+ if ( ! this . sectionStore ) throw new Error ( "Cannot resort room list before skip list is created." ) ;
138149 if ( ! this . matrixClient ) throw new Error ( "Cannot resort room list without matrix client." ) ;
139- if ( this . roomSkipList . activeSortAlgorithm === algorithm ) return ;
150+ if ( this . sectionStore . activeSortAlgorithm === algorithm ) return ;
140151 const sorter = this . getSorterFromSortingAlgorithm ( algorithm , this . matrixClient . getSafeUserId ( ) ) ;
141- this . roomSkipList . useNewSorter ( sorter , this . getRooms ( ) ) ;
152+ this . sectionStore . useNewSorter ( sorter , this . getRooms ( ) ) ;
142153 this . emit ( LISTS_UPDATE_EVENT ) ;
143154 SettingsStore . setValue ( "RoomList.preferredSorting" , null , SettingLevel . DEVICE , algorithm ) ;
144155 }
@@ -147,26 +158,26 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
147158 * Currently active sorting algorithm if the store is ready or undefined otherwise.
148159 */
149160 public get activeSortAlgorithm ( ) : SortingAlgorithm | undefined {
150- return this . roomSkipList ?. activeSortAlgorithm ;
161+ return this . sectionStore ?. activeSortAlgorithm ;
151162 }
152163
153164 protected async onReady ( ) : Promise < any > {
154- if ( this . roomSkipList ?. initialized || ! this . matrixClient ) return ;
165+ if ( this . sectionStore ?. initialized || ! this . matrixClient ) return ;
155166 const sorter = this . getPreferredSorter ( this . matrixClient . getSafeUserId ( ) ) ;
156- this . roomSkipList = new RoomSkipList ( sorter , FILTERS ) ;
167+ this . sectionStore = new SectionStore ( sorter , FILTERS ) ;
157168 await SpaceStore . instance . storeReadyPromise ;
158169 const rooms = this . getRooms ( ) ;
159- this . roomSkipList . seed ( rooms ) ;
170+ this . sectionStore . seed ( rooms ) ;
160171 this . emit ( LISTS_LOADED_EVENT ) ;
161172 this . emit ( LISTS_UPDATE_EVENT ) ;
162173 }
163174
164175 protected async onNotReady ( ) : Promise < void > {
165- this . roomSkipList = undefined ;
176+ this . sectionStore = undefined ;
166177 }
167178
168179 protected async onAction ( payload : ActionPayload ) : Promise < void > {
169- if ( ! this . matrixClient || ! this . roomSkipList ?. initialized ) return ;
180+ if ( ! this . matrixClient || ! this . sectionStore ?. initialized ) return ;
170181
171182 /**
172183 * For the kind of updates that we care about (represented by the cases below),
@@ -242,7 +253,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
242253 ( oldMembership === EffectiveMembership . Invite || oldMembership === EffectiveMembership . Join ) &&
243254 newMembership === EffectiveMembership . Leave
244255 ) {
245- this . roomSkipList . removeRoom ( payload . room ) ;
256+ this . sectionStore . removeRoom ( payload . room ) ;
246257 this . emit ( LISTS_UPDATE_EVENT ) ;
247258 return ;
248259 }
@@ -258,7 +269,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
258269 ) ;
259270 const predecessors = roomUpgradeHistory . slice ( 0 , roomUpgradeHistory . indexOf ( room ) ) ;
260271 for ( const predecessor of predecessors ) {
261- this . roomSkipList . removeRoom ( predecessor ) ;
272+ this . sectionStore . removeRoom ( predecessor ) ;
262273 }
263274 }
264275
@@ -268,7 +279,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
268279
269280 case Action . AfterForgetRoom : {
270281 const room = payload . room ;
271- this . roomSkipList . removeRoom ( room ) ;
282+ this . sectionStore . removeRoom ( room ) ;
272283 this . emit ( LISTS_UPDATE_EVENT ) ;
273284 break ;
274285 }
@@ -279,6 +290,8 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
279290 * This method deals with the two types of account data payloads that we care about.
280291 */
281292 private handleAccountDataPayload ( payload : ActionPayload ) : void {
293+ if ( ! this . sectionStore ) throw new Error ( "sectionStore hasn't been created yet!" ) ;
294+
282295 const eventType = payload . event_type ;
283296 let needsEmit = false ;
284297 switch ( eventType ) {
@@ -293,7 +306,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
293306 logger . warn ( `${ roomId } was found in DMs but the room is not in the store` ) ;
294307 continue ;
295308 }
296- this . roomSkipList ! . reInsertRoom ( room ) ;
309+ this . sectionStore . reInsertRoom ( room ) ;
297310 needsEmit = true ;
298311 }
299312 }
@@ -307,7 +320,7 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
307320 . map ( ( id ) => this . matrixClient ?. getRoom ( id ) )
308321 . filter ( ( room ) => ! ! room ) ;
309322 for ( const room of rooms ) {
310- this . roomSkipList ! . reInsertRoom ( room ) ;
323+ this . sectionStore . reInsertRoom ( room ) ;
311324 needsEmit = true ;
312325 }
313326 break ;
@@ -354,24 +367,24 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
354367 * @param isNewRoom Set this to true if this a new room that the isn't already in the skiplist
355368 */
356369 private addRoomAndEmit ( room : Room , isNewRoom = false ) : void {
357- if ( ! this . roomSkipList ) throw new Error ( "roomSkipList hasn't been created yet!" ) ;
370+ if ( ! this . sectionStore ) throw new Error ( "roomSkipList hasn't been created yet!" ) ;
358371 if ( isNewRoom ) {
359372 if ( ! isRoomVisible ( room ) ) {
360373 logger . info (
361374 `RoomListStoreV3: Refusing to add new room ${ room . roomId } because isRoomVisible returned false.` ,
362375 ) ;
363376 return ;
364377 }
365- this . roomSkipList . addNewRoom ( room ) ;
378+ this . sectionStore . addNewRoom ( room ) ;
366379 } else {
367- this . roomSkipList . reInsertRoom ( room ) ;
380+ this . sectionStore . reInsertRoom ( room ) ;
368381 }
369382 this . emit ( LISTS_UPDATE_EVENT ) ;
370383 }
371384
372385 private onActiveSpaceChanged ( ) : void {
373- if ( ! this . roomSkipList ) return ;
374- this . roomSkipList . calculateActiveSpaceForNodes ( ) ;
386+ if ( ! this . sectionStore ) return ;
387+ this . sectionStore . calculateActiveSpaceForNodes ( ) ;
375388 this . emit ( LISTS_UPDATE_EVENT ) ;
376389 }
377390}
0 commit comments