@@ -29,15 +29,14 @@ func eventKey(srcRoomID, dstRoomID, evType string) string {
2929// _____|________
3030// | | |
3131// R1 SS1 R2
32- // |________
33- // | |
34- // SS2 R3
3532// |
36- // R4
33+ // SS2
34+ // |________
35+ // | |
36+ // R3 R4
3737//
3838// Where:
3939// - the user is joined to all rooms except R4.
40- // - R3 -> SS1 is a parent link without a child.
4140// - R2 <---> Root is a two-way link.
4241// - The remaining links are just children links.
4342// - SS1 is marked as a "space", but SS2 is not.
@@ -78,17 +77,24 @@ func TestClientSpacesSummary(t *testing.T) {
7877 roomNames [ss1 ] = "Sub-Space 1"
7978 r2 := alice .CreateRoom (t , map [string ]interface {}{
8079 "preset" : "public_chat" ,
80+ "name" : "R2" ,
8181 })
82+ roomNames [r2 ] = "R2"
8283 ss2 := alice .CreateRoom (t , map [string ]interface {}{
8384 "preset" : "public_chat" ,
85+ "name" : "SS2" ,
8486 })
87+ roomNames [ss2 ] = "SS2"
8588 r3 := alice .CreateRoom (t , map [string ]interface {}{
8689 "preset" : "public_chat" ,
90+ "name" : "R3" ,
8791 })
92+ roomNames [r3 ] = "R3"
8893 // alice is not joined to R4
8994 bob := deployment .Client (t , "hs1" , "@bob:hs1" )
9095 r4 := bob .CreateRoom (t , map [string ]interface {}{
9196 "preset" : "public_chat" ,
97+ "name" : "R4" ,
9298 "initial_state" : []map [string ]interface {}{
9399 {
94100 "type" : "m.room.history_visibility" ,
@@ -99,6 +105,7 @@ func TestClientSpacesSummary(t *testing.T) {
99105 },
100106 },
101107 })
108+ roomNames [r4 ] = "R4"
102109
103110 // create the links
104111 rootToR1 := eventKey (root , r1 , spaceChildEventType )
@@ -125,7 +132,6 @@ func TestClientSpacesSummary(t *testing.T) {
125132 "via" : []string {"hs1" },
126133 },
127134 })
128- r2ToRoot := eventKey (r2 , root , spaceParentEventType )
129135 alice .SendEventSynced (t , r2 , b.Event { // parent link
130136 Type : spaceParentEventType ,
131137 StateKey : & root ,
@@ -141,10 +147,10 @@ func TestClientSpacesSummary(t *testing.T) {
141147 "via" : []string {"hs1" },
142148 },
143149 })
144- r3ToSS1 := eventKey (r3 , ss1 , spaceParentEventType )
145- alice .SendEventSynced (t , r3 , b.Event { // parent link only
146- Type : spaceParentEventType ,
147- StateKey : & ss1 ,
150+ ss2ToR3 := eventKey (ss2 , r3 , spaceChildEventType )
151+ alice .SendEventSynced (t , ss2 , b.Event {
152+ Type : spaceChildEventType ,
153+ StateKey : & r3 ,
148154 Content : map [string ]interface {}{
149155 "via" : []string {"hs1" },
150156 },
@@ -159,19 +165,10 @@ func TestClientSpacesSummary(t *testing.T) {
159165 })
160166
161167 // - Querying the root returns the entire graph
162- // - Rooms are returned correctly along with the custom fields `num_refs` and ` room_type`.
168+ // - Rooms are returned correctly along with the custom fields `room_type`.
163169 // - Events are returned correctly.
164170 t .Run ("query whole graph" , func (t * testing.T ) {
165- roomRefs := map [string ]int {
166- root : 4 , // r1,r2,ss1,parent r2
167- r1 : 1 , // root
168- r2 : 2 , // root,parent
169- ss1 : 3 , // root,ss2,r3
170- r3 : 1 , // ss1
171- ss2 : 2 , // ss1,r4
172- r4 : 1 , // ss2
173- }
174- res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , root , "spaces" }, map [string ]interface {}{})
171+ res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "org.matrix.msc2946" , "rooms" , root , "spaces" }, map [string ]interface {}{})
175172 must .MatchResponse (t , res , match.HTTPResponse {
176173 JSON : []match.JSON {
177174 match .JSONCheckOff ("rooms" , []interface {}{
@@ -186,12 +183,6 @@ func TestClientSpacesSummary(t *testing.T) {
186183 return fmt .Errorf ("room %s got name %s want %s" , roomID , data .Get ("name" ).Str , name )
187184 }
188185 }
189- if refs , ok := roomRefs [roomID ]; ok {
190- gotRefs := data .Get ("num_refs" ).Int ()
191- if int64 (refs ) != gotRefs {
192- return fmt .Errorf ("room %s got %d refs want %d" , roomID , gotRefs , refs )
193- }
194- }
195186 if roomID == ss1 {
196187 wantType := "org.matrix.msc1772.space"
197188 if data .Get ("room_type" ).Str != wantType {
@@ -200,10 +191,10 @@ func TestClientSpacesSummary(t *testing.T) {
200191 }
201192 return nil
202193 }),
194+ // Check that the links from Root down to other rooms and spaces exist.
203195 match .JSONCheckOff ("events" , []interface {}{
204- rootToR1 , rootToR2 , rootToSS1 , r2ToRoot ,
205- ss1ToSS2 , r3ToSS1 ,
206- ss2ToR4 ,
196+ rootToR1 , rootToR2 , rootToSS1 ,
197+ ss1ToSS2 , ss2ToR3 , ss2ToR4 ,
207198 }, func (r gjson.Result ) interface {} {
208199 return eventKey (r .Get ("room_id" ).Str , r .Get ("state_key" ).Str , r .Get ("type" ).Str )
209200 }, nil ),
@@ -213,61 +204,36 @@ func TestClientSpacesSummary(t *testing.T) {
213204
214205 // - Setting max_rooms_per_space works correctly
215206 t .Run ("max_rooms_per_space" , func (t * testing.T ) {
216- // should omit either R1 or R2 if we start from R4 because we only return 1 link per room which will be:
217- // R4 -> SS2
218- // SS2 -> SS1
219- // SS1 -> root
220- // root -> R1,R2 (but only 1 is allowed)
221- res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , r4 , "spaces" }, map [string ]interface {}{
207+ // should omit either R3 or R4 if we start from SS1 because we only return 1 link per room which will be:
208+ // SS1 -> SS2
209+ // SS2 -> R3,R4 (but only 1 is allowed)
210+ res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "org.matrix.msc2946" , "rooms" , ss1 , "spaces" }, map [string ]interface {}{
222211 "max_rooms_per_space" : 1 ,
223212 })
224213 wantItems := []interface {}{
225- ss2ToR4 , ss1ToSS2 , rootToSS1 ,
226- rootToR1 , rootToR2 , // one of these
214+ ss1ToSS2 ,
215+ ss2ToR3 , ss2ToR4 , // one of these
227216 }
228217 body := must .ParseJSON (t , res .Body )
229218 gjson .GetBytes (body , "events" ).ForEach (func (_ , val gjson.Result ) bool {
230219 wantItems = must .CheckOff (t , wantItems , eventKey (val .Get ("room_id" ).Str , val .Get ("state_key" ).Str , val .Get ("type" ).Str ))
231220 return true
232221 })
233222 if len (wantItems ) != 1 {
234- if wantItems [0 ] != rootToR1 && wantItems [0 ] != rootToR2 {
223+ if wantItems [0 ] != ss2ToR3 && wantItems [0 ] != ss2ToR4 {
235224 t .Errorf ("expected fewer events to be returned: %s" , string (body ))
236225 }
237226 }
238227 })
239228
240- // - Setting limit works correctly
241- t .Run ("limit" , func (t * testing.T ) {
242- // should omit R4 due to limit
243- res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , root , "spaces" }, map [string ]interface {}{
244- "limit" : 6 ,
245- })
246- must .MatchResponse (t , res , match.HTTPResponse {
247- JSON : []match.JSON {
248- match .JSONCheckOff ("rooms" , []interface {}{
249- root , r1 , r2 , r3 , ss1 , ss2 ,
250- }, func (r gjson.Result ) interface {} {
251- return r .Get ("room_id" ).Str
252- }, nil ),
253- match .JSONCheckOff ("events" , []interface {}{
254- rootToR1 , rootToR2 , rootToSS1 , r2ToRoot ,
255- ss1ToSS2 , r3ToSS1 ,
256- }, func (r gjson.Result ) interface {} {
257- return eventKey (r .Get ("room_id" ).Str , r .Get ("state_key" ).Str , r .Get ("type" ).Str )
258- }, nil ),
259- },
260- })
261- })
262-
263229 t .Run ("redact link" , func (t * testing.T ) {
264230 // Remove the root -> SS1 link
265231 alice .SendEventSynced (t , root , b.Event {
266232 Type : spaceChildEventType ,
267233 StateKey : & ss1 ,
268234 Content : map [string ]interface {}{},
269235 })
270- res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , root , "spaces" }, map [string ]interface {}{})
236+ res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "org.matrix.msc2946" , " rooms" , root , "spaces" }, map [string ]interface {}{})
271237 must .MatchResponse (t , res , match.HTTPResponse {
272238 JSON : []match.JSON {
273239 match .JSONCheckOff ("rooms" , []interface {}{
@@ -276,7 +242,7 @@ func TestClientSpacesSummary(t *testing.T) {
276242 return r .Get ("room_id" ).Str
277243 }, nil ),
278244 match .JSONCheckOff ("events" , []interface {}{
279- rootToR1 , rootToR2 , r2ToRoot ,
245+ rootToR1 , rootToR2 ,
280246 }, func (r gjson.Result ) interface {} {
281247 return eventKey (r .Get ("room_id" ).Str , r .Get ("state_key" ).Str , r .Get ("type" ).Str )
282248 }, nil ),
@@ -383,7 +349,7 @@ func TestFederatedClientSpaces(t *testing.T) {
383349 }
384350 t .Logf ("rooms: %v" , allEvents )
385351
386- res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "rooms" , root , "spaces" }, map [string ]interface {}{})
352+ res := alice .MustDo (t , "POST" , []string {"_matrix" , "client" , "unstable" , "org.matrix.msc2946" , " rooms" , root , "spaces" }, map [string ]interface {}{})
387353 must .MatchResponse (t , res , match.HTTPResponse {
388354 JSON : []match.JSON {
389355 match .JSONCheckOff ("rooms" , []interface {}{
0 commit comments