@@ -31,28 +31,23 @@ import {RoomNotificationStateStore} from "./notifications/RoomNotificationStateS
3131import { DefaultTagID } from "./room-list/models" ;
3232import { EnhancedMap , mapDiff } from "../utils/maps" ;
3333import { setHasDiff } from "../utils/sets" ;
34- import { objectDiff } from "../utils/objects" ;
35- import { arrayHasDiff } from "../utils/arrays" ;
3634import { ISpaceSummaryEvent , ISpaceSummaryRoom } from "../components/structures/SpaceRoomDirectory" ;
3735import RoomViewStore from "./RoomViewStore" ;
3836
39- type SpaceKey = string | symbol ;
40-
4137interface IState { }
4238
4339const ACTIVE_SPACE_LS_KEY = "mx_active_space" ;
4440
45- export const HOME_SPACE = Symbol ( "home-space" ) ;
4641export const SUGGESTED_ROOMS = Symbol ( "suggested-rooms" ) ;
4742
4843export const UPDATE_TOP_LEVEL_SPACES = Symbol ( "top-level-spaces" ) ;
4944export const UPDATE_INVITED_SPACES = Symbol ( "invited-spaces" ) ;
5045export 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
5247
5348const MAX_SUGGESTED_ROOMS = 20 ;
5449
55- const getSpaceContextKey = ( space ?: Room ) => `mx_space_context_${ space ?. roomId || "home_space " } ` ;
50+ const getSpaceContextKey = ( space ?: Room ) => `mx_space_context_${ space ?. roomId || "ALL_ROOMS " } ` ;
5651
5752const partitionSpacesAndRooms = ( arr : Room [ ] ) : [ Room [ ] , Room [ ] ] => { // [spaces, rooms]
5853 return arr . reduce ( ( result , room : Room ) => {
@@ -83,15 +78,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
8378
8479 // The spaces representing the roots of the various tree-like hierarchies
8580 private rootSpaces : Room [ ] = [ ] ;
86- // The list of rooms not present in any currently joined spaces
87- private orphanedRooms = new Set < string > ( ) ;
8881 // Map from room ID to set of spaces which list it as a child
8982 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 > ( ) ;
9285 // 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
9588 private _activeSpace ?: Room = null ;
9689 private _suggestedRooms : ISpaceSummaryRoom [ ] = [ ] ;
9790 private _invitedSpaces = new Set < Room > ( ) ;
@@ -227,7 +220,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
227220 }
228221
229222 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 ( ) ;
231227 } ;
232228
233229 private rebuild = throttle ( ( ) => {
@@ -258,7 +254,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
258254 } ) ;
259255 } ) ;
260256
261- const [ rootSpaces , orphanedRooms ] = partitionSpacesAndRooms ( Array . from ( unseenChildren ) ) ;
257+ const [ rootSpaces ] = partitionSpacesAndRooms ( Array . from ( unseenChildren ) ) ;
262258
263259 // somewhat algorithm to handle full-cycles
264260 const detachedNodes = new Set < Room > ( spaces ) ;
@@ -299,7 +295,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
299295 // rootSpaces.push(space);
300296 // });
301297
302- this . orphanedRooms = new Set ( orphanedRooms ) ;
303298 this . rootSpaces = rootSpaces ;
304299 this . parentMap = backrefs ;
305300
@@ -320,25 +315,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
320315 this . rebuild ( ) ;
321316 }
322317
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-
342318 private onSpaceMembersChange = ( ev : MatrixEvent ) => {
343319 // skip this update if we do not have a DM with this user
344320 if ( DMRoomMap . shared ( ) . getDMRoomsForUserId ( ev . getStateKey ( ) ) . length < 1 ) return ;
@@ -352,16 +328,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
352328 const oldFilteredRooms = this . spaceFilteredRooms ;
353329 this . spaceFilteredRooms = new Map ( ) ;
354330
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-
365331 this . rootSpaces . forEach ( s => {
366332 // traverse each space tree in DFS to build up the supersets as you go up,
367333 // reusing results from like subtrees.
@@ -408,13 +374,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
408374 // Update NotificationStates
409375 this . getNotificationState ( s ) ?. setRooms ( visibleRooms . filter ( room => {
410376 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 ) ;
418379 }
419380
420381 return false ;
@@ -475,8 +436,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
475436 // TODO confirm this after implementing parenting behaviour
476437 if ( room . isSpaceRoom ( ) ) {
477438 this . onSpaceUpdate ( ) ;
478- } else {
479- this . onRoomUpdate ( room ) ;
480439 }
481440 this . emit ( room . roomId ) ;
482441 break ;
@@ -489,38 +448,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
489448 }
490449 } ;
491450
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-
521451 protected async reset ( ) {
522452 this . rootSpaces = [ ] ;
523- this . orphanedRooms = new Set ( ) ;
524453 this . parentMap = new EnhancedMap ( ) ;
525454 this . notificationStateMap = new Map ( ) ;
526455 this . spaceFilteredRooms = new Map ( ) ;
@@ -535,8 +464,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
535464 this . matrixClient . removeListener ( "Room" , this . onRoom ) ;
536465 this . matrixClient . removeListener ( "Room.myMembership" , this . onRoom ) ;
537466 this . matrixClient . removeListener ( "RoomState.events" , this . onRoomState ) ;
538- this . matrixClient . removeListener ( "Room.accountData" , this . onRoomAccountData ) ;
539- this . matrixClient . removeListener ( "accountData" , this . onAccountData ) ;
540467 }
541468 await this . reset ( ) ;
542469 }
@@ -546,8 +473,6 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
546473 this . matrixClient . on ( "Room" , this . onRoom ) ;
547474 this . matrixClient . on ( "Room.myMembership" , this . onRoom ) ;
548475 this . matrixClient . on ( "RoomState.events" , this . onRoomState ) ;
549- this . matrixClient . on ( "Room.accountData" , this . onRoomAccountData ) ;
550- this . matrixClient . on ( "accountData" , this . onAccountData ) ;
551476
552477 await this . onSpaceUpdate ( ) ; // trigger an initial update
553478
@@ -602,7 +527,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
602527 }
603528 }
604529
605- public getNotificationState ( key : SpaceKey ) : SpaceNotificationState {
530+ public getNotificationState ( key : string ) : SpaceNotificationState {
606531 if ( this . notificationStateMap . has ( key ) ) {
607532 return this . notificationStateMap . get ( key ) ;
608533 }
0 commit comments