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

Function SendOwnerInvite

federationapi/routing/new_func.go:165–242  ·  view source on GitHub ↗
(httpReq *http.Request, userAPI userapi.FederationUserAPI, cfg *config.FederationAPI, rsAPI roomserverAPI.FederationRoomserverAPI,
)

Source from the content-addressed store, hash-verified

163}
164
165func SendOwnerInvite(httpReq *http.Request, userAPI userapi.FederationUserAPI, cfg *config.FederationAPI, rsAPI roomserverAPI.FederationRoomserverAPI,
166) util.JSONResponse {
167 ctx := httpReq.Context()
168 req := inviteAsOwnerReq{}
169 resErr := httputil.UnmarshalJSONRequest(httpReq, &req)
170 if resErr != nil {
171 return *resErr
172 }
173 if req.RoomId == "" || req.TargetUserId == "" {
174 return util.JSONResponse{
175 Code: http.StatusBadRequest,
176 JSON: jsonerror.BadJSON("invalid params"),
177 }
178 }
179 groupOwner, err := new_db.GetGroupOwner(req.RoomId)
180 if err != nil {
181 return util.ErrorResponse(err)
182 }
183 var userPro userapi.QueryProfileResponse
184 err = userAPI.QueryProfile(ctx, &userapi.QueryProfileRequest{
185 req.TargetUserId,
186 }, &userPro)
187 if err != nil {
188 return util.ErrorResponse(err)
189 }
190 builder := gomatrixserverlib.EventBuilder{
191 Sender: groupOwner,
192 RoomID: req.RoomId,
193 Type: "m.room.member",
194 StateKey: &req.TargetUserId,
195 }
196 content := gomatrixserverlib.MemberContent{
197 Membership: gomatrixserverlib.Invite,
198 DisplayName: userPro.DisplayName,
199 AvatarURL: userPro.AvatarURL,
200 Reason: req.Reason,
201 IsDirect: false,
202 }
203 if err = builder.SetContent(content); err != nil {
204 return util.ErrorResponse(err)
205 }
206 event, err := eventutil.QueryAndBuildEvent(ctx, &builder, cfg.Matrix, time.Now(), rsAPI, nil)
207 if err == errMissingUserID {
208 return util.JSONResponse{
209 Code: http.StatusBadRequest,
210 JSON: jsonerror.BadJSON(err.Error()),
211 }
212 } else if err == eventutil.ErrRoomNoExists {
213 return util.JSONResponse{
214 Code: http.StatusNotFound,
215 JSON: jsonerror.NotFound(err.Error()),
216 }
217 } else if err != nil {
218 util.GetLogger(ctx).WithError(err).Error("buildMembershipEvent failed")
219 return jsonerror.InternalServerError()
220 }
221
222 var inviteRes roomserverAPI.PerformInviteResponse

Callers

nothing calls this directly

Calls 5

ContextMethod · 0.80
JSONResponseMethod · 0.80
QueryProfileMethod · 0.65
PerformInviteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected