Don't send our membership event twice

This commit is contained in:
Neil Alexander 2020-09-09 15:13:34 +01:00
parent f1b76541ea
commit 746e105888
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -108,6 +108,7 @@ func (r *FederationSenderInternalAPI) PerformJoin(
) )
} }
// nolint:gocyclo
func (r *FederationSenderInternalAPI) performJoinUsingServer( func (r *FederationSenderInternalAPI) performJoinUsingServer(
ctx context.Context, ctx context.Context,
roomID, userID string, roomID, userID string,
@ -192,6 +193,19 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
return fmt.Errorf("joinCtx.CheckSendJoinResponse: %w", err) return fmt.Errorf("joinCtx.CheckSendJoinResponse: %w", err)
} }
// It's possible that the remote server has included our new
// membership event in the room state in the send_join response,
// but if that's the case, then we'll get a duplicate state block
// error if we try to send that along with our own copy of the
// event. The simple way around this is just to prune the event
// from the state if we find it.
for i, ev := range respState.StateEvents {
if ev.Type() == gomatrixserverlib.MRoomMember && ev.StateKeyEquals(userID) {
respState.StateEvents = append(respState.StateEvents[i:], respState.StateEvents[:i+1]...)
break
}
}
// If we successfully performed a send_join above then the other // If we successfully performed a send_join above then the other
// server now thinks we're a part of the room. Send the newly // server now thinks we're a part of the room. Send the newly
// returned state to the roomserver to update our local view. // returned state to the roomserver to update our local view.