diff --git a/src/github.com/matrix-org/dendrite/clientapi/jsonerror/jsonerror.go b/src/github.com/matrix-org/dendrite/clientapi/jsonerror/jsonerror.go index 2ba9db328..07fe90304 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/jsonerror/jsonerror.go +++ b/src/github.com/matrix-org/dendrite/clientapi/jsonerror/jsonerror.go @@ -73,10 +73,10 @@ func MissingArgument(msg string) *MatrixError { return &MatrixError{"M_MISSING_ARGUMENT", msg} } -// InvalidArgumentBody is an error when the client tries to provide an -// invalid body under a valid argument -func InvalidArgumentBody(msg string) *MatrixError { - return &MatrixError{"M_INVALID_ARGUMENT_BODY", msg} +// InvalidArgumentValue is an error when the client tries to provide an +// invalid value for a valid argument +func InvalidArgumentValue(msg string) *MatrixError { + return &MatrixError{"M_INVALID_ARGUMENT_VALUE", msg} } // MissingToken is an error when the client tries to access a resource which diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go index da47451fa..1403a8292 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go @@ -31,19 +31,6 @@ import ( "github.com/matrix-org/util" ) -type profileResponse struct { - AvatarURL string `json:"avatar_url"` - DisplayName string `json:"displayname"` -} - -type avatarURL struct { - AvatarURL string `json:"avatar_url"` -} - -type displayName struct { - DisplayName string `json:"displayname"` -} - // GetProfile implements GET /profile/{userID} func GetProfile( req *http.Request, accountDB *accounts.Database, userID string, @@ -63,7 +50,7 @@ func GetProfile( if err != nil { return httputil.LogThenError(req, err) } - res := profileResponse{ + res := common.ProfileResponse{ AvatarURL: profile.AvatarURL, DisplayName: profile.DisplayName, } @@ -86,7 +73,7 @@ func GetAvatarURL( if err != nil { return httputil.LogThenError(req, err) } - res := avatarURL{ + res := common.AvatarURL{ AvatarURL: profile.AvatarURL, } return util.JSONResponse{ @@ -110,7 +97,7 @@ func SetAvatarURL( changedKey := "avatar_url" - var r avatarURL + var r common.AvatarURL if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { return *resErr } @@ -178,7 +165,7 @@ func GetDisplayName( if err != nil { return httputil.LogThenError(req, err) } - res := displayName{ + res := common.DisplayName{ DisplayName: profile.DisplayName, } return util.JSONResponse{ @@ -202,7 +189,7 @@ func SetDisplayName( changedKey := "displayname" - var r displayName + var r common.DisplayName if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { return *resErr } diff --git a/src/github.com/matrix-org/dendrite/common/types.go b/src/github.com/matrix-org/dendrite/common/types.go index 471a2f30b..d8c5c5a7e 100644 --- a/src/github.com/matrix-org/dendrite/common/types.go +++ b/src/github.com/matrix-org/dendrite/common/types.go @@ -20,3 +20,19 @@ type AccountData struct { RoomID string `json:"room_id"` Type string `json:"type"` } + +// ProfileResponse is a struct containing all known user profile data +type ProfileResponse struct { + AvatarURL string `json:"avatar_url"` + DisplayName string `json:"displayname"` +} + +// AvatarURL is a struct containing only the URL to a user's avatar +type AvatarURL struct { + AvatarURL string `json:"avatar_url"` +} + +// DisplayName is a struct containing only a user's display name +type DisplayName struct { + DisplayName string `json:"displayname"` +} diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/profile.go b/src/github.com/matrix-org/dendrite/federationapi/routing/profile.go index 04ed99657..67703931e 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/profile.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/profile.go @@ -20,24 +20,12 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" + "github.com/matrix-org/dendrite/common" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) -type profileResponse struct { - AvatarURL string `json:"avatar_url"` - DisplayName string `json:"displayname"` -} - -type avatarURL struct { - AvatarURL string `json:"avatar_url"` -} - -type displayName struct { - DisplayName string `json:"displayname"` -} - -// GetProfile implements /_matrix/federation/v1/query/profile +// GetProfile implements GET /_matrix/federation/v1/query/profile func GetProfile( httpReq *http.Request, accountDB *accounts.Database, @@ -68,19 +56,19 @@ func GetProfile( if field != "" { switch field { case "displayname": - res = displayName{ + res = common.DisplayName{ profile.DisplayName, } case "avatar_url": - res = avatarURL{ + res = common.AvatarURL{ profile.AvatarURL, } default: code = 400 - res = jsonerror.InvalidArgumentBody("The request body did not contain allowed values of argument 'field'. Allowed: 'avatar_url', 'displayname'.") + res = jsonerror.InvalidArgumentValue("The request body did not contain an allowed value of argument 'field'. Allowed values are either: 'avatar_url', 'displayname'.") } } else { - res = profileResponse{ + res = common.ProfileResponse{ profile.AvatarURL, profile.DisplayName, }