mirror of
				https://github.com/matrix-org/gomatrix
				synced 2025-11-04 06:18:05 +00:00 
			
		
		
		
	Merge branch 'master' of github.com:kanopeld/gomatrix into kanopeld/room-aliases
This commit is contained in:
		
						commit
						9b894c66e2
					
				
					 13 changed files with 5242 additions and 82 deletions
				
			
		
							
								
								
									
										6
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -26,3 +26,9 @@ _testmain.go
 | 
			
		|||
 | 
			
		||||
# test editor files
 | 
			
		||||
*.swp
 | 
			
		||||
 | 
			
		||||
# Jetbrains ide files
 | 
			
		||||
.idea
 | 
			
		||||
 | 
			
		||||
# VsCode files
 | 
			
		||||
.vscode
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										118
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										118
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -187,16 +187,30 @@ func (cli *Client) StopSync() {
 | 
			
		|||
func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) error {
 | 
			
		||||
	var req *http.Request
 | 
			
		||||
	var err error
 | 
			
		||||
	var body io.Reader = nil
 | 
			
		||||
 | 
			
		||||
	if reqBody != nil {
 | 
			
		||||
		buf := new(bytes.Buffer)
 | 
			
		||||
		if err := json.NewEncoder(buf).Encode(reqBody); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		if marshaller, ok := reqBody.(json.Marshaler); ok {
 | 
			
		||||
			var data []byte
 | 
			
		||||
			data, err = marshaller.MarshalJSON()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			_, err = buf.Write(data)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			if err = json.NewEncoder(buf).Encode(reqBody); err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		req, err = http.NewRequest(method, httpURL, buf)
 | 
			
		||||
	} else {
 | 
			
		||||
		req, err = http.NewRequest(method, httpURL, nil)
 | 
			
		||||
		body = buf
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	req, err = http.NewRequest(method, httpURL, body)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -242,6 +256,18 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if resBody != nil && res.Body != nil {
 | 
			
		||||
		if unmarshaller, ok := resBody.(json.Unmarshaler); ok {
 | 
			
		||||
			var data []byte
 | 
			
		||||
			data, err = ioutil.ReadAll(res.Body)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			err = unmarshaller.UnmarshalJSON(data)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		return json.NewDecoder(res.Body).Decode(&resBody)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -251,7 +277,7 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
 | 
			
		|||
// CreateFilter makes an HTTP request according to http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter
 | 
			
		||||
func (cli *Client) CreateFilter(filter json.RawMessage) (resp *RespCreateFilter, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("user", cli.UserID, "filter")
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, &filter, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, &filter, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -273,12 +299,12 @@ func (cli *Client) SyncRequest(timeout int, since, filterID string, fullState bo
 | 
			
		|||
		query["full_state"] = "true"
 | 
			
		||||
	}
 | 
			
		||||
	urlPath := cli.BuildURLWithQuery([]string{"sync"}, query)
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (cli *Client) register(u string, req *ReqRegister) (resp *RespRegister, uiaResp *RespUserInteractive, err error) {
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		httpErr, ok := err.(HTTPError)
 | 
			
		||||
		if !ok { // network error
 | 
			
		||||
| 
						 | 
				
			
			@ -353,7 +379,7 @@ func (cli *Client) RegisterDummy(req *ReqRegister) (*RespRegister, error) {
 | 
			
		|||
// This does not set credentials on this client instance. See SetCredentials() instead.
 | 
			
		||||
func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("login")
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -361,7 +387,7 @@ func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) {
 | 
			
		|||
// This does not clear the credentials from the client instance. See ClearCredentials() instead.
 | 
			
		||||
func (cli *Client) Logout() (resp *RespLogout, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("logout")
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -369,14 +395,14 @@ func (cli *Client) Logout() (resp *RespLogout, err error) {
 | 
			
		|||
// This does not clear the credentials from the client instance. See ClearCredentails() instead.
 | 
			
		||||
func (cli *Client) LogoutAll() (resp *RespLogoutAll, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("logout/all")
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Versions returns the list of supported Matrix versions on this homeserver. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions
 | 
			
		||||
func (cli *Client) Versions() (resp *RespVersions, err error) {
 | 
			
		||||
	urlPath := cli.BuildBaseURL("_matrix", "client", "versions")
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -395,7 +421,7 @@ func (cli *Client) PublicRooms(limit int, since string, server string) (resp *Re
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	urlPath := cli.BuildURLWithQuery([]string{"publicRooms"}, args)
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -423,7 +449,7 @@ func (cli *Client) PublicRoomsFiltered(limit int, since string, server string, f
 | 
			
		|||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, content, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, content, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -440,21 +466,21 @@ func (cli *Client) JoinRoom(roomIDorAlias, serverName string, content interface{
 | 
			
		|||
	} else {
 | 
			
		||||
		urlPath = cli.BuildURL("join", roomIDorAlias)
 | 
			
		||||
	}
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, content, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, content, &resp)
 | 
			
		||||
	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)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	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)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -464,7 +490,7 @@ func (cli *Client) SetDisplayName(displayName string) (err error) {
 | 
			
		|||
	s := struct {
 | 
			
		||||
		DisplayName string `json:"displayname"`
 | 
			
		||||
	}{displayName}
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, &s, nil)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, urlPath, &s, nil)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -475,7 +501,7 @@ func (cli *Client) GetAvatarURL() (string, error) {
 | 
			
		|||
		AvatarURL string `json:"avatar_url"`
 | 
			
		||||
	}{}
 | 
			
		||||
 | 
			
		||||
	err := cli.MakeRequest("GET", urlPath, nil, &s)
 | 
			
		||||
	err := cli.MakeRequest(http.MethodGet, urlPath, nil, &s)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -489,7 +515,7 @@ func (cli *Client) SetAvatarURL(url string) error {
 | 
			
		|||
	s := struct {
 | 
			
		||||
		AvatarURL string `json:"avatar_url"`
 | 
			
		||||
	}{url}
 | 
			
		||||
	err := cli.MakeRequest("PUT", urlPath, &s, nil)
 | 
			
		||||
	err := cli.MakeRequest(http.MethodPut, urlPath, &s, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +526,7 @@ func (cli *Client) SetAvatarURL(url string) error {
 | 
			
		|||
// 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)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -516,7 +542,7 @@ func (cli *Client) SetStatus(presence, status string) (err error) {
 | 
			
		|||
		Presence  string `json:"presence"`
 | 
			
		||||
		StatusMsg string `json:"status_msg"`
 | 
			
		||||
	}{presence, status}
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, &s, nil)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, urlPath, &s, nil)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -525,7 +551,7 @@ func (cli *Client) SetStatus(presence, status string) (err error) {
 | 
			
		|||
func (cli *Client) SendMessageEvent(roomID string, eventType string, contentJSON interface{}) (resp *RespSendEvent, err error) {
 | 
			
		||||
	txnID := txnID()
 | 
			
		||||
	urlPath := cli.BuildURL("rooms", roomID, "send", eventType, txnID)
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, contentJSON, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, urlPath, contentJSON, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -533,7 +559,7 @@ func (cli *Client) SendMessageEvent(roomID string, eventType string, contentJSON
 | 
			
		|||
// contentJSON should be a pointer to something that can be encoded as JSON using json.Marshal.
 | 
			
		||||
func (cli *Client) SendStateEvent(roomID, eventType, stateKey string, contentJSON interface{}) (resp *RespSendEvent, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("rooms", roomID, "state", eventType, stateKey)
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, contentJSON, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, urlPath, contentJSON, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -541,14 +567,14 @@ func (cli *Client) SendStateEvent(roomID, eventType, stateKey string, contentJSO
 | 
			
		|||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-text
 | 
			
		||||
func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) {
 | 
			
		||||
	return cli.SendMessageEvent(roomID, "m.room.message",
 | 
			
		||||
		TextMessage{MsgType: "m.text", Body: text})
 | 
			
		||||
		TextMessage{MsgType: TextMessageType, Body: text})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendFormattedText sends an m.room.message event into the given room with a msgtype of m.text, supports a subset of HTML for formatting.
 | 
			
		||||
// See https://matrix.org/docs/spec/client_server/r0.6.0#m-text
 | 
			
		||||
func (cli *Client) SendFormattedText(roomID, text, formattedText string) (*RespSendEvent, error) {
 | 
			
		||||
	return cli.SendMessageEvent(roomID, "m.room.message",
 | 
			
		||||
		TextMessage{MsgType: "m.text", Body: text, FormattedBody: formattedText, Format: "org.matrix.custom.html"})
 | 
			
		||||
		TextMessage{MsgType: TextMessageType, Body: text, FormattedBody: formattedText, Format: "org.matrix.custom.html"})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendImage sends an m.room.message event into the given room with a msgtype of m.image
 | 
			
		||||
| 
						 | 
				
			
			@ -556,7 +582,7 @@ func (cli *Client) SendFormattedText(roomID, text, formattedText string) (*RespS
 | 
			
		|||
func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {
 | 
			
		||||
	return cli.SendMessageEvent(roomID, "m.room.message",
 | 
			
		||||
		ImageMessage{
 | 
			
		||||
			MsgType: "m.image",
 | 
			
		||||
			MsgType: ImageMessageType,
 | 
			
		||||
			Body:    body,
 | 
			
		||||
			URL:     url,
 | 
			
		||||
		})
 | 
			
		||||
| 
						 | 
				
			
			@ -567,7 +593,7 @@ func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {
 | 
			
		|||
func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) {
 | 
			
		||||
	return cli.SendMessageEvent(roomID, "m.room.message",
 | 
			
		||||
		VideoMessage{
 | 
			
		||||
			MsgType: "m.video",
 | 
			
		||||
			MsgType: VideoMessageType,
 | 
			
		||||
			Body:    body,
 | 
			
		||||
			URL:     url,
 | 
			
		||||
		})
 | 
			
		||||
| 
						 | 
				
			
			@ -577,21 +603,21 @@ func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) {
 | 
			
		|||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice
 | 
			
		||||
func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error) {
 | 
			
		||||
	return cli.SendMessageEvent(roomID, "m.room.message",
 | 
			
		||||
		TextMessage{MsgType: "m.notice", Body: text})
 | 
			
		||||
		TextMessage{MsgType: NoticeMessageType, Body: text})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RedactEvent redacts the given event. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
 | 
			
		||||
func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *RespSendEvent, err error) {
 | 
			
		||||
	txnID := txnID()
 | 
			
		||||
	urlPath := cli.BuildURL("rooms", roomID, "redact", eventID, txnID)
 | 
			
		||||
	err = cli.MakeRequest("PUT", urlPath, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, urlPath, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MarkRead marks eventID in roomID as read, signifying the event, and all before it have been read. See https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid
 | 
			
		||||
func (cli *Client) MarkRead(roomID, eventID string) error {
 | 
			
		||||
	urlPath := cli.BuildURL("rooms", roomID, "receipt", "m.read", eventID)
 | 
			
		||||
	return cli.MakeRequest("POST", urlPath, nil, nil)
 | 
			
		||||
	return cli.MakeRequest(http.MethodPost, urlPath, nil, nil)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CreateRoom creates a new Matrix room. See https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
 | 
			
		||||
| 
						 | 
				
			
			@ -601,56 +627,56 @@ func (cli *Client) MarkRead(roomID, eventID string) error {
 | 
			
		|||
//  fmt.Println("Room:", resp.RoomID)
 | 
			
		||||
func (cli *Client) CreateRoom(req *ReqCreateRoom) (resp *RespCreateRoom, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("createRoom")
 | 
			
		||||
	err = cli.MakeRequest("POST", urlPath, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, urlPath, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// LeaveRoom leaves the given room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave
 | 
			
		||||
func (cli *Client) LeaveRoom(roomID string) (resp *RespLeaveRoom, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "leave")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, struct{}{}, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, struct{}{}, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ForgetRoom forgets a room entirely. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget
 | 
			
		||||
func (cli *Client) ForgetRoom(roomID string) (resp *RespForgetRoom, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "forget")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, struct{}{}, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, struct{}{}, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
 | 
			
		||||
func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "invite")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InviteUserByThirdParty invites a third-party identifier to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#invite-by-third-party-id-endpoint
 | 
			
		||||
func (cli *Client) InviteUserByThirdParty(roomID string, req *ReqInvite3PID) (resp *RespInviteUser, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "invite")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// KickUser kicks a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
 | 
			
		||||
func (cli *Client) KickUser(roomID string, req *ReqKickUser) (resp *RespKickUser, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "kick")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// BanUser bans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
 | 
			
		||||
func (cli *Client) BanUser(roomID string, req *ReqBanUser) (resp *RespBanUser, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "ban")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UnbanUser unbans a user from a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
 | 
			
		||||
func (cli *Client) UnbanUser(roomID string, req *ReqUnbanUser) (resp *RespUnbanUser, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "unban")
 | 
			
		||||
	err = cli.MakeRequest("POST", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPost, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -658,7 +684,7 @@ func (cli *Client) UnbanUser(roomID string, req *ReqUnbanUser) (resp *RespUnbanU
 | 
			
		|||
func (cli *Client) UserTyping(roomID string, typing bool, timeout int64) (resp *RespTyping, err error) {
 | 
			
		||||
	req := ReqTyping{Typing: typing, Timeout: timeout}
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "typing", cli.UserID)
 | 
			
		||||
	err = cli.MakeRequest("PUT", u, req, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodPut, u, req, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -667,7 +693,7 @@ func (cli *Client) UserTyping(roomID string, typing bool, timeout int64) (resp *
 | 
			
		|||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey
 | 
			
		||||
func (cli *Client) StateEvent(roomID, eventType, stateKey string, outContent interface{}) (err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "state", eventType, stateKey)
 | 
			
		||||
	err = cli.MakeRequest("GET", u, nil, outContent)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, u, nil, outContent)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -686,7 +712,7 @@ func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) {
 | 
			
		|||
// UploadToContentRepo uploads the given bytes to the content repository and returns an MXC URI.
 | 
			
		||||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload
 | 
			
		||||
func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, contentLength int64) (*RespMediaUpload, error) {
 | 
			
		||||
	req, err := http.NewRequest("POST", cli.BuildBaseURL("_matrix/media/r0/upload"), content)
 | 
			
		||||
	req, err := http.NewRequest(http.MethodPost, cli.BuildBaseURL("_matrix/media/r0/upload"), content)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -734,7 +760,7 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co
 | 
			
		|||
// This API is primarily designed for application services which may want to efficiently look up joined members in a room.
 | 
			
		||||
func (cli *Client) JoinedMembers(roomID string) (resp *RespJoinedMembers, err error) {
 | 
			
		||||
	u := cli.BuildURL("rooms", roomID, "joined_members")
 | 
			
		||||
	err = cli.MakeRequest("GET", u, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, u, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -744,7 +770,7 @@ func (cli *Client) JoinedMembers(roomID string) (resp *RespJoinedMembers, err er
 | 
			
		|||
// This API is primarily designed for application services which may want to efficiently look up joined rooms.
 | 
			
		||||
func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) {
 | 
			
		||||
	u := cli.BuildURL("joined_rooms")
 | 
			
		||||
	err = cli.MakeRequest("GET", u, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, u, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -764,7 +790,7 @@ func (cli *Client) Messages(roomID, from, to string, dir rune, limit int) (resp
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	urlPath := cli.BuildURLWithQuery([]string{"rooms", roomID, "messages"}, query)
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -806,7 +832,7 @@ func (cli *Client) RoomAliases(roomID string) (resp *RespRoomAliases, err error)
 | 
			
		|||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-voip-turnserver
 | 
			
		||||
func (cli *Client) TurnServer() (resp *RespTurnServer, err error) {
 | 
			
		||||
	urlPath := cli.BuildURL("voip", "turnServer")
 | 
			
		||||
	err = cli.MakeRequest("GET", urlPath, nil, &resp)
 | 
			
		||||
	err = cli.MakeRequest(http.MethodGet, urlPath, nil, &resp)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,7 +10,7 @@ import (
 | 
			
		|||
 | 
			
		||||
func TestClient_LeaveRoom(t *testing.T) {
 | 
			
		||||
	cli := mockClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
		if req.Method == "POST" && req.URL.Path == "/_matrix/client/r0/rooms/!foo:bar/leave" {
 | 
			
		||||
		if req.Method == http.MethodPost && req.URL.Path == "/_matrix/client/r0/rooms/!foo:bar/leave" {
 | 
			
		||||
			return &http.Response{
 | 
			
		||||
				StatusCode: 200,
 | 
			
		||||
				Body:       ioutil.NopCloser(bytes.NewBufferString(`{}`)),
 | 
			
		||||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ func TestClient_LeaveRoom(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
func TestClient_GetAvatarUrl(t *testing.T) {
 | 
			
		||||
	cli := mockClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
		if req.Method == "GET" && req.URL.Path == "/_matrix/client/r0/profile/@user:test.gomatrix.org/avatar_url" {
 | 
			
		||||
		if req.Method == http.MethodGet && req.URL.Path == "/_matrix/client/r0/profile/@user:test.gomatrix.org/avatar_url" {
 | 
			
		||||
			return &http.Response{
 | 
			
		||||
				StatusCode: 200,
 | 
			
		||||
				Body:       ioutil.NopCloser(bytes.NewBufferString(`{"avatar_url":"mxc://matrix.org/iJaUjkshgdfsdkjfn"}`)),
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ func TestClient_GetAvatarUrl(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
func TestClient_SetAvatarUrl(t *testing.T) {
 | 
			
		||||
	cli := mockClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
		if req.Method == "PUT" && req.URL.Path == "/_matrix/client/r0/profile/@user:test.gomatrix.org/avatar_url" {
 | 
			
		||||
		if req.Method == http.MethodPut && req.URL.Path == "/_matrix/client/r0/profile/@user:test.gomatrix.org/avatar_url" {
 | 
			
		||||
			return &http.Response{
 | 
			
		||||
				StatusCode: 200,
 | 
			
		||||
				Body:       ioutil.NopCloser(bytes.NewBufferString(`{}`)),
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +63,7 @@ func TestClient_SetAvatarUrl(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
func TestClient_StateEvent(t *testing.T) {
 | 
			
		||||
	cli := mockClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
		if req.Method == "GET" && req.URL.Path == "/_matrix/client/r0/rooms/!foo:bar/state/m.room.name" {
 | 
			
		||||
		if req.Method == http.MethodGet && req.URL.Path == "/_matrix/client/r0/rooms/!foo:bar/state/m.room.name" {
 | 
			
		||||
			return &http.Response{
 | 
			
		||||
				StatusCode: 200,
 | 
			
		||||
				Body:       ioutil.NopCloser(bytes.NewBufferString(`{"name":"Room Name Goes Here"}`)),
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +86,7 @@ func TestClient_StateEvent(t *testing.T) {
 | 
			
		|||
 | 
			
		||||
func TestClient_PublicRooms(t *testing.T) {
 | 
			
		||||
	cli := mockClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
		if req.Method == "GET" && req.URL.Path == "/_matrix/client/r0/publicRooms" {
 | 
			
		||||
		if req.Method == http.MethodGet && req.URL.Path == "/_matrix/client/r0/publicRooms" {
 | 
			
		||||
			return &http.Response{
 | 
			
		||||
				StatusCode: 200,
 | 
			
		||||
				Body: ioutil.NopCloser(bytes.NewBufferString(`{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										134
									
								
								errors.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								errors.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,134 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
// RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface.
 | 
			
		||||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#api-standards
 | 
			
		||||
type RespError struct {
 | 
			
		||||
	ErrCode string `json:"errcode"`
 | 
			
		||||
	Err     string `json:"error"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Error returns the errcode and error message.
 | 
			
		||||
func (e RespError) Error() string {
 | 
			
		||||
	return e.ErrCode + ": " + e.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Is allow use 'errors.Is' from stdlib
 | 
			
		||||
func (e RespError) Is(err error) bool {
 | 
			
		||||
	target, ok := err.(RespError)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if e.ErrCode == "M_UNKNOWN" && target.ErrCode == "M_UNKNOWN" {
 | 
			
		||||
		return e.Err == target.Err
 | 
			
		||||
	}
 | 
			
		||||
	return e.ErrCode == target.ErrCode
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Common error codes from https://matrix.org/docs/spec/client_server/latest#api-standards
 | 
			
		||||
//
 | 
			
		||||
// Can be used with errors.Is() to check the response code without casting the error:
 | 
			
		||||
//   err := client.SyncRequest()
 | 
			
		||||
//   if errors.Is(err, ErrUnknownToken) {
 | 
			
		||||
//     // logout
 | 
			
		||||
//   }
 | 
			
		||||
var (
 | 
			
		||||
	// ErrForbidden Forbidden access, e.g. joining a room without permission, failed login.
 | 
			
		||||
	ErrForbidden = RespError{ErrCode: "M_FORBIDDEN"}
 | 
			
		||||
 | 
			
		||||
	// ErrUnknownToken The access token specified was not recognised.
 | 
			
		||||
	ErrUnknownToken = RespError{ErrCode: "M_UNKNOWN_TOKEN"}
 | 
			
		||||
 | 
			
		||||
	// ErrMissingToken No access token was specified for the request.
 | 
			
		||||
	ErrMissingToken = RespError{ErrCode: "M_MISSING_TOKEN"}
 | 
			
		||||
 | 
			
		||||
	// ErrBadJSON Request contained valid JSON, but it was malformed in some way, e.g. missing required keys, invalid values for keys.
 | 
			
		||||
	ErrBadJSON = RespError{ErrCode: "M_BAD_JSON"}
 | 
			
		||||
 | 
			
		||||
	// ErrNotJSON Request did not contain valid JSON.
 | 
			
		||||
	ErrNotJSON = RespError{ErrCode: "M_NOT_JSON"}
 | 
			
		||||
 | 
			
		||||
	// ErrNotFound No resource was found for this request.
 | 
			
		||||
	ErrNotFound = RespError{ErrCode: "M_NOT_FOUND"}
 | 
			
		||||
 | 
			
		||||
	// ErrLimitExceeded Too many requests have been sent in a short period of time. Wait a while then try again.
 | 
			
		||||
	ErrLimitExceeded = RespError{ErrCode: "M_LIMIT_EXCEEDED"}
 | 
			
		||||
 | 
			
		||||
	// ErrUnknown An unknown error has occurred
 | 
			
		||||
	ErrUnknown = RespError{ErrCode: "M_UNKNOWN"}
 | 
			
		||||
 | 
			
		||||
	// ErrUnrecognuzed The server did not understand the request.
 | 
			
		||||
	ErrUnrecognuzed = RespError{ErrCode: "M_UNRECOGNIZED"}
 | 
			
		||||
 | 
			
		||||
	// ErrUnauthorized The request was not correctly authorized. Usually due to login failures.
 | 
			
		||||
	ErrUnauthorized = RespError{ErrCode: "M_UNAUTHORIZED"}
 | 
			
		||||
 | 
			
		||||
	// ErrUserDeactivated The user ID associated with the request has been deactivated.
 | 
			
		||||
	// Typically for endpoints that prove authentication, such as /login.
 | 
			
		||||
	ErrUserDeactivated = RespError{ErrCode: "M_USER_DEACTIVATED"}
 | 
			
		||||
 | 
			
		||||
	// ErrUserInUse Encountered when trying to register a user ID which has been taken.
 | 
			
		||||
	ErrUserInUse = RespError{ErrCode: "M_USER_IN_USE"}
 | 
			
		||||
 | 
			
		||||
	// ErrInvalidUsername Encountered when trying to register a user ID which is not valid.
 | 
			
		||||
	ErrInvalidUsername = RespError{ErrCode: "M_INVALID_USERNAME"}
 | 
			
		||||
 | 
			
		||||
	// ErrRoomInUse Sent when the room alias given to the createRoom API is already in use.
 | 
			
		||||
	ErrRoomInUse = RespError{ErrCode: "M_ROOM_IN_USE"}
 | 
			
		||||
 | 
			
		||||
	// ErrInvalidRoomState Sent when the initial state given to the createRoom API is invalid
 | 
			
		||||
	ErrInvalidRoomState = RespError{ErrCode: "M_INVALID_ROOM_STATE"}
 | 
			
		||||
 | 
			
		||||
	// ErrThreepidInUse Sent when a threepid given to an API cannot be used because the same threepid is already in use.
 | 
			
		||||
	ErrThreepidInUse = RespError{ErrCode: "M_THREEPID_IN_USE"}
 | 
			
		||||
 | 
			
		||||
	// ErrThreepidNotFound Sent when a threepid given to an API cannot be used because no record matching the threepid was found.
 | 
			
		||||
	ErrThreepidNotFound = RespError{ErrCode: "M_THREEPID_NOT_FOUND"}
 | 
			
		||||
 | 
			
		||||
	// ErrThreepidAuthFailed Authentication could not be performed on the third party identifier.
 | 
			
		||||
	ErrThreepidAuthFailed = RespError{ErrCode: "M_THREEPID_AUTH_FAILED"}
 | 
			
		||||
 | 
			
		||||
	// ErrThreepidDenied The server does not permit this third party identifier. This may happen if the server only permits, for example, email addresses from a particular domain.
 | 
			
		||||
	ErrThreepidDenied = RespError{ErrCode: "M_THREEPID_DENIED"}
 | 
			
		||||
 | 
			
		||||
	// ErrServerNotTrusted The client's request used a third party server, eg. identity server, that this server does not trust.
 | 
			
		||||
	ErrServerNotTrusted = RespError{ErrCode: "M_SERVER_NOT_TRUSTED"}
 | 
			
		||||
 | 
			
		||||
	// ErrUnsupportedRoomVersion The client's request to create a room used a room version that the server does not support.
 | 
			
		||||
	ErrUnsupportedRoomVersion = RespError{ErrCode: "M_UNSUPPORTED_ROOM_VERSION:"}
 | 
			
		||||
 | 
			
		||||
	// ErrIncompatibleRoomVersion The client attempted to join a room that has a version the server does not support. Inspect the room_version property of the error response for the room's version.
 | 
			
		||||
	ErrIncompatibleRoomVersion = RespError{ErrCode: "M_INCOMPATIBLE_ROOM_VERSION"}
 | 
			
		||||
 | 
			
		||||
	// ErrBadState The state change requested cannot be performed, such as attempting to unban a user who is not banned.
 | 
			
		||||
	ErrBadState = RespError{ErrCode: "M_BAD_STATE"}
 | 
			
		||||
 | 
			
		||||
	// ErrGuestAccessForbidden The room or resource does not permit guests to access it.
 | 
			
		||||
	ErrGuestAccessForbidden = RespError{ErrCode: "M_GUEST_ACCESS_FORBIDDEN"}
 | 
			
		||||
 | 
			
		||||
	// ErrCaptchaNeeded A Captcha is required to complete the request.
 | 
			
		||||
	ErrCaptchaNeeded = RespError{ErrCode: "M_CAPTCHA_NEEDED"}
 | 
			
		||||
 | 
			
		||||
	// ErrCaptchaInvalid The Captcha provided did not match what was expected.
 | 
			
		||||
	ErrCaptchaInvalid = RespError{ErrCode: "M_CAPTCHA_INVALID"}
 | 
			
		||||
 | 
			
		||||
	// ErrMissingParam A required parameter was missing from the request.
 | 
			
		||||
	ErrMissingParam = RespError{ErrCode: "M_MISSING_PARAM"}
 | 
			
		||||
 | 
			
		||||
	// ErrInvalidParam A parameter that was specified has the wrong value. For example, the server expected an integer and instead received a string.
 | 
			
		||||
	ErrInvalidParam = RespError{ErrCode: "M_INVALID_PARAM"}
 | 
			
		||||
 | 
			
		||||
	// ErrTooLarge The request or entity was too large.
 | 
			
		||||
	ErrTooLarge = RespError{ErrCode: "M_TOO_LARGE"}
 | 
			
		||||
 | 
			
		||||
	// ErrExclusive The resource being requested is reserved by an application service, or the application service making the request has not created the resource.
 | 
			
		||||
	ErrExclusive = RespError{ErrCode: "M_EXCLUSIVE"}
 | 
			
		||||
 | 
			
		||||
	// ErrRespuceLimitExceeded The request cannot be completed because the homeserver has reached a resource limit imposed on it. For example, a homeserver held in a shared hosting environment may
 | 
			
		||||
	//reach a resource limit if it starts using too much memory or disk space. The error MUST have an admin_contact field to provide the user receiving the error a place to reach out to.
 | 
			
		||||
	//Typically, this error will appear on routes which attempt to modify state (eg: sending messages, account data, etc) and not routes which only read state (eg: /sync, get account data, etc).
 | 
			
		||||
	ErrRespuceLimitExceeded = RespError{ErrCode: "M_RESOURCE_LIMIT_EXCEEDED"}
 | 
			
		||||
 | 
			
		||||
	// ErrCannotLeaveServerNoticeRoom The user is unable to reject an invite to join the server notices room.
 | 
			
		||||
	ErrCannotLeaveServerNoticeRoom = RespError{ErrCode: "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM"}
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										34
									
								
								events.go
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								events.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -43,10 +43,10 @@ func (event *Event) MessageType() (msgtype string, ok bool) {
 | 
			
		|||
 | 
			
		||||
// TextMessage is the contents of a Matrix formated message event.
 | 
			
		||||
type TextMessage struct {
 | 
			
		||||
	MsgType       string `json:"msgtype"`
 | 
			
		||||
	Body          string `json:"body"`
 | 
			
		||||
	FormattedBody string `json:"formatted_body"`
 | 
			
		||||
	Format        string `json:"format"`
 | 
			
		||||
	MsgType       MessageType `json:"msgtype"`
 | 
			
		||||
	Body          string      `json:"body"`
 | 
			
		||||
	FormattedBody string      `json:"formatted_body"`
 | 
			
		||||
	Format        string      `json:"format"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ThumbnailInfo contains info about an thumbnail image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
 | 
			
		||||
| 
						 | 
				
			
			@ -80,26 +80,26 @@ type VideoInfo struct {
 | 
			
		|||
 | 
			
		||||
// VideoMessage is an m.video  - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video
 | 
			
		||||
type VideoMessage struct {
 | 
			
		||||
	MsgType string    `json:"msgtype"`
 | 
			
		||||
	Body    string    `json:"body"`
 | 
			
		||||
	URL     string    `json:"url"`
 | 
			
		||||
	Info    VideoInfo `json:"info"`
 | 
			
		||||
	MsgType MessageType `json:"msgtype"`
 | 
			
		||||
	Body    string      `json:"body"`
 | 
			
		||||
	URL     string      `json:"url"`
 | 
			
		||||
	Info    VideoInfo   `json:"info"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ImageMessage is an m.image event
 | 
			
		||||
type ImageMessage struct {
 | 
			
		||||
	MsgType string    `json:"msgtype"`
 | 
			
		||||
	Body    string    `json:"body"`
 | 
			
		||||
	URL     string    `json:"url"`
 | 
			
		||||
	Info    ImageInfo `json:"info"`
 | 
			
		||||
	MsgType MessageType `json:"msgtype"`
 | 
			
		||||
	Body    string      `json:"body"`
 | 
			
		||||
	URL     string      `json:"url"`
 | 
			
		||||
	Info    ImageInfo   `json:"info"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// An HTMLMessage is the contents of a Matrix HTML formated message event.
 | 
			
		||||
type HTMLMessage struct {
 | 
			
		||||
	Body          string `json:"body"`
 | 
			
		||||
	MsgType       string `json:"msgtype"`
 | 
			
		||||
	Format        string `json:"format"`
 | 
			
		||||
	FormattedBody string `json:"formatted_body"`
 | 
			
		||||
	Body          string      `json:"body"`
 | 
			
		||||
	MsgType       MessageType `json:"msgtype"`
 | 
			
		||||
	Format        string      `json:"format"`
 | 
			
		||||
	FormattedBody string      `json:"formatted_body"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FileInfo contains info about an file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ var htmlRegex = regexp.MustCompile("<[^<]+?>")
 | 
			
		|||
 | 
			
		||||
// GetHTMLMessage returns an HTMLMessage with the body set to a stripped version of the provided HTML, in addition
 | 
			
		||||
// to the provided HTML.
 | 
			
		||||
func GetHTMLMessage(msgtype, htmlText string) HTMLMessage {
 | 
			
		||||
func GetHTMLMessage(msgtype MessageType, htmlText string) HTMLMessage {
 | 
			
		||||
	return HTMLMessage{
 | 
			
		||||
		Body:          html.UnescapeString(htmlRegex.ReplaceAllLiteralString(htmlText, "")),
 | 
			
		||||
		MsgType:       msgtype,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -94,14 +94,14 @@ func TestEventWithoutMessageType(t *testing.T) {
 | 
			
		|||
var testHTML = `<div>a<h1>bc</h1>d<p>e<i>fg</i>hi</p>j<p>k<br/>l<b>m</b>no</p>p<small>q</small>rs</div>`
 | 
			
		||||
 | 
			
		||||
func TestGetHTMLMessage(t *testing.T) {
 | 
			
		||||
	msg := GetHTMLMessage("m.text", testHTML)
 | 
			
		||||
	msg := GetHTMLMessage(TextMessageType, testHTML)
 | 
			
		||||
	if expected := "abcdefghijklmnopqrs"; msg.Body != expected {
 | 
			
		||||
		t.Fatalf("TestGetHTMLMessage: got '%s', expected '%s'", msg.Body, expected)
 | 
			
		||||
	}
 | 
			
		||||
	if msg.FormattedBody != testHTML {
 | 
			
		||||
		t.Fatalf("TestGetHTMLMessage: got '%s', expected '%s'", msg.FormattedBody, testHTML)
 | 
			
		||||
	}
 | 
			
		||||
	if msg.MsgType != "m.text" {
 | 
			
		||||
	if msg.MsgType != TextMessageType {
 | 
			
		||||
		t.Fatalf("TestGetHTMLMessage: got '%s', expected 'm.text'", msg.FormattedBody)
 | 
			
		||||
	}
 | 
			
		||||
	if expected := "org.matrix.custom.html"; msg.Format != expected {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								go.mod
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
module github.com/matrix-org/gomatrix
 | 
			
		||||
 | 
			
		||||
go 1.12
 | 
			
		||||
 | 
			
		||||
require github.com/mailru/easyjson v0.7.7 // indirect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,14 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/mailru/easyjson"
 | 
			
		||||
	"github.com/mailru/easyjson/jlexer"
 | 
			
		||||
	"github.com/mailru/easyjson/jwriter"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Identifier is the interface for https://matrix.org/docs/spec/client_server/r0.6.0#identifier-types
 | 
			
		||||
type Identifier interface {
 | 
			
		||||
	easyjson.MarshalerUnmarshaler
 | 
			
		||||
	// Returns the identifier type
 | 
			
		||||
	// https://matrix.org/docs/spec/client_server/r0.6.0#identifier-types
 | 
			
		||||
	Type() string
 | 
			
		||||
| 
						 | 
				
			
			@ -18,6 +25,14 @@ func (i UserIdentifier) Type() string {
 | 
			
		|||
	return "m.id.user"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i UserIdentifier) MarshalEasyJSON(w *jwriter.Writer) {
 | 
			
		||||
	w.String(i.IDType)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i UserIdentifier) UnmarshalEasyJSON(w *jlexer.Lexer) {
 | 
			
		||||
	i.IDType = w.String()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewUserIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
 | 
			
		||||
func NewUserIdentifier(user string) UserIdentifier {
 | 
			
		||||
	return UserIdentifier{
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +53,14 @@ func (i ThirdpartyIdentifier) Type() string {
 | 
			
		|||
	return "m.id.thirdparty"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i ThirdpartyIdentifier) MarshalEasyJSON(w *jwriter.Writer) {
 | 
			
		||||
	w.String(i.IDType)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i ThirdpartyIdentifier) UnmarshalEasyJSON(w *jlexer.Lexer) {
 | 
			
		||||
	i.IDType = w.String()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewThirdpartyIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
 | 
			
		||||
func NewThirdpartyIdentifier(medium, address string) ThirdpartyIdentifier {
 | 
			
		||||
	return ThirdpartyIdentifier{
 | 
			
		||||
| 
						 | 
				
			
			@ -59,6 +82,14 @@ func (i PhoneIdentifier) Type() string {
 | 
			
		|||
	return "m.id.phone"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i PhoneIdentifier) MarshalEasyJSON(w *jwriter.Writer) {
 | 
			
		||||
	w.String(i.IDType)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i PhoneIdentifier) UnmarshalEasyJSON(w *jlexer.Lexer) {
 | 
			
		||||
	i.IDType = w.String()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewPhoneIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
 | 
			
		||||
func NewPhoneIdentifier(country, phone string) PhoneIdentifier {
 | 
			
		||||
	return PhoneIdentifier{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								message.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								message.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
type MessageType string
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	TextMessageType     MessageType = "m.text"
 | 
			
		||||
	EmoteMessageType    MessageType = "m.emote"
 | 
			
		||||
	NoticeMessageType   MessageType = "m.notice"
 | 
			
		||||
	ImageMessageType    MessageType = "m.image"
 | 
			
		||||
	FileMessageType     MessageType = "m.file"
 | 
			
		||||
	AudioMessageType    MessageType = "m.audio"
 | 
			
		||||
	LocationMessageType MessageType = "m.location"
 | 
			
		||||
	VideoMessageType    MessageType = "m.video"
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										10
									
								
								requests.go
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								requests.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
// ReqRegister is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqRegister struct {
 | 
			
		||||
	Username                 string      `json:"username,omitempty"`
 | 
			
		||||
	BindEmail                bool        `json:"bind_email,omitempty"`
 | 
			
		||||
| 
						 | 
				
			
			@ -11,6 +12,7 @@ type ReqRegister struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqLogin struct {
 | 
			
		||||
	Type                     string     `json:"type"`
 | 
			
		||||
	Identifier               Identifier `json:"identifier,omitempty"`
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +26,7 @@ type ReqLogin struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqCreateRoom struct {
 | 
			
		||||
	Visibility      string                 `json:"visibility,omitempty"`
 | 
			
		||||
	RoomAliasName   string                 `json:"room_alias_name,omitempty"`
 | 
			
		||||
| 
						 | 
				
			
			@ -38,12 +41,14 @@ type ReqCreateRoom struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqRedact struct {
 | 
			
		||||
	Reason string `json:"reason,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReqInvite3PID is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#id57
 | 
			
		||||
// It is also a JSON object used in https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqInvite3PID struct {
 | 
			
		||||
	IDServer string `json:"id_server"`
 | 
			
		||||
	Medium   string `json:"medium"`
 | 
			
		||||
| 
						 | 
				
			
			@ -51,28 +56,33 @@ type ReqInvite3PID struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// ReqInviteUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqInviteUser struct {
 | 
			
		||||
	UserID string `json:"user_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReqKickUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqKickUser struct {
 | 
			
		||||
	Reason string `json:"reason,omitempty"`
 | 
			
		||||
	UserID string `json:"user_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReqBanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqBanUser struct {
 | 
			
		||||
	Reason string `json:"reason,omitempty"`
 | 
			
		||||
	UserID string `json:"user_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReqUnbanUser is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqUnbanUser struct {
 | 
			
		||||
	UserID string `json:"user_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ReqTyping is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type ReqTyping struct {
 | 
			
		||||
	Typing  bool  `json:"typing"`
 | 
			
		||||
	Timeout int64 `json:"timeout"`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1341
									
								
								requests_easyjson.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1341
									
								
								requests_easyjson.go
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										38
									
								
								responses.go
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								responses.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,28 +1,19 @@
 | 
			
		|||
package gomatrix
 | 
			
		||||
 | 
			
		||||
// RespError is the standard JSON error response from Homeservers. It also implements the Golang "error" interface.
 | 
			
		||||
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#api-standards
 | 
			
		||||
type RespError struct {
 | 
			
		||||
	ErrCode string `json:"errcode"`
 | 
			
		||||
	Err     string `json:"error"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Error returns the errcode and error message.
 | 
			
		||||
func (e RespError) Error() string {
 | 
			
		||||
	return e.ErrCode + ": " + e.Err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespCreateFilter is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespCreateFilter struct {
 | 
			
		||||
	FilterID string `json:"filter_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespVersions is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespVersions struct {
 | 
			
		||||
	Versions []string `json:"versions"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespPublicRooms is the JSON response for http://matrix.org/speculator/spec/HEAD/client_server/unstable.html#get-matrix-client-unstable-publicrooms
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespPublicRooms struct {
 | 
			
		||||
	TotalRoomCountEstimate int          `json:"total_room_count_estimate"`
 | 
			
		||||
	PrevBatch              string       `json:"prev_batch"`
 | 
			
		||||
| 
						 | 
				
			
			@ -31,37 +22,47 @@ type RespPublicRooms struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespJoinRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-join
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespJoinRoom struct {
 | 
			
		||||
	RoomID string `json:"room_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespLeaveRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-leave
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespLeaveRoom struct{}
 | 
			
		||||
 | 
			
		||||
// RespForgetRoom is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-forget
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespForgetRoom struct{}
 | 
			
		||||
 | 
			
		||||
// RespInviteUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespInviteUser struct{}
 | 
			
		||||
 | 
			
		||||
// RespKickUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-kick
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespKickUser struct{}
 | 
			
		||||
 | 
			
		||||
// RespBanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-ban
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespBanUser struct{}
 | 
			
		||||
 | 
			
		||||
// RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespUnbanUser struct{}
 | 
			
		||||
 | 
			
		||||
// RespTyping is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-typing-userid
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespTyping struct{}
 | 
			
		||||
 | 
			
		||||
// RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespJoinedRooms struct {
 | 
			
		||||
	JoinedRooms []string `json:"joined_rooms"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespJoinedMembers is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespJoinedMembers struct {
 | 
			
		||||
	Joined map[string]struct {
 | 
			
		||||
		DisplayName *string `json:"display_name"`
 | 
			
		||||
| 
						 | 
				
			
			@ -70,6 +71,7 @@ type RespJoinedMembers struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespMessages is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespMessages struct {
 | 
			
		||||
	Start string  `json:"start"`
 | 
			
		||||
	Chunk []Event `json:"chunk"`
 | 
			
		||||
| 
						 | 
				
			
			@ -77,16 +79,19 @@ type RespMessages struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespSendEvent struct {
 | 
			
		||||
	EventID string `json:"event_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespMediaUpload is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespMediaUpload struct {
 | 
			
		||||
	ContentURI string `json:"content_uri"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespUserInteractive is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#user-interactive-authentication-api
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespUserInteractive struct {
 | 
			
		||||
	Flows []struct {
 | 
			
		||||
		Stages []string `json:"stages"`
 | 
			
		||||
| 
						 | 
				
			
			@ -109,11 +114,13 @@ func (r RespUserInteractive) HasSingleStageFlow(stageName string) bool {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespUserDisplayName is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname
 | 
			
		||||
//easyjson:json
 | 
			
		||||
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
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespUserStatus struct {
 | 
			
		||||
	Presence        string `json:"presence"`
 | 
			
		||||
	StatusMsg       string `json:"status_msg"`
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +129,7 @@ type RespUserStatus struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespRegister is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespRegister struct {
 | 
			
		||||
	AccessToken  string `json:"access_token"`
 | 
			
		||||
	DeviceID     string `json:"device_id"`
 | 
			
		||||
| 
						 | 
				
			
			@ -131,6 +139,7 @@ type RespRegister struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespLogin struct {
 | 
			
		||||
	AccessToken string               `json:"access_token"`
 | 
			
		||||
	DeviceID    string               `json:"device_id"`
 | 
			
		||||
| 
						 | 
				
			
			@ -150,17 +159,21 @@ type DiscoveryInformation struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-logout
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespLogout struct{}
 | 
			
		||||
 | 
			
		||||
// RespLogoutAll is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespLogoutAll struct{}
 | 
			
		||||
 | 
			
		||||
// RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespCreateRoom struct {
 | 
			
		||||
	RoomID string `json:"room_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RespSync is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-sync
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespSync struct {
 | 
			
		||||
	NextBatch   string `json:"next_batch"`
 | 
			
		||||
	AccountData struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -202,6 +215,7 @@ type RespSync struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
// RespTurnServer is the JSON response from a Turn Server
 | 
			
		||||
//easyjson:json
 | 
			
		||||
type RespTurnServer struct {
 | 
			
		||||
	Username string   `json:"username"`
 | 
			
		||||
	Password string   `json:"password"`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3582
									
								
								responses_easyjson.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3582
									
								
								responses_easyjson.go
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue