aboutsummaryrefslogtreecommitdiff
path: root/clientapi/routing/membership.go
diff options
context:
space:
mode:
authorS7evinK <2353100+S7evinK@users.noreply.github.com>2022-02-18 16:05:03 +0100
committerGitHub <noreply@github.com>2022-02-18 16:05:03 +0100
commit002429c9e24cc746e0929b41eccbe429f89a6e1f (patch)
tree217eaea280343f46c61868a694d75fccd8fe66af /clientapi/routing/membership.go
parentdbded875257703eb63c8eb8af8d47d74c811642f (diff)
Implement server notices (#2180)
* Add server_notices config * Disallow rejecting "server notice" invites * Update config * Slightly refactor sendEvent and CreateRoom so it can be reused * Implement unspecced server notices * Validate the request * Set the user api when starting * Rename function/variables * Update comments * Update config * Set the avatar on account creation * Update test * Only create the account when starting Only add routes if sever notices are enabled * Use reserver username Check that we actually got roomData * Add check for admin account Enable server notices for CI Return same values as Synapse * Add custom error for rejecting server notice invite * Move building an invite to it's own function, for reusability * Don't create new rooms, use the existing one (follow Synapse behavior) Co-authored-by: kegsay <kegan@matrix.org>
Diffstat (limited to 'clientapi/routing/membership.go')
-rw-r--r--clientapi/routing/membership.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go
index 11223924..ffe8da13 100644
--- a/clientapi/routing/membership.go
+++ b/clientapi/routing/membership.go
@@ -226,27 +226,42 @@ func SendInvite(
}
}
+ // We already received the return value, so no need to check for an error here.
+ response, _ := sendInvite(req.Context(), accountDB, device, roomID, body.UserID, body.Reason, cfg, rsAPI, asAPI, evTime)
+ return response
+}
+
+// sendInvite sends an invitation to a user. Returns a JSONResponse and an error
+func sendInvite(
+ ctx context.Context,
+ accountDB userdb.Database,
+ device *userapi.Device,
+ roomID, userID, reason string,
+ cfg *config.ClientAPI,
+ rsAPI roomserverAPI.RoomserverInternalAPI,
+ asAPI appserviceAPI.AppServiceQueryAPI, evTime time.Time,
+) (util.JSONResponse, error) {
event, err := buildMembershipEvent(
- req.Context(), body.UserID, body.Reason, accountDB, device, "invite",
+ ctx, userID, reason, accountDB, device, "invite",
roomID, false, cfg, evTime, rsAPI, asAPI,
)
if err == errMissingUserID {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON(err.Error()),
- }
+ }, err
} else if err == eventutil.ErrRoomNoExists {
return util.JSONResponse{
Code: http.StatusNotFound,
JSON: jsonerror.NotFound(err.Error()),
- }
+ }, err
} else if err != nil {
- util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvent failed")
- return jsonerror.InternalServerError()
+ util.GetLogger(ctx).WithError(err).Error("buildMembershipEvent failed")
+ return jsonerror.InternalServerError(), err
}
err = roomserverAPI.SendInvite(
- req.Context(), rsAPI,
+ ctx, rsAPI,
event,
nil, // ask the roomserver to draw up invite room state for us
cfg.Matrix.ServerName,
@@ -254,18 +269,18 @@ func SendInvite(
)
switch e := err.(type) {
case *roomserverAPI.PerformError:
- return e.JSONResponse()
+ return e.JSONResponse(), err
case nil:
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
- }
+ }, nil
default:
- util.GetLogger(req.Context()).WithError(err).Error("roomserverAPI.SendInvite failed")
+ util.GetLogger(ctx).WithError(err).Error("roomserverAPI.SendInvite failed")
return util.JSONResponse{
Code: http.StatusInternalServerError,
JSON: jsonerror.InternalServerError(),
- }
+ }, err
}
}