mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-11 08:53:11 -06:00
Getters for display name and avatar URL
This commit is contained in:
parent
2ca6b914bd
commit
a765352d16
|
|
@ -31,11 +31,11 @@ type profileResponse struct {
|
||||||
DisplayName string `json:"displayname"`
|
DisplayName string `json:"displayname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type avatarURLRequest struct {
|
type avatarURL struct {
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type displayNameRequest struct {
|
type displayName struct {
|
||||||
DisplayName string `json:"displayname"`
|
DisplayName string `json:"displayname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,8 +69,24 @@ func GetProfile(
|
||||||
func AvatarURL(
|
func AvatarURL(
|
||||||
req *http.Request, accountDB *accounts.Database, userID string,
|
req *http.Request, accountDB *accounts.Database, userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if req.Method == "PUT" {
|
if req.Method == "GET" {
|
||||||
var r avatarURLRequest
|
localpart := getLocalPart(userID)
|
||||||
|
profile, err := accountDB.GetProfileByLocalpart(localpart)
|
||||||
|
if err == nil {
|
||||||
|
res := avatarURL{
|
||||||
|
AvatarURL: profile.AvatarURL,
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 200,
|
||||||
|
JSON: res,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 500,
|
||||||
|
JSON: jsonerror.Unknown("Failed to load avatar URL"),
|
||||||
|
}
|
||||||
|
} else if req.Method == "PUT" {
|
||||||
|
var r avatarURL
|
||||||
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
|
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
@ -102,8 +118,24 @@ func AvatarURL(
|
||||||
func DisplayName(
|
func DisplayName(
|
||||||
req *http.Request, accountDB *accounts.Database, userID string,
|
req *http.Request, accountDB *accounts.Database, userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if req.Method == "PUT" {
|
if req.Method == "GET" {
|
||||||
var r displayNameRequest
|
localpart := getLocalPart(userID)
|
||||||
|
profile, err := accountDB.GetProfileByLocalpart(localpart)
|
||||||
|
if err == nil {
|
||||||
|
res := displayName{
|
||||||
|
DisplayName: profile.DisplayName,
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 200,
|
||||||
|
JSON: res,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 500,
|
||||||
|
JSON: jsonerror.Unknown("Failed to load display name"),
|
||||||
|
}
|
||||||
|
} else if req.Method == "PUT" {
|
||||||
|
var r displayName
|
||||||
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
|
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue