@@ -10,7 +10,7 @@ class UserList extends EventEmitter {
10
10
this . users = new Map ( ) ;
11
11
this . rooms = new Map ( ) ;
12
12
13
- this . _populateRooms ( ) ;
13
+ this . populateRooms ( ) ;
14
14
this . _listenEvents ( ) ;
15
15
}
16
16
@@ -27,20 +27,28 @@ class UserList extends EventEmitter {
27
27
if ( rooms ) {
28
28
let using = false ;
29
29
const result = { spaces : [ ] , rooms : [ ] } ;
30
+ const checked = [ ] ;
30
31
const { roomList } = initMatrix ;
31
32
32
- rooms . forEach ( ( roomId ) => {
33
- if ( roomList . isOrphan ( roomId ) ) {
34
- if ( roomList . spaces . has ( roomId ) ) {
35
- using = true ;
36
- result . spaces . push ( roomId ) ;
37
- } else if ( ! roomList . directs . has ( roomId ) ) {
38
- using = true ;
39
- result . rooms . push ( roomId ) ;
33
+ const insertRoom = ( roomId ) => {
34
+ if ( checked . indexOf ( roomId ) < 0 ) {
35
+ checked . push ( roomId ) ;
36
+ if ( roomList . isOrphan ( roomId ) ) {
37
+ if ( roomList . spaces . has ( roomId ) ) {
38
+ using = true ;
39
+ result . spaces . push ( roomId ) ;
40
+ } else if ( ! roomList . directs . has ( roomId ) ) {
41
+ using = true ;
42
+ result . rooms . push ( roomId ) ;
43
+ }
44
+ } else {
45
+ const moreRooms = roomList . roomIdToParents . get ( roomId ) ;
46
+ if ( moreRooms ) moreRooms . forEach ( ( roomId2 ) => insertRoom ( roomId2 ) ) ;
40
47
}
41
48
}
42
- } ) ;
49
+ } ;
43
50
51
+ rooms . forEach ( ( roomId ) => insertRoom ( roomId ) ) ;
44
52
if ( using ) return result ;
45
53
}
46
54
return null ;
@@ -118,7 +126,7 @@ class UserList extends EventEmitter {
118
126
} ) ;
119
127
}
120
128
121
- _populateRooms ( ) {
129
+ populateRooms ( ) {
122
130
const tinyThis = this ;
123
131
this . matrixClient . getRooms ( ) . forEach ( ( room ) => {
124
132
tinyThis . populateRoom ( room ) ;
0 commit comments