From a652f094e58fd1094c1c6b91282c596fb1e2a553 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 23 Jun 2020 16:47:42 +0100 Subject: [PATCH] Include m.room.avatar in stripped state; handle trailing slashes when GETing state events --- clientapi/routing/joinroom.go | 4 +++- clientapi/routing/routing.go | 9 +++++++-- roomserver/internal/input_events.go | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clientapi/routing/joinroom.go b/clientapi/routing/joinroom.go index 2e5cc3a16..e606e35f1 100644 --- a/clientapi/routing/joinroom.go +++ b/clientapi/routing/joinroom.go @@ -18,6 +18,7 @@ import ( "errors" "net/http" + "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" @@ -53,7 +54,8 @@ func JoinRoomByIDOrAlias( util.GetLogger(req.Context()).WithError(err).Error("gomatrixserverlib.SplitID failed") } else { // Request our profile content to populate the request content with. - profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart) + var profile *authtypes.Profile + profile, err = accountDB.GetProfileByLocalpart(req.Context(), localpart) if err != nil { util.GetLogger(req.Context()).WithError(err).Error("accountDB.GetProfileByLocalpart failed") } else { diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index e91b07ac7..825ac50f2 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -159,13 +159,18 @@ func Setup( return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"]) })).Methods(http.MethodGet, http.MethodOptions) - r0mux.Handle("/rooms/{roomID}/state/{type}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse { + r0mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse { vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) } + // If there's a trailing slash, remove it + eventType := vars["type"] + if strings.HasSuffix(eventType, "/") { + eventType = eventType[:len(eventType)-1] + } eventFormat := req.URL.Query().Get("format") == "event" - return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "", eventFormat) + return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], eventType, "", eventFormat) })).Methods(http.MethodGet, http.MethodOptions) r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *api.Device) util.JSONResponse { diff --git a/roomserver/internal/input_events.go b/roomserver/internal/input_events.go index 4487aea02..fe3bdf4b8 100644 --- a/roomserver/internal/input_events.go +++ b/roomserver/internal/input_events.go @@ -298,9 +298,12 @@ func buildInviteStrippedState( return nil, fmt.Errorf("room %q unknown", input.Event.RoomID()) } stateWanted := []gomatrixserverlib.StateKeyTuple{} + // "If they are set on the room, at least the state for m.room.avatar, m.room.canonical_alias, m.room.join_rules, and m.room.name SHOULD be included." + // https://matrix.org/docs/spec/client_server/r0.6.0#m-room-member for _, t := range []string{ gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias, gomatrixserverlib.MRoomAliases, gomatrixserverlib.MRoomJoinRules, + "m.room.avatar", } { stateWanted = append(stateWanted, gomatrixserverlib.StateKeyTuple{ EventType: t,