Federation: Improve /query/directory endpoint (#525)

main
Andrew Morgan 2018-08-07 06:41:50 -07:00 committed by GitHub
parent b11591fdd1
commit e05a31f4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -34,7 +34,7 @@ func RoomAliasToID(
cfg config.Dendrite, cfg config.Dendrite,
aliasAPI api.RoomserverAliasAPI, aliasAPI api.RoomserverAliasAPI,
) util.JSONResponse { ) util.JSONResponse {
roomAlias := httpReq.FormValue("alias") roomAlias := httpReq.FormValue("room_alias")
if roomAlias == "" { if roomAlias == "" {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
@ -58,14 +58,14 @@ func RoomAliasToID(
return httputil.LogThenError(httpReq, err) return httputil.LogThenError(httpReq, err)
} }
if queryRes.RoomID == "" { if queryRes.RoomID != "" {
// TODO: List servers that are aware of this room alias // TODO: List servers that are aware of this room alias
resp = gomatrixserverlib.RespDirectory{ resp = gomatrixserverlib.RespDirectory{
RoomID: queryRes.RoomID, RoomID: queryRes.RoomID,
Servers: []gomatrixserverlib.ServerName{}, Servers: []gomatrixserverlib.ServerName{},
} }
} else { } else {
// If the response doesn't contain a non-empty string, return an error // If no alias was found, return an error
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,
JSON: jsonerror.NotFound(fmt.Sprintf("Room alias %s not found", roomAlias)), JSON: jsonerror.NotFound(fmt.Sprintf("Room alias %s not found", roomAlias)),

View File

@ -127,7 +127,7 @@ func Setup(
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
v1fedmux.Handle("/query/directory/", common.MakeFedAPI( v1fedmux.Handle("/query/directory", common.MakeFedAPI(
"federation_query_room_alias", cfg.Matrix.ServerName, keys, "federation_query_room_alias", cfg.Matrix.ServerName, keys,
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
return RoomAliasToID( return RoomAliasToID(