Nope, that didn't work

This commit is contained in:
Neil Alexander 2020-08-17 15:56:36 +01:00
parent 86b5ac35fb
commit 8952c5a065
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api" federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/state"
"github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/roomserver/storage"
@ -55,19 +54,12 @@ func (r *RoomserverInternalAPI) PerformInvite(
} }
} }
updater, err := r.DB.MembershipUpdater(ctx, roomID, targetUserID, isTargetLocal, req.RoomVersion) var isAlreadyJoined bool
if err != nil { roomNID, err := r.DB.RoomNID(ctx, roomID)
return fmt.Errorf("r.DB.MembershipUpdater: %w", err) if err == nil {
_, isAlreadyJoined, _ = r.DB.GetMembership(ctx, roomNID, "")
} }
succeeded := false if isAlreadyJoined {
defer func() {
txerr := sqlutil.EndTransaction(updater, &succeeded)
if err == nil && txerr != nil {
err = txerr
}
}()
if updater.IsJoin() {
// If the user is joined to the room then that takes precedence over this // If the user is joined to the room then that takes precedence over this
// invite event. It makes little sense to move a user that is already // invite event. It makes little sense to move a user that is already
// joined to the room into the invite state. // joined to the room into the invite state.
@ -146,7 +138,10 @@ func (r *RoomserverInternalAPI) PerformInvite(
// Send the invite event to the roomserver input stream. This will // Send the invite event to the roomserver input stream. This will
// notify existing users in the room about the invite, update the // notify existing users in the room about the invite, update the
// membership table and ensure that the event is ready and available // membership table and ensure that the event is ready and available
// to use as an auth event when accepting the invite. // to use as an auth event when accepting the invite. We don't
// check the return value here because it may be possible that we
// don't know about this room yet if we received the invite over
// federation.
inputReq := &api.InputRoomEventsRequest{ inputReq := &api.InputRoomEventsRequest{
InputRoomEvents: []api.InputRoomEvent{ InputRoomEvents: []api.InputRoomEvent{
{ {
@ -158,12 +153,8 @@ func (r *RoomserverInternalAPI) PerformInvite(
}, },
} }
inputRes := &api.InputRoomEventsResponse{} inputRes := &api.InputRoomEventsResponse{}
if err := r.InputRoomEvents(context.Background(), inputReq, inputRes); isOriginLocal && err != nil { go r.InputRoomEvents(context.Background(), inputReq, inputRes) // nolint:errcheck
log.WithError(err).WithField("event_id", event.EventID()).Error("r.InputRoomEvents failed")
return fmt.Errorf("r.InputRoomEvents: %w", err)
}
succeeded = true
return nil return nil
} }