mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Properly export profile-related structs and fix wording
Signed-off-by: Andrew (anoa) <anoa@openmailbox.org>
This commit is contained in:
parent
d39bcb005e
commit
3f4cf27b5c
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue