Try to find new servers to federated join via

This commit is contained in:
Neil Alexander 2021-11-15 16:03:06 +00:00
parent f7c3f75e48
commit 2d91fe0df1
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -259,10 +259,35 @@ func (r *Joiner) performJoinRoomByID(
} }
} }
if !success { if !success {
return "", "", &api.PerformError{ queryReq := &api.QueryMembershipsForRoomRequest{}
Code: rsAPI.PerformErrorBadRequest, queryRes := &api.QueryMembershipsForRoomResponse{}
Msg: fmt.Sprintf("Can't satisfy restricted join to room %q locally", req.RoomIDOrAlias), if err = r.RSAPI.QueryMembershipsForRoom(ctx, queryReq, queryRes); err != nil {
return "", "", &api.PerformError{
Code: rsAPI.PerformErrorBadRequest,
Msg: fmt.Sprintf("Can't satisfy restricted join to room %q locally: %s", req.RoomIDOrAlias, err),
}
} }
var serverName gomatrixserverlib.ServerName
joinEvents:
for _, q := range queryRes.JoinEvents {
_, serverName, err = gomatrixserverlib.SplitID('@', *q.StateKey)
if err != nil {
continue
}
for _, s := range req.ServerNames {
if s == r.Cfg.Matrix.ServerName {
continue
}
if s == serverName {
continue joinEvents
}
}
req.ServerNames = append(req.ServerNames, serverName)
}
joinedVia, err = r.performFederatedJoinRoomByID(ctx, req)
return req.RoomIDOrAlias, joinedVia, err
} }
} }