From fdea86cdb93f641366e98cb7e9f8682a0a4f819f Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 22 Aug 2017 20:13:42 +0200 Subject: [PATCH 1/4] Add RespUserDisplayName --- responses.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/responses.go b/responses.go index 1b9b066..c729d5b 100644 --- a/responses.go +++ b/responses.go @@ -90,6 +90,11 @@ type RespUserInteractive struct { Error string `json:"error"` } +// RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +type RespUserDisplayName struct { + DisplayName string `json:"displayname"` +} + // HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName. func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool { for _, f := range r.Flows { From fc56cbf80a9ac901efe986dc2a1354fc767fab9a Mon Sep 17 00:00:00 2001 From: MTRNord Date: Tue, 22 Aug 2017 20:21:53 +0200 Subject: [PATCH 2/4] Add GetDisplayName() command --- client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client.go b/client.go index 8ff3247..6e369b0 100644 --- a/client.go +++ b/client.go @@ -387,6 +387,13 @@ func (cli *Client) JoinRoom(roomIDorAlias, serverName string, content interface{ return } +// GetDisplayName returns the display name of the user from the specified MXID. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +func (cli *Client) GetDisplayName(mxid string) (resp *RespUserDisplayName, err error) { + urlPath := cli.BuildURL("profile", mxid, "displayname") + _, err = cli.MakeRequest("GET", urlPath, nil, &resp) + return +} + // SetDisplayName sets the user's profile display name. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname func (cli *Client) SetDisplayName(displayName string) (err error) { urlPath := cli.BuildURL("profile", cli.UserID, "displayname") From 3e76370297409e43fab82db778d7d7a04f88990a Mon Sep 17 00:00:00 2001 From: MTRNord Date: Tue, 22 Aug 2017 21:41:15 +0200 Subject: [PATCH 3/4] Move method HasSingleStageFlow() back to the corresponding struct --- responses.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/responses.go b/responses.go index c729d5b..fe0eeb3 100644 --- a/responses.go +++ b/responses.go @@ -90,11 +90,6 @@ type RespUserInteractive struct { Error string `json:"error"` } -// RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname -type RespUserDisplayName struct { - DisplayName string `json:"displayname"` -} - // HasSingleStageFlow returns true if there exists at least 1 Flow with a single stage of stageName. func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool { for _, f := range r.Flows { @@ -105,6 +100,11 @@ func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool { return false } +// RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +type RespUserDisplayName struct { + DisplayName string `json:"displayname"` +} + // RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register type RespRegister struct { AccessToken string `json:"access_token"` From f6ce5f65b540987037fb27bf708fb41fdad86c38 Mon Sep 17 00:00:00 2001 From: MTRNord Date: Tue, 22 Aug 2017 21:44:21 +0200 Subject: [PATCH 4/4] Add helper function GetOwnDisplayName() --- client.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client.go b/client.go index 6e369b0..90a07c6 100644 --- a/client.go +++ b/client.go @@ -394,6 +394,13 @@ func (cli *Client) GetDisplayName(mxid string) (resp *RespUserDisplayName, err e return } +// GetOwnDisplayName returns the user's display name. See https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname +func (cli *Client) GetOwnDisplayName() (resp *RespUserDisplayName, err error) { + urlPath := cli.BuildURL("profile", cli.UserID, "displayname") + _, err = cli.MakeRequest("GET", urlPath, nil, &resp) + return +} + // SetDisplayName sets the user's profile display name. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname func (cli *Client) SetDisplayName(displayName string) (err error) { urlPath := cli.BuildURL("profile", cli.UserID, "displayname")