@@ -31,28 +31,23 @@ import {RoomNotificationStateStore} from "./notifications/RoomNotificationStateS
31
31
import { DefaultTagID } from "./room-list/models" ;
32
32
import { EnhancedMap , mapDiff } from "../utils/maps" ;
33
33
import { setHasDiff } from "../utils/sets" ;
34
- import { objectDiff } from "../utils/objects" ;
35
- import { arrayHasDiff } from "../utils/arrays" ;
36
34
import { ISpaceSummaryEvent , ISpaceSummaryRoom } from "../components/structures/SpaceRoomDirectory" ;
37
35
import RoomViewStore from "./RoomViewStore" ;
38
36
39
- type SpaceKey = string | symbol ;
40
-
41
37
interface IState { }
42
38
43
39
const ACTIVE_SPACE_LS_KEY = "mx_active_space" ;
44
40
45
- export const HOME_SPACE = Symbol ( "home-space" ) ;
46
41
export const SUGGESTED_ROOMS = Symbol ( "suggested-rooms" ) ;
47
42
48
43
export const UPDATE_TOP_LEVEL_SPACES = Symbol ( "top-level-spaces" ) ;
49
44
export const UPDATE_INVITED_SPACES = Symbol ( "invited-spaces" ) ;
50
45
export const UPDATE_SELECTED_SPACE = Symbol ( "selected-space" ) ;
51
- // Space Room ID/HOME_SPACE will be emitted when a Space's children change
46
+ // Space Room ID will be emitted when a Space's children change
52
47
53
48
const MAX_SUGGESTED_ROOMS = 20 ;
54
49
55
- const getSpaceContextKey = ( space ?: Room ) => `mx_space_context_${ space ?. roomId || "home_space " } ` ;
50
+ const getSpaceContextKey = ( space ?: Room ) => `mx_space_context_${ space ?. roomId || "ALL_ROOMS " } ` ;
56
51
57
52
const partitionSpacesAndRooms = ( arr : Room [ ] ) : [ Room [ ] , Room [ ] ] => { // [spaces, rooms]
58
53
return arr . reduce ( ( result , room : Room ) => {
@@ -83,15 +78,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
83
78
84
79
// The spaces representing the roots of the various tree-like hierarchies
85
80
private rootSpaces : Room [ ] = [ ] ;
86
- // The list of rooms not present in any currently joined spaces
87
- private orphanedRooms = new Set < string > ( ) ;
88
81
// Map from room ID to set of spaces which list it as a child
89
82
private parentMap = new EnhancedMap < string , Set < string > > ( ) ;
90
- // Map from space key to SpaceNotificationState instance representing that space
91
- private notificationStateMap = new Map < SpaceKey , SpaceNotificationState > ( ) ;
83
+ // Map from spaceId to SpaceNotificationState instance representing that space
84
+ private notificationStateMap = new Map < string , SpaceNotificationState > ( ) ;
92
85
// Map from space key to Set of room IDs that should be shown as part of that space's filter
93
- private spaceFilteredRooms = new Map < string | symbol , Set < string > > ( ) ;
94
- // The space currently selected in the Space Panel - if null then `Home` is selected
86
+ private spaceFilteredRooms = new Map < string , Set < string > > ( ) ;
87
+ // The space currently selected in the Space Panel - if null then All Rooms is selected
95
88
private _activeSpace ?: Room = null ;
96
89
private _suggestedRooms : ISpaceSummaryRoom [ ] = [ ] ;
97
90
private _invitedSpaces = new Set < Room > ( ) ;
@@ -227,7 +220,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
227
220
}
228
221
229
222
public getSpaceFilteredRoomIds = ( space : Room | null ) : Set < string > => {
230
- return this . spaceFilteredRooms . get ( space ?. roomId || HOME_SPACE ) || new Set ( ) ;
223
+ if ( ! space ) {
224
+ return new Set ( this . matrixClient . getVisibleRooms ( ) . map ( r => r . roomId ) ) ;
225
+ }
226
+ return this . spaceFilteredRooms . get ( space . roomId ) || new Set ( ) ;
231
227
} ;
232
228
233
229
private rebuild = throttle ( ( ) => {
@@ -258,7 +254,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
258
254
} ) ;
259
255
} ) ;
260
256
261
- const [ rootSpaces , orphanedRooms ] = partitionSpacesAndRooms ( Array . from ( unseenChildren ) ) ;
257
+ const [ rootSpaces ] = partitionSpacesAndRooms ( Array . from ( unseenChildren ) ) ;
262
258
263
259
// somewhat algorithm to handle full-cycles
264
260
const detachedNodes = new Set < Room > ( spaces ) ;
@@ -299,7 +295,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
299
295
// rootSpaces.push(space);
300
296
// });
301
297
302
- this . orphanedRooms = new Set ( orphanedRooms ) ;
303
298
this . rootSpaces = rootSpaces ;
304
299
this . parentMap = backrefs ;
305
300
@@ -320,25 +315,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
320
315
this . rebuild ( ) ;
321
316
}
322
317
323
- private showInHomeSpace = ( room : Room ) => {
324
- if ( room . isSpaceRoom ( ) ) return false ;
325
- return ! this . parentMap . get ( room . roomId ) ?. size // put all orphaned rooms in the Home Space
326
- || DMRoomMap . shared ( ) . getUserIdForRoomId ( room . roomId ) // put all DMs in the Home Space
327
- || RoomListStore . instance . getTagsForRoom ( room ) . includes ( DefaultTagID . Favourite ) // show all favourites
328
- } ;
329
-
330
- // Update a given room due to its tag changing (e.g DM-ness or Fav-ness)
331
- // This can only change whether it shows up in the HOME_SPACE or not
332
- private onRoomUpdate = ( room : Room ) => {
333
- if ( this . showInHomeSpace ( room ) ) {
334
- this . spaceFilteredRooms . get ( HOME_SPACE ) ?. add ( room . roomId ) ;
335
- this . emit ( HOME_SPACE ) ;
336
- } else if ( ! this . orphanedRooms . has ( room . roomId ) ) {
337
- this . spaceFilteredRooms . get ( HOME_SPACE ) ?. delete ( room . roomId ) ;
338
- this . emit ( HOME_SPACE ) ;
339
- }
340
- } ;
341
-
342
318
private onSpaceMembersChange = ( ev : MatrixEvent ) => {
343
319
// skip this update if we do not have a DM with this user
344
320
if ( DMRoomMap . shared ( ) . getDMRoomsForUserId ( ev . getStateKey ( ) ) . length < 1 ) return ;
@@ -352,16 +328,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
352
328
const oldFilteredRooms = this . spaceFilteredRooms ;
353
329
this . spaceFilteredRooms = new Map ( ) ;
354
330
355
- // put all room invites in the Home Space
356
- const invites = visibleRooms . filter ( r => ! r . isSpaceRoom ( ) && r . getMyMembership ( ) === "invite" ) ;
357
- this . spaceFilteredRooms . set ( HOME_SPACE , new Set < string > ( invites . map ( room => room . roomId ) ) ) ;
358
-
359
- visibleRooms . forEach ( room => {
360
- if ( this . showInHomeSpace ( room ) ) {
361
- this . spaceFilteredRooms . get ( HOME_SPACE ) . add ( room . roomId ) ;
362
- }
363
- } ) ;
364
-
365
331
this . rootSpaces . forEach ( s => {
366
332
// traverse each space tree in DFS to build up the supersets as you go up,
367
333
// reusing results from like subtrees.
@@ -408,13 +374,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
408
374
// Update NotificationStates
409
375
this . getNotificationState ( s ) ?. setRooms ( visibleRooms . filter ( room => {
410
376
if ( roomIds . has ( room . roomId ) ) {
411
- // Don't aggregate notifications for DMs except in the Home Space
412
- if ( s !== HOME_SPACE ) {
413
- return ! DMRoomMap . shared ( ) . getUserIdForRoomId ( room . roomId )
414
- || RoomListStore . instance . getTagsForRoom ( room ) . includes ( DefaultTagID . Favourite ) ;
415
- }
416
-
417
- return true ;
377
+ return ! DMRoomMap . shared ( ) . getUserIdForRoomId ( room . roomId )
378
+ || RoomListStore . instance . getTagsForRoom ( room ) . includes ( DefaultTagID . Favourite ) ;
418
379
}
419
380
420
381
return false ;
@@ -475,8 +436,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
475
436
// TODO confirm this after implementing parenting behaviour
476
437
if ( room . isSpaceRoom ( ) ) {
477
438
this . onSpaceUpdate ( ) ;
478
- } else {
479
- this . onRoomUpdate ( room ) ;
480
439
}
481
440
this . emit ( room . roomId ) ;
482
441
break ;
@@ -489,38 +448,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
489
448
}
490
449
} ;
491
450
492
- private onRoomAccountData = ( ev : MatrixEvent , room : Room , lastEvent ?: MatrixEvent ) => {
493
- if ( ev . getType ( ) === EventType . Tag && ! room . isSpaceRoom ( ) ) {
494
- // If the room was in favourites and now isn't or the opposite then update its position in the trees
495
- const oldTags = lastEvent ?. getContent ( ) ?. tags || { } ;
496
- const newTags = ev . getContent ( ) ?. tags || { } ;
497
- if ( ! ! oldTags [ DefaultTagID . Favourite ] !== ! ! newTags [ DefaultTagID . Favourite ] ) {
498
- this . onRoomUpdate ( room ) ;
499
- }
500
- }
501
- }
502
-
503
- private onAccountData = ( ev : MatrixEvent , lastEvent : MatrixEvent ) => {
504
- if ( ev . getType ( ) === EventType . Direct ) {
505
- const lastContent = lastEvent . getContent ( ) ;
506
- const content = ev . getContent ( ) ;
507
-
508
- const diff = objectDiff < Record < string , string [ ] > > ( lastContent , content ) ;
509
- // filter out keys which changed by reference only by checking whether the sets differ
510
- const changed = diff . changed . filter ( k => arrayHasDiff ( lastContent [ k ] , content [ k ] ) ) ;
511
- // DM tag changes, refresh relevant rooms
512
- new Set ( [ ...diff . added , ...diff . removed , ...changed ] ) . forEach ( roomId => {
513
- const room = this . matrixClient ?. getRoom ( roomId ) ;
514
- if ( room ) {
515
- this . onRoomUpdate ( room ) ;
516
- }
517
- } ) ;
518
- }
519
- } ;
520
-
521
451
protected async reset ( ) {
522
452
this . rootSpaces = [ ] ;
523
- this . orphanedRooms = new Set ( ) ;
524
453
this . parentMap = new EnhancedMap ( ) ;
525
454
this . notificationStateMap = new Map ( ) ;
526
455
this . spaceFilteredRooms = new Map ( ) ;
@@ -535,8 +464,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
535
464
this . matrixClient . removeListener ( "Room" , this . onRoom ) ;
536
465
this . matrixClient . removeListener ( "Room.myMembership" , this . onRoom ) ;
537
466
this . matrixClient . removeListener ( "RoomState.events" , this . onRoomState ) ;
538
- this . matrixClient . removeListener ( "Room.accountData" , this . onRoomAccountData ) ;
539
- this . matrixClient . removeListener ( "accountData" , this . onAccountData ) ;
540
467
}
541
468
await this . reset ( ) ;
542
469
}
@@ -546,8 +473,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
546
473
this . matrixClient . on ( "Room" , this . onRoom ) ;
547
474
this . matrixClient . on ( "Room.myMembership" , this . onRoom ) ;
548
475
this . matrixClient . on ( "RoomState.events" , this . onRoomState ) ;
549
- this . matrixClient . on ( "Room.accountData" , this . onRoomAccountData ) ;
550
- this . matrixClient . on ( "accountData" , this . onAccountData ) ;
551
476
552
477
await this . onSpaceUpdate ( ) ; // trigger an initial update
553
478
@@ -602,7 +527,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
602
527
}
603
528
}
604
529
605
- public getNotificationState ( key : SpaceKey ) : SpaceNotificationState {
530
+ public getNotificationState ( key : string ) : SpaceNotificationState {
606
531
if ( this . notificationStateMap . has ( key ) ) {
607
532
return this . notificationStateMap . get ( key ) ;
608
533
}
0 commit comments