mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33: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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
|
@ -96,6 +97,7 @@ func SendLeave(
|
||||||
request *gomatrixserverlib.FederationRequest,
|
request *gomatrixserverlib.FederationRequest,
|
||||||
cfg config.Dendrite,
|
cfg config.Dendrite,
|
||||||
producer *producers.RoomserverProducer,
|
producer *producers.RoomserverProducer,
|
||||||
|
query api.RoomserverQueryAPI,
|
||||||
keys gomatrixserverlib.KeyRing,
|
keys gomatrixserverlib.KeyRing,
|
||||||
roomID, eventID string,
|
roomID, eventID string,
|
||||||
) util.JSONResponse {
|
) 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.
|
// Send the events to the room server.
|
||||||
// We are responsible for notifying other servers that the user has left
|
// We are responsible for notifying other servers that the user has left
|
||||||
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
// the room, so set SendAsServer to cfg.Matrix.ServerName
|
||||||
|
|
@ -156,6 +168,23 @@ func SendLeave(
|
||||||
return httputil.LogThenError(httpReq, err)
|
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{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: struct{}{},
|
JSON: struct{}{},
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ func Setup(
|
||||||
roomID := vars["roomID"]
|
roomID := vars["roomID"]
|
||||||
userID := vars["userID"]
|
userID := vars["userID"]
|
||||||
return SendLeave(
|
return SendLeave(
|
||||||
httpReq, request, cfg, producer, keys, roomID, userID,
|
httpReq, request, cfg, producer, query, keys, roomID, userID,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)).Methods(http.MethodPut)
|
)).Methods(http.MethodPut)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue