From ddd5936fb1f92432123a9a30d1d3a1fa644a4f8e Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 21 Feb 2020 15:57:53 +0100 Subject: Files&images Mattermost->Matrix works --- mxlib/client.go | 6 ++++++ mxlib/mediaobject.go | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'mxlib') diff --git a/mxlib/client.go b/mxlib/client.go index 6d87663..d8237d1 100644 --- a/mxlib/client.go +++ b/mxlib/client.go @@ -280,6 +280,11 @@ func (mx *Client) RoomTopicAs(room string, topic string, as_user string) error { } func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { + // Return early if this is already a Matrix media object + if mxm, ok := m.(*MediaObject); ok { + return mxm, nil + } + reader, err := m.Read() if err != nil { return nil, err @@ -308,6 +313,7 @@ func (mx *Client) UploadMedia(m connector.MediaObject) (*MediaObject, error) { filename: m.Filename(), size: m.Size(), mimetype: m.Mimetype(), + imageSize: m.ImageSize(), MxcServer: mxc[0], MxcMediaId: mxc[1], } diff --git a/mxlib/mediaobject.go b/mxlib/mediaobject.go index 8a730d2..1c35187 100644 --- a/mxlib/mediaobject.go +++ b/mxlib/mediaobject.go @@ -5,6 +5,8 @@ import ( "fmt" "net/url" "net/http" + + "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) type MediaObject struct { @@ -12,6 +14,7 @@ type MediaObject struct { filename string size int64 mimetype string + imageSize *connector.ImageSize MxcServer string MxcMediaId string } @@ -28,6 +31,10 @@ func (m *MediaObject) Mimetype() string { return m.mimetype } +func (m *MediaObject) ImageSize() *connector.ImageSize { + return m.imageSize +} + func (m *MediaObject) Read() (io.ReadCloser, error) { req, err := http.NewRequest("GET", m.URL(), nil) if err != nil { -- cgit v1.2.3