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

Function PerformJoinRoomForSpecUser

clientapi/userutil/userutil.go:56–90  ·  view source on GitHub ↗
(ctx context.Context, roomID string, invitee string, profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI)

Source from the content-addressed store, hash-verified

54 return fmt.Sprintf("@%s:%s", localpart, string(server))
55}
56func PerformJoinRoomForSpecUser(ctx context.Context, roomID string, invitee string, profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI) util.JSONResponse {
57 // Prepare to ask the roomserver to perform the room join.
58 joinReq := roomserverAPI.PerformJoinRequest{
59 RoomIDOrAlias: roomID,
60 UserID: invitee,
61 Content: map[string]interface{}{},
62 }
63 joinRes := roomserverAPI.PerformJoinResponse{}
64 // Request our profile content to populate the request content with.
65 res := &api.QueryProfileResponse{}
66 err := profileAPI.QueryProfile(ctx, &api.QueryProfileRequest{UserID: invitee}, res)
67 if err != nil || !res.UserExists {
68 if !res.UserExists {
69 util.GetLogger(ctx).Error("Unable to query user profile, no profile found.")
70 return util.JSONResponse{
71 Code: http.StatusInternalServerError,
72 JSON: jsonerror.Unknown("Unable to query user profile, no profile found."),
73 }
74 }
75
76 util.GetLogger(ctx).WithError(err).Error("UserProfileAPI.QueryProfile failed")
77 } else {
78 joinReq.Content["displayname"] = res.DisplayName
79 joinReq.Content["avatar_url"] = res.AvatarURL
80 }
81 // Ask the roomserver to perform the join.
82 rsAPI.PerformJoin(ctx, &joinReq, &joinRes)
83 if joinRes.Error != nil {
84 return joinRes.Error.JSONResponse()
85 }
86 return util.JSONResponse{
87 Code: 200,
88 JSON: "ok",
89 }
90}

Callers

nothing calls this directly

Calls 4

JSONResponseMethod · 0.80
QueryProfileMethod · 0.65
PerformJoinMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected