MCPcopy Create free account
hub / github.com/daodst/chat / PerformJoin

Method PerformJoin

federationapi/internal/perform.go:47–134  ·  view source on GitHub ↗

PerformJoin implements api.FederationInternalAPI

(
	ctx context.Context,
	request *api.PerformJoinRequest,
	response *api.PerformJoinResponse,
)

Source from the content-addressed store, hash-verified

45
46// PerformJoin implements api.FederationInternalAPI
47func (r *FederationInternalAPI) PerformJoin(
48 ctx context.Context,
49 request *api.PerformJoinRequest,
50 response *api.PerformJoinResponse,
51) {
52 // Check that a join isn't already in progress for this user/room.
53 j := federatedJoin{request.UserID, request.RoomID}
54 if _, found := r.joins.Load(j); found {
55 response.LastError = &gomatrix.HTTPError{
56 Code: 429,
57 Message: `{
58 "errcode": "M_LIMIT_EXCEEDED",
59 "error": "There is already a federated join to this room in progress. Please wait for it to finish."
60 }`, // TODO: Why do none of our error types play nicely with each other?
61 }
62 return
63 }
64 r.joins.Store(j, nil)
65 defer r.joins.Delete(j)
66
67 // Look up the supported room versions.
68 var supportedVersions []gomatrixserverlib.RoomVersion
69 for version := range version.SupportedRoomVersions() {
70 supportedVersions = append(supportedVersions, version)
71 }
72
73 // Deduplicate the server names we were provided but keep the ordering
74 // as this encodes useful information about which servers are most likely
75 // to respond.
76 seenSet := make(map[gomatrixserverlib.ServerName]bool)
77 var uniqueList []gomatrixserverlib.ServerName
78 for _, srv := range request.ServerNames {
79 if seenSet[srv] || srv == r.cfg.Matrix.ServerName {
80 continue
81 }
82 seenSet[srv] = true
83 uniqueList = append(uniqueList, srv)
84 }
85 request.ServerNames = uniqueList
86
87 // Try each server that we were provided until we land on one that
88 // successfully completes the make-join send-join dance.
89 var lastErr error
90 for _, serverName := range request.ServerNames {
91 if err := r.performJoinUsingServer(
92 ctx,
93 request.RoomID,
94 request.UserID,
95 request.Content,
96 serverName,
97 supportedVersions,
98 ); err != nil {
99 logrus.WithError(err).WithFields(logrus.Fields{
100 "server_name": serverName,
101 "room_id": request.RoomID,
102 }).Warnf("Failed to join room through server")
103 lastErr = err
104 continue

Callers

nothing calls this directly

Calls 4

LoadMethod · 0.80
DeleteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected