Merge pull request #26 from matrix-org/videos

SendImage and SendVideo convenience functions
This commit is contained in:
Richard Lewis 2017-05-08 13:59:41 +01:00 committed by GitHub
commit 462346e69d
2 changed files with 42 additions and 1 deletions

View File

@ -450,6 +450,28 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) {
TextMessage{"m.text", text}) TextMessage{"m.text", text})
} }
// SendImage sends an m.room.message event into the given room with a msgtype of m.image
// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {
return cli.SendMessageEvent(roomID, "m.room.message",
ImageMessage{
MsgType: "m.image",
Body: body,
URL: url,
})
}
// SendVideo sends an m.room.message event into the given room with a msgtype of m.video
// See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-video
func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) {
return cli.SendMessageEvent(roomID, "m.room.message",
VideoMessage{
MsgType: "m.video",
Body: body,
URL: url,
})
}
// SendNotice sends an m.room.message event into the given room with a msgtype of m.notice // 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 // See http://matrix.org/docs/spec/client_server/r0.2.0.html#m-notice
func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error) { func (cli *Client) SendNotice(roomID, text string) (*RespSendEvent, error) {

View File

@ -44,7 +44,7 @@ type TextMessage struct {
Body string `json:"body"` Body string `json:"body"`
} }
// ImageInfo contains info about an image // ImageInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
type ImageInfo struct { type ImageInfo struct {
Height uint `json:"h"` Height uint `json:"h"`
Width uint `json:"w"` Width uint `json:"w"`
@ -52,6 +52,25 @@ type ImageInfo struct {
Size uint `json:"size"` Size uint `json:"size"`
} }
// 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"`
ThumbnailInfo ImageInfo `json:"thumbnail_info"`
ThumbnailURL string `json:"thumbnail_url"`
Height uint `json:"h"`
Width uint `json:"w"`
Duration uint `json:"duration"`
Size uint `json:"size"`
}
// 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"`
}
// ImageMessage is an m.image event // ImageMessage is an m.image event
type ImageMessage struct { type ImageMessage struct {
MsgType string `json:"msgtype"` MsgType string `json:"msgtype"`