From 2d91fe0df174390638dc45a7289d7dd8ee71d3e0 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 15 Nov 2021 16:03:06 +0000 Subject: [PATCH] Try to find new servers to federated join via --- roomserver/internal/perform/perform_join.go | 31 +++++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go index 60fa26d1..441ecd53 100644 --- a/roomserver/internal/perform/perform_join.go +++ b/roomserver/internal/perform/perform_join.go @@ -259,10 +259,35 @@ func (r *Joiner) performJoinRoomByID( } } if !success { - return "", "", &api.PerformError{ - Code: rsAPI.PerformErrorBadRequest, - Msg: fmt.Sprintf("Can't satisfy restricted join to room %q locally", req.RoomIDOrAlias), + queryReq := &api.QueryMembershipsForRoomRequest{} + queryRes := &api.QueryMembershipsForRoomResponse{} + 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 } }