sendToRemoteServer uses federation to send an invite provided by an identity server to a remote server in case the current server isn't in the room the invite is for. Returns an error if it couldn't get the server names to reach or if all of them responded with an error.
( ctx context.Context, inv invite, federation federationAPI.FederationClient, _ *config.FederationAPI, builder gomatrixserverlib.EventBuilder, )
| 340 | // Returns an error if it couldn't get the server names to reach or if all of |
| 341 | // them responded with an error. |
| 342 | func sendToRemoteServer( |
| 343 | ctx context.Context, inv invite, |
| 344 | federation federationAPI.FederationClient, _ *config.FederationAPI, |
| 345 | builder gomatrixserverlib.EventBuilder, |
| 346 | ) (err error) { |
| 347 | remoteServers := make([]gomatrixserverlib.ServerName, 2) |
| 348 | _, remoteServers[0], err = gomatrixserverlib.SplitID('@', inv.Sender) |
| 349 | if err != nil { |
| 350 | return |
| 351 | } |
| 352 | // Fallback to the room's server if the sender's domain is the same as |
| 353 | // the current server's |
| 354 | _, remoteServers[1], err = gomatrixserverlib.SplitID('!', inv.RoomID) |
| 355 | if err != nil { |
| 356 | return |
| 357 | } |
| 358 | |
| 359 | for _, server := range remoteServers { |
| 360 | err = federation.ExchangeThirdPartyInvite(ctx, server, builder) |
| 361 | if err == nil { |
| 362 | return |
| 363 | } |
| 364 | logrus.WithError(err).Warnf("failed to send 3PID invite via %s", server) |
| 365 | } |
| 366 | |
| 367 | return errors.New("failed to send 3PID invite via any server") |
| 368 | } |
| 369 | |
| 370 | // fillDisplayName looks in a list of auth events for a m.room.third_party_invite |
| 371 | // event with the state key matching a given m.room.member event's content's token. |
no test coverage detected