summaryrefslogtreecommitdiffstats
path: root/vendor/github.com
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-10-26 23:31:44 +0200
committerGitHub <noreply@github.com>2019-10-26 23:31:44 +0200
commit0b9bc18236055fdb785a878b3a0f40f73102f8ef (patch)
tree4b267bad36e2995c85c64b4e3a4a59bd078336b9 /vendor/github.com
parentbad3b83d339b5d3ec8cd69e11ee56e82e23737bb (diff)
downloadmatterbridge-msglm-0b9bc18236055fdb785a878b3a0f40f73102f8ef.tar.gz
matterbridge-msglm-0b9bc18236055fdb785a878b3a0f40f73102f8ef.tar.bz2
matterbridge-msglm-0b9bc18236055fdb785a878b3a0f40f73102f8ef.zip
Update vendor matterbridge/gomatrix fork (#928)
Diffstat (limited to 'vendor/github.com')
-rw-r--r--vendor/github.com/matterbridge/gomatrix/.travis.yml2
-rw-r--r--vendor/github.com/matterbridge/gomatrix/client.go155
-rw-r--r--vendor/github.com/matterbridge/gomatrix/events.go52
-rw-r--r--vendor/github.com/matterbridge/gomatrix/filter.go79
-rw-r--r--vendor/github.com/matterbridge/gomatrix/responses.go3
-rw-r--r--vendor/github.com/matterbridge/gomatrix/userids.go2
6 files changed, 208 insertions, 85 deletions
diff --git a/vendor/github.com/matterbridge/gomatrix/.travis.yml b/vendor/github.com/matterbridge/gomatrix/.travis.yml
index fadc3264..13585d41 100644
--- a/vendor/github.com/matterbridge/gomatrix/.travis.yml
+++ b/vendor/github.com/matterbridge/gomatrix/.travis.yml
@@ -1,6 +1,6 @@
language: go
go:
- - 1.8
+ - 1.10.x
install:
- go get github.com/golang/lint/golint
- go get github.com/fzipp/gocyclo
diff --git a/vendor/github.com/matterbridge/gomatrix/client.go b/vendor/github.com/matterbridge/gomatrix/client.go
index acc92258..5a90b52a 100644
--- a/vendor/github.com/matterbridge/gomatrix/client.go
+++ b/vendor/github.com/matterbridge/gomatrix/client.go
@@ -13,6 +13,7 @@ import (
"net/url"
"path"
"strconv"
+ "strings"
"sync"
"time"
)
@@ -38,6 +39,7 @@ type Client struct {
// HTTPError An HTTP Error response, which may wrap an underlying native Go Error.
type HTTPError struct {
+ Contents []byte
WrappedError error
Message string
Code int
@@ -48,7 +50,7 @@ func (e HTTPError) Error() string {
if e.WrappedError != nil {
wrappedErrMsg = e.WrappedError.Error()
}
- return fmt.Sprintf("msg=%s code=%d wrapped=%s", e.Message, e.Code, wrappedErrMsg)
+ return fmt.Sprintf("contents=%v msg=%s code=%d wrapped=%s", e.Contents, e.Message, e.Code, wrappedErrMsg)
}
// BuildURL builds a URL with the Client's homserver/prefix/access_token set already.
@@ -68,6 +70,10 @@ func (cli *Client) BuildBaseURL(urlPath ...string) string {
parts := []string{hsURL.Path}
parts = append(parts, urlPath...)
hsURL.Path = path.Join(parts...)
+ // Manually add the trailing slash back to the end of the path if it's explicitly needed
+ if strings.HasSuffix(urlPath[len(urlPath)-1], "/") {
+ hsURL.Path = hsURL.Path + "/"
+ }
query := hsURL.Query()
if cli.AccessToken != "" {
query.Set("access_token", cli.AccessToken)
@@ -178,27 +184,27 @@ func (cli *Client) StopSync() {
}
// MakeRequest makes a JSON HTTP request to the given URL.
-// If "resBody" is not nil, the response body will be json.Unmarshalled into it.
+// The response body will be stream decoded into an interface. This will automatically stop if the response
+// body is nil.
//
-// Returns the HTTP body as bytes on 2xx with a nil error. Returns an error if the response is not 2xx along
-// with the HTTP body bytes if it got that far. This error is an HTTPError which includes the returned
-// HTTP status code and possibly a RespError as the WrappedError, if the HTTP body could be decoded as a RespError.
-func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) ([]byte, error) {
+// Returns an error if the response is not 2xx along with the HTTP body bytes if it got that far. This error is
+// an HTTPError which includes the returned HTTP status code, byte contents of the response body and possibly a
+// RespError as the WrappedError, if the HTTP body could be decoded as a RespError.
+func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{}, resBody interface{}) error {
var req *http.Request
var err error
if reqBody != nil {
- var jsonStr []byte
- jsonStr, err = json.Marshal(reqBody)
- if err != nil {
- return nil, err
+ buf := new(bytes.Buffer)
+ if err := json.NewEncoder(buf).Encode(reqBody); err != nil {
+ return err
}
- req, err = http.NewRequest(method, httpURL, bytes.NewBuffer(jsonStr))
+ req, err = http.NewRequest(method, httpURL, buf)
} else {
req, err = http.NewRequest(method, httpURL, nil)
}
if err != nil {
- return nil, err
+ return err
}
req.Header.Set("Content-Type", "application/json")
res, err := cli.Client.Do(req)
@@ -206,10 +212,14 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
defer res.Body.Close()
}
if err != nil {
- return nil, err
+ return err
}
- contents, err := ioutil.ReadAll(res.Body)
if res.StatusCode/100 != 2 { // not 2xx
+ contents, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return err
+ }
+
var wrap error
var respErr RespError
if _ = json.Unmarshal(contents, &respErr); respErr.ErrCode != "" {
@@ -223,29 +233,25 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
msg = msg + ": " + string(contents)
}
- return contents, HTTPError{
+ return HTTPError{
+ Contents: contents,
Code: res.StatusCode,
Message: msg,
WrappedError: wrap,
}
}
- if err != nil {
- return nil, err
- }
- if resBody != nil {
- if err = json.Unmarshal(contents, &resBody); err != nil {
- return nil, err
- }
+ if resBody != nil && res.Body != nil {
+ return json.NewDecoder(res.Body).Decode(&resBody)
}
- return contents, nil
+ return nil
}
// 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("POST", urlPath, &filter, &resp)
return
}
@@ -267,13 +273,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("GET", urlPath, nil, &resp)
return
}
func (cli *Client) register(u string, req *ReqRegister) (resp *RespRegister, uiaResp *RespUserInteractive, err error) {
- var bodyBytes []byte
- bodyBytes, err = cli.MakeRequest("POST", u, req, nil)
+ err = cli.MakeRequest("POST", u, req, &resp)
if err != nil {
httpErr, ok := err.(HTTPError)
if !ok { // network error
@@ -281,13 +286,10 @@ func (cli *Client) register(u string, req *ReqRegister) (resp *RespRegister, uia
}
if httpErr.Code == 401 {
// body should be RespUserInteractive, if it isn't, fail with the error
- err = json.Unmarshal(bodyBytes, &uiaResp)
+ err = json.Unmarshal(httpErr.Contents, &uiaResp)
return
}
- return
}
- // body should be RespRegister
- err = json.Unmarshal(bodyBytes, &resp)
return
}
@@ -351,7 +353,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("POST", urlPath, req, &resp)
return
}
@@ -359,14 +361,14 @@ 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("POST", 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("GET", urlPath, nil, &resp)
return
}
@@ -383,21 +385,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("POST", 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("GET", 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("GET", urlPath, nil, &resp)
return
}
@@ -407,18 +409,18 @@ 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("PUT", urlPath, &s, nil)
return
}
// GetAvatarURL gets the user's avatar URL. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url
-func (cli *Client) GetAvatarURL() (url string, err error) {
+func (cli *Client) GetAvatarURL() (string, error) {
urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url")
s := struct {
AvatarURL string `json:"avatar_url"`
}{}
- _, err = cli.MakeRequest("GET", urlPath, nil, &s)
+ err := cli.MakeRequest("GET", urlPath, nil, &s)
if err != nil {
return "", err
}
@@ -427,12 +429,12 @@ func (cli *Client) GetAvatarURL() (url string, err error) {
}
// 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) {
+func (cli *Client) SetAvatarURL(url string) error {
urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url")
s := struct {
AvatarURL string `json:"avatar_url"`
}{url}
- _, err = cli.MakeRequest("PUT", urlPath, &s, nil)
+ err := cli.MakeRequest("PUT", urlPath, &s, nil)
if err != nil {
return err
}
@@ -445,7 +447,7 @@ func (cli *Client) SetAvatarURL(url 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("PUT", urlPath, contentJSON, &resp)
return
}
@@ -453,7 +455,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("PUT", urlPath, contentJSON, &resp)
return
}
@@ -491,6 +493,36 @@ func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) {
})
}
+// SendAudio sends an m.room.message event into the given room with a msgtype of m.audio
+// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio
+func (cli *Client) SendAudio(roomID, body, url, mimetype string, size uint) (*RespSendEvent, error) {
+ return cli.SendMessageEvent(roomID, "m.room.message",
+ AudioMessage{
+ MsgType: "m.audio",
+ Body: body,
+ URL: url,
+ Info: AudioInfo{
+ Size: size,
+ Mimetype: mimetype,
+ },
+ })
+}
+
+// SendFile sends an m.room.message event into the given room with a msgtype of m.file
+// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
+func (cli *Client) SendFile(roomID, body, url, mimetype string, size uint) (*RespSendEvent, error) {
+ return cli.SendMessageEvent(roomID, "m.room.message",
+ FileMessage{
+ MsgType: "m.file",
+ Body: body,
+ URL: url,
+ Info: FileInfo{
+ Size: size,
+ Mimetype: mimetype,
+ },
+ })
+}
+
// SendNotice sends an m.room.message event into the given room with a msgtype of m.notice
// See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice
func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error) {
@@ -507,7 +539,7 @@ func (cli *Client) SendNoticeHTML(roomID, textclear, text string) (*RespSendEven
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("PUT", urlPath, req, &resp)
return
}
@@ -518,56 +550,56 @@ func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *Re
// 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("POST", 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("POST", 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("POST", 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, struct{}{}, &resp)
+ err = cli.MakeRequest("POST", 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("POST", 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("POST", 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("POST", 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("POST", u, req, &resp)
return
}
@@ -575,7 +607,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("PUT", u, req, &resp)
return
}
@@ -584,7 +616,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("GET", u, nil, outContent)
return
}
@@ -625,8 +657,9 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co
}
}
return nil, HTTPError{
- Message: "Upload request failed: " + string(contents),
- Code: res.StatusCode,
+ Contents: contents,
+ Message: "Upload request failed: " + string(contents),
+ Code: res.StatusCode,
}
}
var m RespMediaUpload
@@ -642,7 +675,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("GET", u, nil, &resp)
return
}
@@ -652,7 +685,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("GET", u, nil, &resp)
return
}
@@ -672,7 +705,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("GET", urlPath, nil, &resp)
return
}
@@ -680,7 +713,7 @@ func (cli *Client) Messages(roomID, from, to string, dir rune, limit int) (resp
// 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("GET", urlPath, nil, &resp)
return
}
diff --git a/vendor/github.com/matterbridge/gomatrix/events.go b/vendor/github.com/matterbridge/gomatrix/events.go
index d065cd72..d3ee7491 100644
--- a/vendor/github.com/matterbridge/gomatrix/events.go
+++ b/vendor/github.com/matterbridge/gomatrix/events.go
@@ -15,6 +15,7 @@ type Event struct {
RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence)
Content map[string]interface{} `json:"content"` // The JSON content of the event.
Redacts string `json:"redacts,omitempty"` // The event ID that was redacted if a m.room.redaction event
+ Unsigned map[string]interface{} `json:"unsigned"` // The unsigned portions of the event, such as age and prev_content
}
// Body returns the value of the "body" key in the event content if it is
@@ -47,22 +48,47 @@ type TextMessage struct {
FormattedBody string `json:"formatted_body,omitempty"`
}
-// ImageInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
-type ImageInfo struct {
+// ThumbnailInfo contains info about an thumbnail image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
+type ThumbnailInfo struct {
Height uint `json:"h,omitempty"`
Width uint `json:"w,omitempty"`
Mimetype string `json:"mimetype,omitempty"`
Size uint `json:"size,omitempty"`
}
+// ImageInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
+type ImageInfo struct {
+ Height uint `json:"h,omitempty"`
+ Width uint `json:"w,omitempty"`
+ Mimetype string `json:"mimetype,omitempty"`
+ Size uint `json:"size,omitempty"`
+ ThumbnailInfo ThumbnailInfo `json:"thumbnail_info,omitempty"`
+ ThumbnailURL string `json:"thumbnail_url,omitempty"`
+}
+
// VideoInfo contains info about a video - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-video
type VideoInfo struct {
+ Mimetype string `json:"mimetype,omitempty"`
+ ThumbnailInfo ThumbnailInfo `json:"thumbnail_info"`
+ ThumbnailURL string `json:"thumbnail_url,omitempty"`
+ Height uint `json:"h,omitempty"`
+ Width uint `json:"w,omitempty"`
+ Duration uint `json:"duration,omitempty"`
+ Size uint `json:"size,omitempty"`
+}
+
+// AudioInfo contains info about a file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio
+type AudioInfo struct {
+ Mimetype string `json:"mimetype,omitempty"`
+ Size uint `json:"size,omitempty"`
+ Duration uint `json:"duration,omitempty"`
+}
+
+// FileInfo contains info about a file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
+type FileInfo struct {
Mimetype string `json:"mimetype,omitempty"`
ThumbnailInfo ImageInfo `json:"thumbnail_info"`
ThumbnailURL string `json:"thumbnail_url,omitempty"`
- Height uint `json:"h,omitempty"`
- Width uint `json:"w,omitempty"`
- Duration uint `json:"duration,omitempty"`
Size uint `json:"size,omitempty"`
}
@@ -82,6 +108,22 @@ type ImageMessage struct {
Info ImageInfo `json:"info"`
}
+// AudioMessage is an m.audio event
+type AudioMessage struct {
+ MsgType string `json:"msgtype"`
+ Body string `json:"body"`
+ URL string `json:"url"`
+ Info AudioInfo `json:"info"`
+}
+
+// FileMessage is a m.file event
+type FileMessage struct {
+ MsgType string `json:"msgtype"`
+ Body string `json:"body"`
+ URL string `json:"url"`
+ Info FileInfo `json:"info"`
+}
+
// An HTMLMessage is the contents of a Matrix HTML formated message event.
type HTMLMessage struct {
Body string `json:"body"`
diff --git a/vendor/github.com/matterbridge/gomatrix/filter.go b/vendor/github.com/matterbridge/gomatrix/filter.go
index e4e76287..2a0c37fa 100644
--- a/vendor/github.com/matterbridge/gomatrix/filter.go
+++ b/vendor/github.com/matterbridge/gomatrix/filter.go
@@ -14,6 +14,8 @@
package gomatrix
+import "errors"
+
//Filter is used by clients to specify how the server should filter responses to e.g. sync requests
//Specified by: https://matrix.org/docs/spec/client_server/r0.2.0.html#filtering
type Filter struct {
@@ -21,23 +23,68 @@ type Filter struct {
EventFields []string `json:"event_fields,omitempty"`
EventFormat string `json:"event_format,omitempty"`
Presence FilterPart `json:"presence,omitempty"`
- Room struct {
- AccountData FilterPart `json:"account_data,omitempty"`
- Ephemeral FilterPart `json:"ephemeral,omitempty"`
- IncludeLeave bool `json:"include_leave,omitempty"`
- NotRooms []string `json:"not_rooms,omitempty"`
- Rooms []string `json:"rooms,omitempty"`
- State FilterPart `json:"state,omitempty"`
- Timeline FilterPart `json:"timeline,omitempty"`
- } `json:"room,omitempty"`
+ Room RoomFilter `json:"room,omitempty"`
+}
+
+// RoomFilter is used to define filtering rules for room events
+type RoomFilter struct {
+ AccountData FilterPart `json:"account_data,omitempty"`
+ Ephemeral FilterPart `json:"ephemeral,omitempty"`
+ IncludeLeave bool `json:"include_leave,omitempty"`
+ NotRooms []string `json:"not_rooms,omitempty"`
+ Rooms []string `json:"rooms,omitempty"`
+ State FilterPart `json:"state,omitempty"`
+ Timeline FilterPart `json:"timeline,omitempty"`
}
+// FilterPart is used to define filtering rules for specific categories of events
type FilterPart struct {
- NotRooms []string `json:"not_rooms,omitempty"`
- Rooms []string `json:"rooms,omitempty"`
- Limit *int `json:"limit,omitempty"`
- NotSenders []string `json:"not_senders,omitempty"`
- NotTypes []string `json:"not_types,omitempty"`
- Senders []string `json:"senders,omitempty"`
- Types []string `json:"types,omitempty"`
+ NotRooms []string `json:"not_rooms,omitempty"`
+ Rooms []string `json:"rooms,omitempty"`
+ Limit int `json:"limit,omitempty"`
+ NotSenders []string `json:"not_senders,omitempty"`
+ NotTypes []string `json:"not_types,omitempty"`
+ Senders []string `json:"senders,omitempty"`
+ Types []string `json:"types,omitempty"`
+ ContainsURL *bool `json:"contains_url,omitempty"`
+}
+
+// Validate checks if the filter contains valid property values
+func (filter *Filter) Validate() error {
+ if filter.EventFormat != "client" && filter.EventFormat != "federation" {
+ return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
+ }
+ return nil
+}
+
+// DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request
+func DefaultFilter() Filter {
+ return Filter{
+ AccountData: DefaultFilterPart(),
+ EventFields: nil,
+ EventFormat: "client",
+ Presence: DefaultFilterPart(),
+ Room: RoomFilter{
+ AccountData: DefaultFilterPart(),
+ Ephemeral: DefaultFilterPart(),
+ IncludeLeave: false,
+ NotRooms: nil,
+ Rooms: nil,
+ State: DefaultFilterPart(),
+ Timeline: DefaultFilterPart(),
+ },
+ }
+}
+
+// DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request
+func DefaultFilterPart() FilterPart {
+ return FilterPart{
+ NotRooms: nil,
+ Rooms: nil,
+ Limit: 20,
+ NotSenders: nil,
+ NotTypes: nil,
+ Senders: nil,
+ Types: nil,
+ }
}
diff --git a/vendor/github.com/matterbridge/gomatrix/responses.go b/vendor/github.com/matterbridge/gomatrix/responses.go
index fe0eeb32..7a3a4ce3 100644
--- a/vendor/github.com/matterbridge/gomatrix/responses.go
+++ b/vendor/github.com/matterbridge/gomatrix/responses.go
@@ -84,7 +84,7 @@ type RespUserInteractive struct {
Stages []string `json:"stages"`
} `json:"flows"`
Params map[string]interface{} `json:"params"`
- Session string `json:"string"`
+ Session string `json:"session"`
Completed []string `json:"completed"`
ErrCode string `json:"errcode"`
Error string `json:"error"`
@@ -168,6 +168,7 @@ type RespSync struct {
} `json:"rooms"`
}
+// RespTurnServer is the JSON response from a Turn Server
type RespTurnServer struct {
Username string `json:"username"`
Password string `json:"password"`
diff --git a/vendor/github.com/matterbridge/gomatrix/userids.go b/vendor/github.com/matterbridge/gomatrix/userids.go
index 23e78072..70002c5b 100644
--- a/vendor/github.com/matterbridge/gomatrix/userids.go
+++ b/vendor/github.com/matterbridge/gomatrix/userids.go
@@ -125,6 +125,6 @@ func ExtractUserLocalpart(userID string) (string, error) {
}
return strings.TrimPrefix(
strings.SplitN(userID, ":", 2)[0], // @foo:bar:8448 => [ "@foo", "bar:8448" ]
- "@", // remove "@" prefix
+ "@", // remove "@" prefix
), nil
}