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

Method performJoinUsingServer

federationapi/internal/perform.go:136–284  ·  view source on GitHub ↗
(
	ctx context.Context,
	roomID, userID string,
	content map[string]interface{},
	serverName gomatrixserverlib.ServerName,
	supportedVersions []gomatrixserverlib.RoomVersion,
)

Source from the content-addressed store, hash-verified

134}
135
136func (r *FederationInternalAPI) performJoinUsingServer(
137 ctx context.Context,
138 roomID, userID string,
139 content map[string]interface{},
140 serverName gomatrixserverlib.ServerName,
141 supportedVersions []gomatrixserverlib.RoomVersion,
142) error {
143 // Try to perform a make_join using the information supplied in the
144 // request.
145 respMakeJoin, err := r.federation.MakeJoin(
146 ctx,
147 serverName,
148 roomID,
149 userID,
150 supportedVersions,
151 )
152 if err != nil {
153 // TODO: Check if the user was not allowed to join the room.
154 r.statistics.ForServer(serverName).Failure()
155 return fmt.Errorf("r.federation.MakeJoin: %w", err)
156 }
157 r.statistics.ForServer(serverName).Success()
158
159 // Set all the fields to be what they should be, this should be a no-op
160 // but it's possible that the remote server returned us something "odd"
161 respMakeJoin.JoinEvent.Type = gomatrixserverlib.MRoomMember
162 respMakeJoin.JoinEvent.Sender = userID
163 respMakeJoin.JoinEvent.StateKey = &userID
164 respMakeJoin.JoinEvent.RoomID = roomID
165 respMakeJoin.JoinEvent.Redacts = ""
166 if content == nil {
167 content = map[string]interface{}{}
168 }
169 _ = json.Unmarshal(respMakeJoin.JoinEvent.Content, &content)
170 content["membership"] = gomatrixserverlib.Join
171 if err = respMakeJoin.JoinEvent.SetContent(content); err != nil {
172 return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err)
173 }
174 if err = respMakeJoin.JoinEvent.SetUnsigned(struct{}{}); err != nil {
175 return fmt.Errorf("respMakeJoin.JoinEvent.SetUnsigned: %w", err)
176 }
177
178 // Work out if we support the room version that has been supplied in
179 // the make_join response.
180 // "If not provided, the room version is assumed to be either "1" or "2"."
181 // https://matrix.org/docs/spec/server_server/unstable#get-matrix-federation-v1-make-join-roomid-userid
182 if respMakeJoin.RoomVersion == "" {
183 respMakeJoin.RoomVersion = setDefaultRoomVersionFromJoinEvent(respMakeJoin.JoinEvent)
184 }
185 if _, err = respMakeJoin.RoomVersion.EventFormat(); err != nil {
186 return fmt.Errorf("respMakeJoin.RoomVersion.EventFormat: %w", err)
187 }
188
189 // Build the join event.
190 event, err := respMakeJoin.JoinEvent.Build(
191 time.Now(),
192 r.cfg.Matrix.ServerName,
193 r.cfg.Matrix.KeyID,

Callers 1

PerformJoinMethod · 0.95

Calls 10

sanityCheckAuthChainFunction · 0.85
federatedAuthProviderFunction · 0.85
MakeJoinMethod · 0.65
SendJoinMethod · 0.65
UpdateRoomMethod · 0.65
FailureMethod · 0.45
ForServerMethod · 0.45
SuccessMethod · 0.45

Tested by

no test coverage detected