mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Try to handle invites better in roomserver, federationapi
This commit is contained in:
parent
b95f2b8a64
commit
aba581f3f1
|
|
@ -37,26 +37,39 @@ func Invite(
|
||||||
producer *producers.RoomserverProducer,
|
producer *producers.RoomserverProducer,
|
||||||
keys gomatrixserverlib.KeyRing,
|
keys gomatrixserverlib.KeyRing,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
inviteReq := gomatrixserverlib.InviteV2Request{}
|
var intermediate struct {
|
||||||
if err := json.Unmarshal(request.Content(), &inviteReq); err != nil {
|
Event json.RawMessage `json:"event"`
|
||||||
|
InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"`
|
||||||
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal the request into the intermediate form.
|
||||||
|
if err := json.Unmarshal(request.Content(), &intermediate); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request. " + err.Error()),
|
JSON: jsonerror.NotJSON("The request body could not be decoded into an invite request: " + err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event := inviteReq.Event()
|
|
||||||
|
|
||||||
// Check if we support the room version for the invite.
|
// Check if we support the supplied room version before doing anything else.
|
||||||
roomVersion := inviteReq.RoomVersion()
|
if _, err := roomserverVersion.SupportedRoomVersion(intermediate.RoomVersion); err != nil {
|
||||||
if _, err := roomserverVersion.SupportedRoomVersion(roomVersion); err != nil {
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnsupportedRoomVersion(
|
JSON: jsonerror.UnsupportedRoomVersion(
|
||||||
fmt.Sprintf("Users of this server cannot join version %q rooms.", roomVersion),
|
fmt.Sprintf("Users of this server cannot join version %q rooms.", intermediate.RoomVersion),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unmarshal the event.
|
||||||
|
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(intermediate.Event, intermediate.RoomVersion)
|
||||||
|
if err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.NotJSON("The event in the request body could not be parsed: " + err.Error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check that the room ID is correct.
|
// Check that the room ID is correct.
|
||||||
if event.RoomID() != roomID {
|
if event.RoomID() != roomID {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
|
|
@ -101,8 +114,8 @@ func Invite(
|
||||||
// Add the invite event to the roomserver.
|
// Add the invite event to the roomserver.
|
||||||
if err = producer.SendInvite(
|
if err = producer.SendInvite(
|
||||||
httpReq.Context(),
|
httpReq.Context(),
|
||||||
signedEvent.Headered(inviteReq.RoomVersion()),
|
signedEvent.Headered(intermediate.RoomVersion),
|
||||||
inviteReq.InviteRoomState(),
|
intermediate.InviteRoomState,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed")
|
util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
|
|
||||||
|
|
@ -190,12 +190,8 @@ func (s *OutputRoomEventConsumer) processInvite(oie api.OutputNewInviteEvent) er
|
||||||
// When sending a v2 invite, the inviting server should try and include
|
// When sending a v2 invite, the inviting server should try and include
|
||||||
// a "stripped down" version of the room state. This is pretty much just
|
// a "stripped down" version of the room state. This is pretty much just
|
||||||
// enough information for the remote side to show something useful to the
|
// enough information for the remote side to show something useful to the
|
||||||
// user, like the room name, aliases etc. Initially we'll strip down
|
// user, like the room name, aliases etc.
|
||||||
// the invite event itself, as this satisfies the membership event in the
|
strippedState := []gomatrixserverlib.InviteV2StrippedState{}
|
||||||
// stripped state.
|
|
||||||
strippedState := []gomatrixserverlib.InviteV2StrippedState{
|
|
||||||
gomatrixserverlib.NewInviteV2StrippedState(&oie.Event.Event),
|
|
||||||
}
|
|
||||||
stateWanted := []string{
|
stateWanted := []string{
|
||||||
gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias,
|
gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias,
|
||||||
gomatrixserverlib.MRoomAliases, gomatrixserverlib.MRoomJoinRules,
|
gomatrixserverlib.MRoomAliases, gomatrixserverlib.MRoomJoinRules,
|
||||||
|
|
|
||||||
|
|
@ -247,9 +247,11 @@ func processInviteEvent(
|
||||||
|
|
||||||
event := input.Event.Unwrap()
|
event := input.Event.Unwrap()
|
||||||
|
|
||||||
|
if len(input.InviteRoomState) > 0 {
|
||||||
if err = event.SetUnsignedField("invite_room_state", input.InviteRoomState); err != nil {
|
if err = event.SetUnsignedField("invite_room_state", input.InviteRoomState); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
outputUpdates, err := updateToInviteMembership(updater, &event, nil, input.Event.RoomVersion)
|
outputUpdates, err := updateToInviteMembership(updater, &event, nil, input.Event.RoomVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue