diff options
Diffstat (limited to 'clientapi/routing/sendtyping.go')
-rw-r--r-- | clientapi/routing/sendtyping.go | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/clientapi/routing/sendtyping.go b/clientapi/routing/sendtyping.go index 54a82286..e4b5b7a3 100644 --- a/clientapi/routing/sendtyping.go +++ b/clientapi/routing/sendtyping.go @@ -21,7 +21,6 @@ import ( "github.com/matrix-org/dendrite/eduserver/api" userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/storage/accounts" - "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -46,46 +45,19 @@ func SendTyping( } // Verify that the user is a member of this room - tuple := gomatrixserverlib.StateKeyTuple{ - EventType: gomatrixserverlib.MRoomMember, - StateKey: userID, - } - var res currentstateAPI.QueryCurrentStateResponse - err := stateAPI.QueryCurrentState(req.Context(), ¤tstateAPI.QueryCurrentStateRequest{ - RoomID: roomID, - StateTuples: []gomatrixserverlib.StateKeyTuple{tuple}, - }, &res) - if err != nil { - util.GetLogger(req.Context()).WithError(err).Error("QueryCurrentState failed") - return jsonerror.InternalServerError() - } - ev := res.StateEvents[tuple] - if ev == nil { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: jsonerror.Forbidden("User not in this room"), - } - } - membership, err := ev.Membership() - if err != nil { - util.GetLogger(req.Context()).WithError(err).Error("Member event isn't valid") - return jsonerror.InternalServerError() - } - if membership != gomatrixserverlib.Join { - return util.JSONResponse{ - Code: http.StatusForbidden, - JSON: jsonerror.Forbidden("User not in this room"), - } + resErr := checkMemberInRoom(req.Context(), stateAPI, userID, roomID) + if resErr != nil { + return *resErr } // parse the incoming http request var r typingContentJSON - resErr := httputil.UnmarshalJSONRequest(req, &r) + resErr = httputil.UnmarshalJSONRequest(req, &r) if resErr != nil { return *resErr } - if err = api.SendTyping( + if err := api.SendTyping( req.Context(), eduAPI, userID, roomID, r.Typing, r.Timeout, ); err != nil { util.GetLogger(req.Context()).WithError(err).Error("eduProducer.Send failed") |