mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Reflow forced federated joins
This commit is contained in:
parent
d96780c376
commit
36862bc436
|
|
@ -183,33 +183,30 @@ func (r *Joiner) performJoinRoomByID(
|
||||||
return "", fmt.Errorf("eb.SetContent: %w", err)
|
return "", fmt.Errorf("eb.SetContent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work out if this should be a federated join. This will be true
|
// Force a federated join if we aren't in the room and we've been
|
||||||
// if our server isn't joined to this room already, or in response
|
// given some server names to try joining by.
|
||||||
// to an existing invite from a federated server. If it is then we
|
|
||||||
// avoid the situation where we might think we know about a room
|
|
||||||
// in the following section but don't know the latest state as all
|
|
||||||
// of our users have left.
|
|
||||||
serverInRoom, _ := helpers.IsServerCurrentlyInRoom(ctx, r.DB, r.ServerName, req.RoomIDOrAlias)
|
serverInRoom, _ := helpers.IsServerCurrentlyInRoom(ctx, r.DB, r.ServerName, req.RoomIDOrAlias)
|
||||||
isInvitePending, inviteSender, _, err := helpers.IsInvitePending(ctx, r.DB, req.RoomIDOrAlias, req.UserID)
|
forceFederatedJoin := len(req.ServerNames) > 0 && !serverInRoom
|
||||||
if !serverInRoom || (err == nil && isInvitePending) {
|
|
||||||
if err == nil && inviteSender != "" {
|
|
||||||
// Check if there's an invite pending.
|
|
||||||
_, inviterDomain, ierr := gomatrixserverlib.SplitID('@', inviteSender)
|
|
||||||
if ierr != nil {
|
|
||||||
return "", fmt.Errorf("gomatrixserverlib.SplitID: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that the domain isn't ours. If it's local then we don't
|
// Force a federated join if we're dealing with a pending invite
|
||||||
// need to do anything as our own copy of the room state will be
|
// and we aren't in the room.
|
||||||
// up-to-date.
|
isInvitePending, inviteSender, _, err := helpers.IsInvitePending(ctx, r.DB, req.RoomIDOrAlias, req.UserID)
|
||||||
if inviterDomain != r.Cfg.Matrix.ServerName {
|
if err == nil && isInvitePending {
|
||||||
// Add the server of the person who invited us to the server list,
|
forceFederatedJoin = true
|
||||||
// as they should be a fairly good bet.
|
_, inviterDomain, ierr := gomatrixserverlib.SplitID('@', inviteSender)
|
||||||
req.ServerNames = append(req.ServerNames, inviterDomain)
|
if ierr != nil {
|
||||||
}
|
return "", fmt.Errorf("gomatrixserverlib.SplitID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a federated room join.
|
// If we were invited by someone from another server then we can
|
||||||
|
// assume they are in the room so we can join via them.
|
||||||
|
if inviterDomain != r.Cfg.Matrix.ServerName {
|
||||||
|
req.ServerNames = append(req.ServerNames, inviterDomain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we should do a forced federated join then do that.
|
||||||
|
if forceFederatedJoin {
|
||||||
return req.RoomIDOrAlias, r.performFederatedJoinRoomByID(ctx, req)
|
return req.RoomIDOrAlias, r.performFederatedJoinRoomByID(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue