1
0
Fork 0
mirror of https://github.com/matrix-org/gomatrix synced 2025-05-12 10:41:44 +00:00

Add function to set a users' avatar

This commit is contained in:
Richard Lewis 2017-02-15 22:10:04 +00:00
parent aa984fcabc
commit 4d75d81067
2 changed files with 39 additions and 11 deletions

View file

@ -403,18 +403,37 @@ func (cli *Client) GetAvatarURL() (url string, err error) {
s := struct {
AvatarURL string `json:"avatar_url"`
}{}
res, err := cli.MakeRequest("GET", urlPath, &s, nil)
// res, err := cli.MakeRequest("GET", urlPath, nil, &s)
_, err = cli.MakeRequest("GET", urlPath, nil, &s)
if err != nil {
return "", err
}
if err = json.Unmarshal(res, &s); err != nil {
return "", err
}
// if err = json.Unmarshal(res, &s); err != nil {
// return "", err
// }
return s.AvatarURL, nil
}
// SetAvatarURL sets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url
func (cli *Client) SetAvatarURL(url string) (err error) {
urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url")
s := struct {
AvatarURL string `json:"avatar_url"`
}{url}
res, err := cli.MakeRequest("PUT", urlPath, &s, nil)
if err != nil {
return err
}
if err = json.Unmarshal(res, &s); err != nil {
return err
}
return nil
}
// SendMessageEvent sends a message event into a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
// contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.
func (cli *Client) SendMessageEvent(roomID string, eventType string, contentJSON interface{}) (resp *RespSendEvent, err error) {