From 15a1db7062d2e8f1e730674b4b71ae5154b59ae6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 24 Apr 2020 09:56:26 +0100 Subject: [PATCH] SendInvite improvements --- clientapi/producers/roomserver.go | 3 +++ clientapi/routing/membership.go | 40 +++++++++++++++++++++---------- federationapi/routing/invite.go | 2 ++ roomserver/api/input.go | 2 ++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/clientapi/producers/roomserver.go b/clientapi/producers/roomserver.go index 391ea07bf..fac1e3c7c 100644 --- a/clientapi/producers/roomserver.go +++ b/clientapi/producers/roomserver.go @@ -106,12 +106,15 @@ func (c *RoomserverProducer) SendInputRoomEvents( func (c *RoomserverProducer) SendInvite( ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent, inviteRoomState []gomatrixserverlib.InviteV2StrippedState, + sendAsServer gomatrixserverlib.ServerName, txnID *api.TransactionID, ) error { request := api.InputRoomEventsRequest{ InputInviteEvents: []api.InputInviteEvent{{ Event: inviteEvent, InviteRoomState: inviteRoomState, RoomVersion: inviteEvent.RoomVersion, + SendAsServer: string(sendAsServer), + TransactionID: txnID, }}, } var response api.InputRoomEventsResponse diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index 9f386b718..d3b86fcbf 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -104,23 +104,39 @@ func SendMembership( return jsonerror.InternalServerError() } - if _, err := producer.SendEvents( - req.Context(), - []gomatrixserverlib.HeaderedEvent{(*event).Headered(verRes.RoomVersion)}, - cfg.Matrix.ServerName, - nil, - ); err != nil { - util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed") - return jsonerror.InternalServerError() - } - var returnData interface{} = struct{}{} - // The join membership requires the room id to be sent in the response - if membership == gomatrixserverlib.Join { + switch membership { + case gomatrixserverlib.Invite: + // Invites need to be handled specially + err = producer.SendInvite( + req.Context(), + event.Headered(verRes.RoomVersion), + nil, // ask the roomserver to draw up invite room state for us + cfg.Matrix.ServerName, + nil, + ) + if err != nil { + util.GetLogger(req.Context()).WithError(err).Error("producer.SendInvite failed") + return jsonerror.InternalServerError() + } + case gomatrixserverlib.Join: + // The join membership requires the room id to be sent in the response returnData = struct { RoomID string `json:"room_id"` }{roomID} + fallthrough + default: + _, err = producer.SendEvents( + req.Context(), + []gomatrixserverlib.HeaderedEvent{(*event).Headered(verRes.RoomVersion)}, + cfg.Matrix.ServerName, + nil, + ) + if err != nil { + util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed") + return jsonerror.InternalServerError() + } } return util.JSONResponse{ diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 4b367e004..332f7f70c 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -90,6 +90,8 @@ func Invite( httpReq.Context(), signedEvent.Headered(inviteReq.RoomVersion()), inviteReq.InviteRoomState(), + event.Origin(), + nil, ); err != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed") return jsonerror.InternalServerError() diff --git a/roomserver/api/input.go b/roomserver/api/input.go index 87e3983e3..bb4e040de 100644 --- a/roomserver/api/input.go +++ b/roomserver/api/input.go @@ -89,6 +89,8 @@ type InputInviteEvent struct { RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` Event gomatrixserverlib.HeaderedEvent `json:"event"` InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"` + SendAsServer string `json:"send_as_server"` + TransactionID *TransactionID `json:"transaction_id"` } // InputRoomEventsRequest is a request to InputRoomEvents