mirror of
https://github.com/matrix-org/gomatrix
synced 2025-05-12 10:41:44 +00:00
Add LeaveRoom(roomID) with test
This commit is contained in:
parent
e66d1ef529
commit
69b0fcb79d
3 changed files with 61 additions and 2 deletions
16
client.go
16
client.go
|
@ -185,7 +185,7 @@ func (cli *Client) SendJSON(method string, httpURL string, contentJSON interface
|
|||
if res.StatusCode >= 300 || res.StatusCode < 200 {
|
||||
var wrap error
|
||||
var respErr RespError
|
||||
if _ = json.Unmarshal(contents, respErr); respErr.ErrCode != "" {
|
||||
if _ = json.Unmarshal(contents, &respErr); respErr.ErrCode != "" {
|
||||
wrap = respErr
|
||||
}
|
||||
|
||||
|
@ -315,6 +315,20 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) {
|
|||
TextMessage{"m.text", text})
|
||||
}
|
||||
|
||||
// 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) (*RespLeaveRoom, error) {
|
||||
u := cli.BuildURL("rooms", roomID, "leave")
|
||||
resBytes, err := cli.SendJSON("POST", u, struct{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp RespLeaveRoom
|
||||
if err = json.Unmarshal(resBytes, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// UploadLink uploads an HTTP URL and then returns an MXC URI.
|
||||
func (cli *Client) UploadLink(link string) (*RespMediaUpload, error) {
|
||||
res, err := cli.Client.Get(link)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue