From 8fa3002f8878e855776d8a7cf680f3c5031c6d08 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 17 Aug 2020 13:38:58 +0100 Subject: [PATCH] Make PerformJoin send input membership event --- roomserver/api/wrapper.go | 17 ----------------- roomserver/internal/perform_invite.go | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go index ed3daf67e..207c12c8f 100644 --- a/roomserver/api/wrapper.go +++ b/roomserver/api/wrapper.go @@ -118,23 +118,6 @@ func SendInvite( return response.Error } - // Now send the invite event into the roomserver. If the room is known - // locally then this will succeed, notifying existing users in the room - // about the new invite. If the room isn't known locally then this will - // fail - and that's also OK. - inputReq := &InputRoomEventsRequest{ - InputRoomEvents: []InputRoomEvent{ - { - Kind: KindNew, - Event: inviteEvent, - AuthEventIDs: inviteEvent.AuthEventIDs(), - SendAsServer: string(sendAsServer), - }, - }, - } - inputRes := &InputRoomEventsResponse{} - _ = rsAPI.InputRoomEvents(ctx, inputReq, inputRes) - return nil } diff --git a/roomserver/internal/perform_invite.go b/roomserver/internal/perform_invite.go index 2e6bcc8ec..65a713c65 100644 --- a/roomserver/internal/perform_invite.go +++ b/roomserver/internal/perform_invite.go @@ -143,15 +143,22 @@ func (r *RoomserverInternalAPI) PerformInvite( } } - unwrapped := event.Unwrap() - outputUpdates, err := updateToInviteMembership(updater, &unwrapped, nil, req.Event.RoomVersion) - if err != nil { - return fmt.Errorf("updateToInviteMembership: %w", err) - } - - if err = r.WriteOutputEvents(roomID, outputUpdates); err != nil { - return fmt.Errorf("r.WriteOutputEvents: %w", err) + // Send the invite event to the roomserver input stream. This will + // notify existing users in the room about the invite, update the + // membership table and ensure that the event is ready and available + // to use as an auth event when accepting the invite. + inputReq := &api.InputRoomEventsRequest{ + InputRoomEvents: []api.InputRoomEvent{ + { + Kind: api.KindNew, + Event: event, + AuthEventIDs: event.AuthEventIDs(), + SendAsServer: string(r.Cfg.Matrix.ServerName), + }, + }, } + inputRes := &api.InputRoomEventsResponse{} + _ = r.InputRoomEvents(ctx, inputReq, inputRes) succeeded = true return nil