Return empty inaccessibleRooms

This commit is contained in:
Till Faelligen 2024-03-25 20:16:29 +01:00
parent 42a452cec2
commit 52a441a2ef
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
4 changed files with 20 additions and 11 deletions

View file

@ -138,7 +138,7 @@ func QueryRoomHierarchy(req *http.Request, device *userapi.Device, roomIDStr str
walker = *cachedWalker walker = *cachedWalker
} }
discoveredRooms, nextWalker, err := rsAPI.QueryNextRoomHierarchyPage(req.Context(), walker, limit) discoveredRooms, _, nextWalker, err := rsAPI.QueryNextRoomHierarchyPage(req.Context(), walker, limit)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {

View file

@ -146,7 +146,7 @@ func QueryRoomHierarchy(httpReq *http.Request, request *fclient.FederationReques
} }
walker := roomserverAPI.NewRoomHierarchyWalker(types.NewServerNameNotDevice(request.Origin()), roomID, suggestedOnly, 1) walker := roomserverAPI.NewRoomHierarchyWalker(types.NewServerNameNotDevice(request.Origin()), roomID, suggestedOnly, 1)
discoveredRooms, _, err := rsAPI.QueryNextRoomHierarchyPage(httpReq.Context(), walker, -1) discoveredRooms, inaccessibleRooms, _, err := rsAPI.QueryNextRoomHierarchyPage(httpReq.Context(), walker, -1)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
@ -177,8 +177,7 @@ func QueryRoomHierarchy(httpReq *http.Request, request *fclient.FederationReques
JSON: fclient.RoomHierarchyResponse{ JSON: fclient.RoomHierarchyResponse{
Room: discoveredRooms[0], Room: discoveredRooms[0],
Children: discoveredRooms[1:], Children: discoveredRooms[1:],
// TODO: Actually check which rooms the requesting server/user is not allowed to see. InaccessibleChildren: inaccessibleRooms,
InaccessibleChildren: []string{},
}, },
} }
} }

View file

@ -141,7 +141,12 @@ type QueryRoomHierarchyAPI interface {
// //
// If returned walker is nil, then there are no more rooms left to traverse. This method does not modify the provided walker, so it // If returned walker is nil, then there are no more rooms left to traverse. This method does not modify the provided walker, so it
// can be cached. // can be cached.
QueryNextRoomHierarchyPage(ctx context.Context, walker RoomHierarchyWalker, limit int) ([]fclient.RoomHierarchyRoom, *RoomHierarchyWalker, error) QueryNextRoomHierarchyPage(ctx context.Context, walker RoomHierarchyWalker, limit int) (
hierarchyRooms []fclient.RoomHierarchyRoom,
inaccessibleRooms []string,
hierarchyWalker *RoomHierarchyWalker,
err error,
)
} }
type QueryMembershipAPI interface { type QueryMembershipAPI interface {

View file

@ -39,9 +39,14 @@ import (
// //
// If returned walker is nil, then there are no more rooms left to traverse. This method does not modify the provided walker, so it // If returned walker is nil, then there are no more rooms left to traverse. This method does not modify the provided walker, so it
// can be cached. // can be cached.
func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker roomserver.RoomHierarchyWalker, limit int) ([]fclient.RoomHierarchyRoom, *roomserver.RoomHierarchyWalker, error) { func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker roomserver.RoomHierarchyWalker, limit int) (
[]fclient.RoomHierarchyRoom,
[]string,
*roomserver.RoomHierarchyWalker,
error,
) {
if authorised, _ := authorised(ctx, querier, walker.Caller, walker.RootRoomID, nil); !authorised { if authorised, _ := authorised(ctx, querier, walker.Caller, walker.RootRoomID, nil); !authorised {
return nil, nil, roomserver.ErrRoomUnknownOrNotAllowed{Err: fmt.Errorf("room is unknown/forbidden")} return nil, []string{}, nil, roomserver.ErrRoomUnknownOrNotAllowed{Err: fmt.Errorf("room is unknown/forbidden")}
} }
discoveredRooms := []fclient.RoomHierarchyRoom{} discoveredRooms := []fclient.RoomHierarchyRoom{}
@ -173,7 +178,7 @@ func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker r
if len(unvisited) == 0 { if len(unvisited) == 0 {
// If no more rooms to walk, then don't return a walker for future pages // If no more rooms to walk, then don't return a walker for future pages
return discoveredRooms, nil, nil return discoveredRooms, []string{}, nil, nil
} else { } else {
// If there are more rooms to walk, then return a new walker to resume walking from (for querying more pages) // If there are more rooms to walk, then return a new walker to resume walking from (for querying more pages)
newWalker := roomserver.RoomHierarchyWalker{ newWalker := roomserver.RoomHierarchyWalker{
@ -185,7 +190,7 @@ func (querier *Queryer) QueryNextRoomHierarchyPage(ctx context.Context, walker r
Processed: processed, Processed: processed,
} }
return discoveredRooms, &newWalker, nil return discoveredRooms, []string{}, &newWalker, nil
} }
} }