mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
check that user leaves the room
This commit is contained in:
parent
1241cf66d8
commit
227d53dff4
|
|
@ -14,6 +14,7 @@ package routing
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
|
|
@ -96,6 +97,7 @@ func SendLeave(
|
|||
request *gomatrixserverlib.FederationRequest,
|
||||
cfg config.Dendrite,
|
||||
producer *producers.RoomserverProducer,
|
||||
query api.RoomserverQueryAPI,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
roomID, eventID string,
|
||||
) util.JSONResponse {
|
||||
|
|
@ -148,6 +150,16 @@ 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
|
||||
|
|
@ -156,6 +168,23 @@ 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{}{},
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ func Setup(
|
|||
roomID := vars["roomID"]
|
||||
userID := vars["userID"]
|
||||
return SendLeave(
|
||||
httpReq, request, cfg, producer, keys, roomID, userID,
|
||||
httpReq, request, cfg, producer, query, keys, roomID, userID,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodPut)
|
||||
|
|
|
|||
Loading…
Reference in a new issue