@@ -21,12 +21,10 @@ import { MSC3575Filter, SlidingSyncEvent } from "matrix-js-sdk/src/sliding-sync"
21
21
import { RoomUpdateCause , TagID , OrderedDefaultTagIDs , DefaultTagID } from "./models" ;
22
22
import { ITagMap , ListAlgorithm , SortAlgorithm } from "./algorithms/models" ;
23
23
import { ActionPayload } from "../../dispatcher/payloads" ;
24
- import defaultDispatcher from "../../dispatcher/dispatcher" ;
24
+ import { MatrixDispatcher } from "../../dispatcher/dispatcher" ;
25
25
import { IFilterCondition } from "./filters/IFilterCondition" ;
26
26
import { AsyncStoreWithClient } from "../AsyncStoreWithClient" ;
27
27
import { RoomListStore as Interface , RoomListStoreEvent } from "./Interface" ;
28
- import { SlidingSyncManager } from "../../SlidingSyncManager" ;
29
- import SpaceStore from "../spaces/SpaceStore" ;
30
28
import { MetaSpace , SpaceKey , UPDATE_SELECTED_SPACE } from "../spaces" ;
31
29
import { LISTS_LOADING_EVENT } from "./RoomListStore" ;
32
30
import { UPDATE_EVENT } from "../AsyncStore" ;
@@ -38,7 +36,7 @@ interface IState {
38
36
39
37
export const SlidingSyncSortToFilter : Record < SortAlgorithm , string [ ] > = {
40
38
[ SortAlgorithm . Alphabetic ] : [ "by_name" , "by_recency" ] ,
41
- [ SortAlgorithm . Recent ] : [ "by_highlight_count" , "by_notification_count ", "by_recency" ] ,
39
+ [ SortAlgorithm . Recent ] : [ "by_notification_level " , "by_recency" ] ,
42
40
[ SortAlgorithm . Manual ] : [ "by_recency" ] ,
43
41
} ;
44
42
@@ -48,21 +46,18 @@ const filterConditions: Record<TagID, MSC3575Filter> = {
48
46
} ,
49
47
[ DefaultTagID . Favourite ] : {
50
48
tags : [ "m.favourite" ] ,
51
- is_tombstoned : false ,
52
49
} ,
53
50
// TODO https://github.com/vector-im/element-web/issues/23207
54
51
// DefaultTagID.SavedItems,
55
52
[ DefaultTagID . DM ] : {
56
53
is_dm : true ,
57
54
is_invite : false ,
58
- is_tombstoned : false ,
59
55
// If a DM has a Favourite & Low Prio tag then it'll be shown in those lists instead
60
56
not_tags : [ "m.favourite" , "m.lowpriority" ] ,
61
57
} ,
62
58
[ DefaultTagID . Untagged ] : {
63
59
is_dm : false ,
64
60
is_invite : false ,
65
- is_tombstoned : false ,
66
61
not_room_types : [ "m.space" ] ,
67
62
not_tags : [ "m.favourite" , "m.lowpriority" ] ,
68
63
// spaces filter added dynamically
@@ -71,7 +66,6 @@ const filterConditions: Record<TagID, MSC3575Filter> = {
71
66
tags : [ "m.lowpriority" ] ,
72
67
// If a room has both Favourite & Low Prio tags then it'll be shown under Favourites
73
68
not_tags : [ "m.favourite" ] ,
74
- is_tombstoned : false ,
75
69
} ,
76
70
// TODO https://github.com/vector-im/element-web/issues/23207
77
71
// DefaultTagID.ServerNotice,
@@ -87,25 +81,25 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
87
81
private counts : Record < TagID , number > = { } ;
88
82
private stickyRoomId : string | null ;
89
83
90
- public constructor ( ) {
91
- super ( defaultDispatcher ) ;
84
+ public constructor ( dis : MatrixDispatcher , private readonly context : SdkContextClass ) {
85
+ super ( dis ) ;
92
86
this . setMaxListeners ( 20 ) ; // RoomList + LeftPanel + 8xRoomSubList + spares
93
87
}
94
88
95
89
public async setTagSorting ( tagId : TagID , sort : SortAlgorithm ) {
96
90
logger . info ( "SlidingRoomListStore.setTagSorting " , tagId , sort ) ;
97
91
this . tagIdToSortAlgo [ tagId ] = sort ;
98
- const slidingSyncIndex = SlidingSyncManager . instance . getOrAllocateListIndex ( tagId ) ;
92
+ const slidingSyncIndex = this . context . slidingSyncManager . getOrAllocateListIndex ( tagId ) ;
99
93
switch ( sort ) {
100
94
case SortAlgorithm . Alphabetic :
101
- await SlidingSyncManager . instance . ensureListRegistered (
95
+ await this . context . slidingSyncManager . ensureListRegistered (
102
96
slidingSyncIndex , {
103
97
sort : SlidingSyncSortToFilter [ SortAlgorithm . Alphabetic ] ,
104
98
} ,
105
99
) ;
106
100
break ;
107
101
case SortAlgorithm . Recent :
108
- await SlidingSyncManager . instance . ensureListRegistered (
102
+ await this . context . slidingSyncManager . ensureListRegistered (
109
103
slidingSyncIndex , {
110
104
sort : SlidingSyncSortToFilter [ SortAlgorithm . Recent ] ,
111
105
} ,
@@ -174,10 +168,13 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
174
168
// check all lists for each tag we know about and see if the room is there
175
169
const tags : TagID [ ] = [ ] ;
176
170
for ( const tagId in this . tagIdToSortAlgo ) {
177
- const index = SlidingSyncManager . instance . getOrAllocateListIndex ( tagId ) ;
178
- const { roomIndexToRoomId } = SlidingSyncManager . instance . slidingSync . getListData ( index ) ;
179
- for ( const roomIndex in roomIndexToRoomId ) {
180
- const roomId = roomIndexToRoomId [ roomIndex ] ;
171
+ const index = this . context . slidingSyncManager . getOrAllocateListIndex ( tagId ) ;
172
+ const listData = this . context . slidingSyncManager . slidingSync . getListData ( index ) ;
173
+ if ( ! listData ) {
174
+ continue ;
175
+ }
176
+ for ( const roomIndex in listData . roomIndexToRoomId ) {
177
+ const roomId = listData . roomIndexToRoomId [ roomIndex ] ;
181
178
if ( roomId === room . roomId ) {
182
179
tags . push ( tagId ) ;
183
180
break ;
@@ -207,7 +204,7 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
207
204
208
205
// this room will not move due to it being viewed: it is sticky. This can be null to indicate
209
206
// no sticky room if you aren't viewing a room.
210
- this . stickyRoomId = SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
207
+ this . stickyRoomId = this . context . roomViewStore . getRoomId ( ) ;
211
208
let stickyRoomNewIndex = - 1 ;
212
209
const stickyRoomOldIndex = ( tagMap [ tagId ] || [ ] ) . findIndex ( ( room ) => {
213
210
return room . roomId === this . stickyRoomId ;
@@ -264,7 +261,7 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
264
261
}
265
262
266
263
private onSlidingSyncListUpdate ( listIndex : number , joinCount : number , roomIndexToRoomId : Record < number , string > ) {
267
- const tagId = SlidingSyncManager . instance . listIdForIndex ( listIndex ) ;
264
+ const tagId = this . context . slidingSyncManager . listIdForIndex ( listIndex ) ;
268
265
this . counts [ tagId ] = joinCount ;
269
266
this . refreshOrderedLists ( tagId , roomIndexToRoomId ) ;
270
267
// let the UI update
@@ -273,7 +270,7 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
273
270
274
271
private onRoomViewStoreUpdated ( ) {
275
272
// we only care about this to know when the user has clicked on a room to set the stickiness value
276
- if ( SdkContextClass . instance . roomViewStore . getRoomId ( ) === this . stickyRoomId ) {
273
+ if ( this . context . roomViewStore . getRoomId ( ) === this . stickyRoomId ) {
277
274
return ;
278
275
}
279
276
@@ -296,14 +293,17 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
296
293
if ( room ) {
297
294
// resort it based on the slidingSync view of the list. This may cause this old sticky
298
295
// room to cease to exist.
299
- const index = SlidingSyncManager . instance . getOrAllocateListIndex ( tagId ) ;
300
- const { roomIndexToRoomId } = SlidingSyncManager . instance . slidingSync . getListData ( index ) ;
301
- this . refreshOrderedLists ( tagId , roomIndexToRoomId ) ;
296
+ const index = this . context . slidingSyncManager . getOrAllocateListIndex ( tagId ) ;
297
+ const listData = this . context . slidingSyncManager . slidingSync . getListData ( index ) ;
298
+ if ( ! listData ) {
299
+ continue ;
300
+ }
301
+ this . refreshOrderedLists ( tagId , listData . roomIndexToRoomId ) ;
302
302
hasUpdatedAnyList = true ;
303
303
}
304
304
}
305
305
// in the event we didn't call refreshOrderedLists, it helps to still remember the sticky room ID.
306
- this . stickyRoomId = SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
306
+ this . stickyRoomId = this . context . roomViewStore . getRoomId ( ) ;
307
307
308
308
if ( hasUpdatedAnyList ) {
309
309
this . emit ( LISTS_UPDATE_EVENT ) ;
@@ -313,11 +313,11 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
313
313
protected async onReady ( ) : Promise < any > {
314
314
logger . info ( "SlidingRoomListStore.onReady" ) ;
315
315
// permanent listeners: never get destroyed. Could be an issue if we want to test this in isolation.
316
- SlidingSyncManager . instance . slidingSync . on ( SlidingSyncEvent . List , this . onSlidingSyncListUpdate . bind ( this ) ) ;
317
- SdkContextClass . instance . roomViewStore . addListener ( UPDATE_EVENT , this . onRoomViewStoreUpdated . bind ( this ) ) ;
318
- SpaceStore . instance . on ( UPDATE_SELECTED_SPACE , this . onSelectedSpaceUpdated . bind ( this ) ) ;
319
- if ( SpaceStore . instance . activeSpace ) {
320
- this . onSelectedSpaceUpdated ( SpaceStore . instance . activeSpace , false ) ;
316
+ this . context . slidingSyncManager . slidingSync . on ( SlidingSyncEvent . List , this . onSlidingSyncListUpdate . bind ( this ) ) ;
317
+ this . context . roomViewStore . addListener ( UPDATE_EVENT , this . onRoomViewStoreUpdated . bind ( this ) ) ;
318
+ this . context . spaceStore . on ( UPDATE_SELECTED_SPACE , this . onSelectedSpaceUpdated . bind ( this ) ) ;
319
+ if ( this . context . spaceStore . activeSpace ) {
320
+ this . onSelectedSpaceUpdated ( this . context . spaceStore . activeSpace , false ) ;
321
321
}
322
322
323
323
// sliding sync has an initial response for spaces. Now request all the lists.
@@ -332,8 +332,8 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
332
332
const sort = SortAlgorithm . Recent ; // default to recency sort, TODO: read from config
333
333
this . tagIdToSortAlgo [ tagId ] = sort ;
334
334
this . emit ( LISTS_LOADING_EVENT , tagId , true ) ;
335
- const index = SlidingSyncManager . instance . getOrAllocateListIndex ( tagId ) ;
336
- SlidingSyncManager . instance . ensureListRegistered ( index , {
335
+ const index = this . context . slidingSyncManager . getOrAllocateListIndex ( tagId ) ;
336
+ this . context . slidingSyncManager . ensureListRegistered ( index , {
337
337
filters : filter ,
338
338
sort : SlidingSyncSortToFilter [ sort ] ,
339
339
} ) . then ( ( ) => {
@@ -350,9 +350,18 @@ export class SlidingRoomListStoreClass extends AsyncStoreWithClient<IState> impl
350
350
const oldSpace = filters . spaces ?. [ 0 ] ;
351
351
filters . spaces = ( activeSpace && activeSpace != MetaSpace . Home ) ? [ activeSpace ] : undefined ;
352
352
if ( oldSpace !== activeSpace ) {
353
+ // include subspaces in this list
354
+ this . context . spaceStore . traverseSpace ( activeSpace , ( roomId : string ) => {
355
+ if ( roomId === activeSpace ) {
356
+ return ;
357
+ }
358
+ filters . spaces . push ( roomId ) ; // add subspace
359
+ } , false ) ;
360
+
353
361
this . emit ( LISTS_LOADING_EVENT , tagId , true ) ;
354
- SlidingSyncManager . instance . ensureListRegistered (
355
- SlidingSyncManager . instance . getOrAllocateListIndex ( tagId ) ,
362
+ const index = this . context . slidingSyncManager . getOrAllocateListIndex ( tagId ) ;
363
+ this . context . slidingSyncManager . ensureListRegistered (
364
+ index ,
356
365
{
357
366
filters : filters ,
358
367
} ,
0 commit comments