mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 23:23:10 -06:00
Add federated route for room/space hierarchy
This commit is contained in:
parent
c97ba0b9e6
commit
d62a706a44
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
@ -116,3 +117,49 @@ func RoomAliasToID(
|
||||||
JSON: resp,
|
JSON: resp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func QueryRoomHierarchy(httpReq *http.Request, request *fclient.FederationRequest, roomIDStr string, rsAPI roomserverAPI.FederationRoomserverAPI) util.JSONResponse {
|
||||||
|
parsedRoomID, err := spec.NewRoomID(roomIDStr)
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusNotFound,
|
||||||
|
JSON: spec.InvalidParam("room is unknown/forbidden"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
roomID := *parsedRoomID
|
||||||
|
|
||||||
|
suggestedOnly := false // Defaults to false (spec-defined)
|
||||||
|
switch httpReq.URL.Query().Get("suggested_only") {
|
||||||
|
case "true":
|
||||||
|
suggestedOnly = true
|
||||||
|
case "false":
|
||||||
|
case "": // Empty string is returned when query param is not set
|
||||||
|
default:
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: spec.InvalidParam("query parameter 'suggested_only', if set, must be 'true' or 'false'"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
walker := rsAPI.QueryRoomHierarchy(httpReq.Context(), types.NewServerNameNotDevice(request.Origin()), roomID, suggestedOnly, 1)
|
||||||
|
|
||||||
|
discoveredRooms, err := walker.NextPage(-1)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(discoveredRooms) == 0 {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 404,
|
||||||
|
JSON: spec.NotFound("room is unknown/forbidden"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 200,
|
||||||
|
JSON: fclient.MSC2946SpacesResponse{
|
||||||
|
Room: discoveredRooms[0],
|
||||||
|
Children: discoveredRooms[1:],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -596,6 +596,13 @@ func Setup(
|
||||||
return GetOpenIDUserInfo(req, userAPI)
|
return GetOpenIDUserInfo(req, userAPI)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet)
|
).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
v1fedmux.Handle("/hierarchy/{roomID}", MakeFedAPI(
|
||||||
|
"federation_room_hierarchy", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
||||||
|
func(httpReq *http.Request, request *fclient.FederationRequest, vars map[string]string) util.JSONResponse {
|
||||||
|
return QueryRoomHierarchy(httpReq, request, vars["roomID"], rsAPI)
|
||||||
|
},
|
||||||
|
)).Methods(http.MethodGet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrorIfLocalServerNotInRoom(
|
func ErrorIfLocalServerNotInRoom(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue