diff --git a/clientapi/producers/roomserver.go b/clientapi/producers/roomserver.go index d5a8ffd8f..f537557f5 100644 --- a/clientapi/producers/roomserver.go +++ b/clientapi/producers/roomserver.go @@ -99,19 +99,3 @@ func (c *RoomserverProducer) SendInputRoomEvents( eventID = response.EventID return } - -// SendInvite writes the invite event to the roomserver input API. -// This should only be needed for invite events that occur outside of a known room. -// If we are in the room then the event should be sent using the SendEvents method. -func (c *RoomserverProducer) SendInvite( - ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent, -) error { - request := api.InputRoomEventsRequest{ - InputInviteEvents: []api.InputInviteEvent{{ - Event: inviteEvent, - RoomVersion: inviteEvent.RoomVersion, - }}, - } - var response api.InputRoomEventsResponse - return c.InputAPI.InputRoomEvents(ctx, &request, &response) -} diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index 0aac3ac15..35e77e3c2 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -41,7 +41,7 @@ func Invite( var intermediate struct { Event json.RawMessage `json:"event"` - InviteRoomState []json.RawMessage `json:"invite_room_state"` + InviteRoomState json.RawMessage `json:"invite_room_state"` RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` } @@ -88,6 +88,12 @@ func Invite( } } + // Populate the unsigned key with the invite room state. + if err = event.SetUnsignedField("invite_room_state", intermediate.InviteRoomState); err != nil { + util.GetLogger(httpReq.Context()).WithError(err).Error("event.SetUnsignedField failed") + return jsonerror.InternalServerError() + } + // Check that the event is signed by the server sending the request. redacted := event.Redact() verifyRequests := []gomatrixserverlib.VerifyJSONRequest{{ @@ -114,11 +120,13 @@ func Invite( ) // Add the invite event to the roomserver. - if err = producer.SendInvite( + if _, err := producer.SendEvents( httpReq.Context(), - signedEvent.Headered(intermediate.RoomVersion), + []gomatrixserverlib.HeaderedEvent{signedEvent.Headered(intermediate.RoomVersion)}, + signedEvent.Origin(), + nil, ); err != nil { - util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendInvite failed") + util.GetLogger(httpReq.Context()).WithError(err).Error("producer.SendEvents failed") return jsonerror.InternalServerError() } diff --git a/federationsender/consumers/roomserver.go b/federationsender/consumers/roomserver.go index 68fa065fb..ab9e51407 100644 --- a/federationsender/consumers/roomserver.go +++ b/federationsender/consumers/roomserver.go @@ -187,6 +187,10 @@ func (s *OutputRoomEventConsumer) processInvite(oie api.OutputNewInviteEvent) er return nil } + fmt.Println("FEDERATION SENDER IS PROCESSING INVITE") + fmt.Println("Event:", string(oie.Event.JSON())) + fmt.Println("Invite room state:", string(oie.InviteRoomState)) + // Try to unmarshal the invite room state to pass to the destination queue. inviteRoomState := []gomatrixserverlib.InviteV2StrippedState{} if err := json.Unmarshal(oie.InviteRoomState, &inviteRoomState); err != nil { diff --git a/roomserver/api/input.go b/roomserver/api/input.go index 37c5c44d7..fbedff2ed 100644 --- a/roomserver/api/input.go +++ b/roomserver/api/input.go @@ -17,7 +17,6 @@ package api import ( "context" - "encoding/json" "errors" "net/http" @@ -83,19 +82,9 @@ type TransactionID struct { TransactionID string `json:"id"` } -// InputInviteEvent is a matrix invite event received over federation without -// the usual context a matrix room event would have. We usually do not have -// access to the events needed to check the event auth rules for the invite. -type InputInviteEvent struct { - RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` - Event gomatrixserverlib.HeaderedEvent `json:"event"` - InviteRoomState json.RawMessage `json:"invite_room_state"` -} - // InputRoomEventsRequest is a request to InputRoomEvents type InputRoomEventsRequest struct { - InputRoomEvents []InputRoomEvent `json:"input_room_events"` - InputInviteEvents []InputInviteEvent `json:"input_invite_events"` + InputRoomEvents []InputRoomEvent `json:"input_room_events"` } // InputRoomEventsResponse is a response to InputRoomEvents diff --git a/roomserver/input/events.go b/roomserver/input/events.go index 66c22139d..64d696cd1 100644 --- a/roomserver/input/events.go +++ b/roomserver/input/events.go @@ -18,16 +18,12 @@ package input import ( "context" - "encoding/json" - "fmt" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/state/database" "github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/gomatrixserverlib" - log "github.com/sirupsen/logrus" ) // A RoomEventDatabase has the storage APIs needed to store a room event. @@ -185,6 +181,7 @@ func calculateAndSetState( return db.SetState(ctx, stateAtEvent.EventNID, stateAtEvent.BeforeStateSnapshotNID) } +/* func processInviteEvent( ctx context.Context, db RoomEventDatabase, @@ -251,6 +248,11 @@ func processInviteEvent( event := input.Event.Unwrap() inviteStrippedState := input.InviteRoomState + fmt.Println("ROOM SERVER RECEIVED EVENT:") + j1, _ := json.MarshalIndent(event, "", " ") + j2, _ := json.MarshalIndent(inviteStrippedState, "", " ") + fmt.Printf("Event: %s\nInvite room state: %s\n", j1, j2) + // TODO: replace this with a proper origin check if inviteStrippedState == nil { // Otherwise, we should see if we know anything about the room state @@ -327,3 +329,4 @@ func buildInviteStrippedState( } return inviteStrippedState, nil } +*/ diff --git a/roomserver/input/input.go b/roomserver/input/input.go index 3b519ecba..fb69e9014 100644 --- a/roomserver/input/input.go +++ b/roomserver/input/input.go @@ -69,11 +69,6 @@ func (r *RoomserverInputAPI) InputRoomEvents( return err } } - for i := range request.InputInviteEvents { - if err = processInviteEvent(ctx, r.DB, r, request.InputInviteEvents[i]); err != nil { - return err - } - } return nil }