Added SendFile function, and FileMessage and FileInfo data structs

This commit is contained in:
Donomii 2017-07-15 17:44:50 +02:00
parent 372e8fa06f
commit d0c8c3e5b0
2 changed files with 31 additions and 0 deletions

View File

@ -450,6 +450,21 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) {
TextMessage{"m.text", text}) TextMessage{"m.text", text})
} }
// 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
// FIXME add thumbnail support
func (cli *Client) SendFile(roomID, body, url, filename string, info FileInfo, thumb_info, thumb_url interface{}) (*RespSendEvent, error) {
return cli.SendMessageEvent(roomID, "m.room.message",
FileMessage{
MsgType: "m.file",
Body: body,
URL: url,
FileName: filename,
Info: info,
})
}
// SendImage sends an m.room.message event into the given room with a msgtype of m.image // 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 // See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image
func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) { func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) {

View File

@ -44,6 +44,12 @@ type TextMessage struct {
Body string `json:"body"` Body string `json:"body"`
} }
// FileInfo contains info about an image - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
type FileInfo struct {
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 // 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,omitempty"` Height uint `json:"h,omitempty"`
@ -71,6 +77,16 @@ type VideoMessage struct {
Info VideoInfo `json:"info"` Info VideoInfo `json:"info"`
} }
// FileMessage is an m.file event
type FileMessage struct {
MsgType string `json:"msgtype"`
Body string `json:"body"`
URL string `json:"url"`
FileName string `json:"filename"`
Info FileInfo `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"`