mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-03 22:08:04 +00:00 
			
		
		
		
	Status functions for interacting with the r0.6.0 presence/status API
This commit is contained in:
		
							parent
							
								
									e5578b12c7
								
							
						
					
					
						commit
						6166ab33b3
					
				
					 2 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										23
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -486,6 +486,29 @@ func (cli *Client) SetAvatarURL(url string) error {
 | 
			
		|||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetStatus returns the status of the user from the specified MXID. See https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status
 | 
			
		||||
func (cli *Client) GetStatus(mxid string) (resp *RespUserStatus, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("presence", mxid, "status")
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetOwnStatus returns the user's status. See https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status
 | 
			
		||||
func (cli *Client) GetOwnStatus() (resp *RespUserStatus, err error) {
 | 
			
		||||
	return cli.GetStatus(cli.UserID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetStatus sets the user's status. See https://matrix.org/docs/spec/client_server/r0.6.0#put-matrix-client-r0-presence-userid-status
 | 
			
		||||
func (cli *Client) SetStatus(presence, status string) (err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("presence", cli.UserID, "status")
 | 
			
		||||
	s := struct {
 | 
			
		||||
		Presence  string `json:"presence"`
 | 
			
		||||
		StatusMsg string `json:"status_msg"`
 | 
			
		||||
	}{presence, status}
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, &s, nil)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,6 +113,14 @@ type RespUserDisplayName struct {
 | 
			
		|||
	DisplayName string `json:"displayname"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespUserStatus is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-presence-userid-status
 | 
			
		||||
type RespUserStatus struct {
 | 
			
		||||
	Presence        string `json:"presence"`
 | 
			
		||||
	StatusMsg       string `json:"status_msg"`
 | 
			
		||||
	lastActiveAgo   int    `json:"last_active_ago"`
 | 
			
		||||
	currentlyActive bool   `json:"currently_active"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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"`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue