From 4bc46014aeb6693fe9193ae0d63c77efd5bc16db Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Tue, 25 Apr 2017 11:02:33 +0100 Subject: [PATCH 1/3] Functions to send basic image and video events --- client.go | 22 ++++++++++++++++++++++ events.go | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/client.go b/client.go index f916174..f560932 100644 --- a/client.go +++ b/client.go @@ -450,6 +450,28 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) { 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 string, 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 string, url string) (*RespSendEvent, error) { + return cli.SendMessageEvent(roomID, "m.room.message", + VideoMessage{ + MsgType: "m.video", + Body: body, + URL: url, + }) +} + // RedactEvent redacts the given event. See http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid func (cli *Client) RedactEvent(roomID, eventID string, req *ReqRedact) (resp *RespSendEvent, err error) { txnID := txnID() diff --git a/events.go b/events.go index 6355444..25a5f9c 100644 --- a/events.go +++ b/events.go @@ -52,6 +52,25 @@ type ImageInfo struct { Size uint `json:"size"` } +// VideoInfo contains info about a 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 event +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 type ImageMessage struct { MsgType string `json:"msgtype"` From 63c361cb6176a2c30f081bb4a428270c1fa86dae Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 8 May 2017 10:57:04 +0100 Subject: [PATCH 2/3] Fix function signature --- client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index f560932..a18204a 100644 --- a/client.go +++ b/client.go @@ -452,7 +452,7 @@ func (cli *Client) SendText(roomID, text string) (*RespSendEvent, error) { // 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 string, url string) (*RespSendEvent, error) { +func (cli *Client) SendImage(roomID, body, url string) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, "m.room.message", ImageMessage{ MsgType: "m.image", @@ -463,7 +463,7 @@ func (cli *Client) SendImage(roomID, body string, url string) (*RespSendEvent, e // 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 string, url string) (*RespSendEvent, error) { +func (cli *Client) SendVideo(roomID, body, url string) (*RespSendEvent, error) { return cli.SendMessageEvent(roomID, "m.room.message", VideoMessage{ MsgType: "m.video", From 8132e161ec6f66eeeadafcdb2fac3e0303a29af3 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 8 May 2017 11:23:22 +0100 Subject: [PATCH 3/3] Add links to docs. --- events.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/events.go b/events.go index 25a5f9c..abc5cd4 100644 --- a/events.go +++ b/events.go @@ -44,7 +44,7 @@ type TextMessage struct { 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 { Height uint `json:"h"` Width uint `json:"w"` @@ -52,7 +52,7 @@ type ImageInfo struct { Size uint `json:"size"` } -// VideoInfo contains info about a video +// 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"` @@ -63,7 +63,7 @@ type VideoInfo struct { Size uint `json:"size"` } -// VideoMessage is an m.video event +// 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"`