aboutsummaryrefslogtreecommitdiff
path: root/mxlib
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-21 15:57:53 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-21 15:57:53 +0100
commitddd5936fb1f92432123a9a30d1d3a1fa644a4f8e (patch)
tree6a06aac9b5e676a2987f4bf612abea5500155ea2 /mxlib
parent92d380aa86dfd3e60f5b8d826ec96c0fbc17614a (diff)
downloadeasybridge-ddd5936fb1f92432123a9a30d1d3a1fa644a4f8e.tar.gz
easybridge-ddd5936fb1f92432123a9a30d1d3a1fa644a4f8e.zip
Files&images Mattermost->Matrix works
Diffstat (limited to 'mxlib')
-rw-r--r--mxlib/client.go6
-rw-r--r--mxlib/mediaobject.go7
2 files changed, 13 insertions, 0 deletions
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 {