sendInvite sends an invitation to a user. Returns a JSONResponse and an error
( ctx context.Context, profileAPI userapi.ClientUserAPI, device *userapi.Device, roomID, userID, reason string, cfg *config.ClientAPI, rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI, evTime time.Time, )
| 239 | |
| 240 | // sendInvite sends an invitation to a user. Returns a JSONResponse and an error |
| 241 | func sendInvite( |
| 242 | ctx context.Context, |
| 243 | profileAPI userapi.ClientUserAPI, |
| 244 | device *userapi.Device, |
| 245 | roomID, userID, reason string, |
| 246 | cfg *config.ClientAPI, |
| 247 | rsAPI roomserverAPI.ClientRoomserverAPI, |
| 248 | asAPI appserviceAPI.AppServiceInternalAPI, evTime time.Time, |
| 249 | ) (util.JSONResponse, error) { |
| 250 | event, err := buildMembershipEvent( |
| 251 | ctx, userID, reason, profileAPI, device, "invite", |
| 252 | roomID, false, cfg, evTime, rsAPI, asAPI, |
| 253 | ) |
| 254 | if err == errMissingUserID { |
| 255 | return util.JSONResponse{ |
| 256 | Code: http.StatusBadRequest, |
| 257 | JSON: jsonerror.BadJSON(err.Error()), |
| 258 | }, err |
| 259 | } else if err == eventutil.ErrRoomNoExists { |
| 260 | return util.JSONResponse{ |
| 261 | Code: http.StatusNotFound, |
| 262 | JSON: jsonerror.NotFound(err.Error()), |
| 263 | }, err |
| 264 | } else if err != nil { |
| 265 | util.GetLogger(ctx).WithError(err).Error("buildMembershipEvent failed") |
| 266 | return jsonerror.InternalServerError(), err |
| 267 | } |
| 268 | |
| 269 | var inviteRes api.PerformInviteResponse |
| 270 | if err := rsAPI.PerformInvite(ctx, &api.PerformInviteRequest{ |
| 271 | Event: event, |
| 272 | InviteRoomState: nil, // ask the roomserver to draw up invite room state for us |
| 273 | RoomVersion: event.RoomVersion, |
| 274 | SendAsServer: string(cfg.Matrix.ServerName), |
| 275 | }, &inviteRes); err != nil { |
| 276 | util.GetLogger(ctx).WithError(err).Error("PerformInvite failed") |
| 277 | return util.JSONResponse{ |
| 278 | Code: http.StatusInternalServerError, |
| 279 | JSON: jsonerror.InternalServerError(), |
| 280 | }, err |
| 281 | } |
| 282 | if inviteRes.Error != nil { |
| 283 | return inviteRes.Error.JSONResponse(), inviteRes.Error |
| 284 | } |
| 285 | |
| 286 | return util.JSONResponse{ |
| 287 | Code: http.StatusOK, |
| 288 | JSON: struct{}{}, |
| 289 | }, nil |
| 290 | } |
| 291 | |
| 292 | func buildMembershipEvent( |
| 293 | ctx context.Context, |
no test coverage detected