From 36de964d51ad3c417137ca9e2190c6b01e0a3d43 Mon Sep 17 00:00:00 2001 From: Anant Prakash Date: Wed, 11 Jul 2018 15:09:41 +0530 Subject: [PATCH] Revert "check that user leaves the room" This reverts commit 227d53dff4cea8e93d8cb1347a8e17912d3b96af. Revert "Add internal API QueryMembershipForUser" This reverts commit 1241cf66d8e46f9c378ef1a6e44556bb46d1c98d. --- .../dendrite/federationapi/routing/leave.go | 29 ------------ .../dendrite/federationapi/routing/routing.go | 2 +- .../dendrite/roomserver/api/query.go | 42 ----------------- .../dendrite/roomserver/query/query.go | 45 ------------------- 4 files changed, 1 insertion(+), 117 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/leave.go b/src/github.com/matrix-org/dendrite/federationapi/routing/leave.go index 101d54446..44bfab980 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/leave.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/leave.go @@ -14,7 +14,6 @@ package routing import ( "encoding/json" - "fmt" "net/http" "github.com/matrix-org/dendrite/clientapi/httputil" @@ -97,7 +96,6 @@ func SendLeave( request *gomatrixserverlib.FederationRequest, cfg config.Dendrite, producer *producers.RoomserverProducer, - query api.RoomserverQueryAPI, keys gomatrixserverlib.KeyRing, roomID, eventID string, ) util.JSONResponse { @@ -150,16 +148,6 @@ func SendLeave( } } - var userID string - if stateKey := event.StateKey(); stateKey != nil { - userID = *stateKey - } else { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.BadJSON("The event JSON should contain the stateKey"), - } - } - // Send the events to the room server. // We are responsible for notifying other servers that the user has left // the room, so set SendAsServer to cfg.Matrix.ServerName @@ -168,23 +156,6 @@ func SendLeave( return httputil.LogThenError(httpReq, err) } - // Check that the leave has taken effect - var response api.QueryMembershipForUserResponse - if err = query.QueryMembershipForUser( - httpReq.Context(), - &api.QueryMembershipForUserRequest{ - RoomID: event.RoomID(), - Sender: userID, - }, - &response, - ); err != nil { - return httputil.LogThenError(httpReq, err) - } - - if response.IsInRoom { - return httputil.LogThenError(httpReq, fmt.Errorf("user (user ID: %s) is still in room", userID)) - } - return util.JSONResponse{ Code: http.StatusOK, JSON: struct{}{}, diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go index fd81b0b64..d52f3e63c 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -201,7 +201,7 @@ func Setup( roomID := vars["roomID"] userID := vars["userID"] return SendLeave( - httpReq, request, cfg, producer, query, keys, roomID, userID, + httpReq, request, cfg, producer, keys, roomID, userID, ) }, )).Methods(http.MethodPut) diff --git a/src/github.com/matrix-org/dendrite/roomserver/api/query.go b/src/github.com/matrix-org/dendrite/roomserver/api/query.go index 3b10bc62a..258f31c1b 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/api/query.go +++ b/src/github.com/matrix-org/dendrite/roomserver/api/query.go @@ -104,25 +104,6 @@ type QueryEventsByIDResponse struct { Events []gomatrixserverlib.Event `json:"events"` } -// QueryMembershipForUserRequest is a request to QueryMembership -type QueryMembershipForUserRequest struct { - // ID of the room to fetch membership from - RoomID string `json:"room_id"` - // ID of the user sending the request - Sender string `json:"sender"` -} - -// QueryMembershipForUserResponse is a response to QueryMembership -type QueryMembershipForUserResponse struct { - // The EventID of the latest "m.room.member" event for the sender, - // if HasBeenInRoom is true. - EventID string `json:"event_id"` - // True if the user has been in room before and has either stayed in it or left it. - HasBeenInRoom bool `json:"has_been_in_room"` - // True if the user is in room. - IsInRoom bool `json:"is_in_room"` -} - // QueryMembershipsForRoomRequest is a request to QueryMembershipsForRoom type QueryMembershipsForRoomRequest struct { // If true, only returns the membership events of "join" membership @@ -241,13 +222,6 @@ type RoomserverQueryAPI interface { response *QueryEventsByIDResponse, ) error - // Query the membership event for an user for a room. - QueryMembershipForUser( - ctx context.Context, - request *QueryMembershipForUserRequest, - response *QueryMembershipForUserResponse, - ) error - // Query a list of membership events for a room QueryMembershipsForRoom( ctx context.Context, @@ -295,9 +269,6 @@ const RoomserverQueryStateAfterEventsPath = "/api/roomserver/queryStateAfterEven // RoomserverQueryEventsByIDPath is the HTTP path for the QueryEventsByID API. const RoomserverQueryEventsByIDPath = "/api/roomserver/queryEventsByID" -// RoomserverQueryMembershipForUserPath is the HTTP path for the QueryMembershipForUser API. -const RoomserverQueryMembershipForUserPath = "/api/roomserver/queryMembershipForUser" - // RoomserverQueryMembershipsForRoomPath is the HTTP path for the QueryMembershipsForRoom API const RoomserverQueryMembershipsForRoomPath = "/api/roomserver/queryMembershipsForRoom" @@ -366,19 +337,6 @@ func (h *httpRoomserverQueryAPI) QueryEventsByID( return postJSON(ctx, span, h.httpClient, apiURL, request, response) } -// QueryMembershipForUser implements RoomserverQueryAPI -func (h *httpRoomserverQueryAPI) QueryMembershipForUser( - ctx context.Context, - request *QueryMembershipForUserRequest, - response *QueryMembershipForUserResponse, -) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipForUser") - defer span.Finish() - - apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath - return postJSON(ctx, span, h.httpClient, apiURL, request, response) -} - // QueryMembershipsForRoom implements RoomserverQueryAPI func (h *httpRoomserverQueryAPI) QueryMembershipsForRoom( ctx context.Context, diff --git a/src/github.com/matrix-org/dendrite/roomserver/query/query.go b/src/github.com/matrix-org/dendrite/roomserver/query/query.go index 243ad8310..de0b43ffe 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/query/query.go +++ b/src/github.com/matrix-org/dendrite/roomserver/query/query.go @@ -227,37 +227,6 @@ func (r *RoomserverQueryAPI) loadEvents( return result, nil } -// QueryMembershipForUser implements api.RoomserverQueryAPI -func (r *RoomserverQueryAPI) QueryMembershipForUser( - ctx context.Context, - request *api.QueryMembershipForUserRequest, - response *api.QueryMembershipForUserResponse, -) error { - roomNID, err := r.DB.RoomNID(ctx, request.RoomID) - if err != nil { - return err - } - - membershipEventNID, stillInRoom, err := r.DB.GetMembership(ctx, roomNID, request.Sender) - if err != nil { - return err - } - - if membershipEventNID == 0 { - response.HasBeenInRoom = false - return nil - } - - response.IsInRoom = stillInRoom - eventIDMap, err := r.DB.EventIDs(ctx, []types.EventNID{membershipEventNID}) - if err != nil { - return err - } - - response.EventID = eventIDMap[membershipEventNID] - return nil -} - // QueryMembershipsForRoom implements api.RoomserverQueryAPI func (r *RoomserverQueryAPI) QueryMembershipsForRoom( ctx context.Context, @@ -624,20 +593,6 @@ func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( - api.RoomserverQueryMembershipForUserPath, - common.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse { - var request api.QueryMembershipForUserRequest - var response api.QueryMembershipForUserResponse - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.ErrorResponse(err) - } - if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil { - return util.ErrorResponse(err) - } - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) servMux.Handle( api.RoomserverQueryMembershipsForRoomPath, common.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {