From d0c8c3e5b08547b0dda8cba1a3a8826066e5daf2 Mon Sep 17 00:00:00 2001 From: Donomii Date: Sat, 15 Jul 2017 17:44:50 +0200 Subject: [PATCH] Added SendFile function, and FileMessage and FileInfo data structs --- client.go | 15 +++++++++++++++ events.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/client.go b/client.go index b07ee20..1a622d6 100644 --- a/client.go +++ b/client.go @@ -450,6 +450,21 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) { 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 // See https://matrix.org/docs/spec/client_server/r0.2.0.html#m-image func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) { diff --git a/events.go b/events.go index 7427740..0ce8278 100644 --- a/events.go +++ b/events.go @@ -44,6 +44,12 @@ type TextMessage struct { 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 type ImageInfo struct { Height uint `json:"h,omitempty"` @@ -71,6 +77,16 @@ type VideoMessage struct { 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 type ImageMessage struct { MsgType string `json:"msgtype"`