mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-18 17:12:37 +01:00
Add support for uploaded images/video/files (matrix)
This commit is contained in:
parent
34227a7a39
commit
cbd73ee313
@ -8,6 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
matrix "github.com/matrix-org/gomatrix"
|
matrix "github.com/matrix-org/gomatrix"
|
||||||
)
|
)
|
||||||
@ -144,7 +145,13 @@ func (b *Bmatrix) getRoomID(channel string) string {
|
|||||||
func (b *Bmatrix) handlematrix() error {
|
func (b *Bmatrix) handlematrix() error {
|
||||||
syncer := b.mc.Syncer.(*matrix.DefaultSyncer)
|
syncer := b.mc.Syncer.(*matrix.DefaultSyncer)
|
||||||
syncer.OnEventType("m.room.message", func(ev *matrix.Event) {
|
syncer.OnEventType("m.room.message", func(ev *matrix.Event) {
|
||||||
if (ev.Content["msgtype"].(string) == "m.text" || ev.Content["msgtype"].(string) == "m.notice" || ev.Content["msgtype"].(string) == "m.emote") && ev.Sender != b.UserID {
|
flog.Debugf("Received: %#v", ev)
|
||||||
|
if (ev.Content["msgtype"].(string) == "m.text" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.notice" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.emote" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.file" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.image" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.video") && ev.Sender != b.UserID {
|
||||||
b.RLock()
|
b.RLock()
|
||||||
channel, ok := b.RoomMap[ev.RoomID]
|
channel, ok := b.RoomMap[ev.RoomID]
|
||||||
b.RUnlock()
|
b.RUnlock()
|
||||||
@ -161,10 +168,31 @@ func (b *Bmatrix) handlematrix() error {
|
|||||||
if ev.Content["msgtype"].(string) == "m.emote" {
|
if ev.Content["msgtype"].(string) == "m.emote" {
|
||||||
rmsg.Event = config.EVENT_USER_ACTION
|
rmsg.Event = config.EVENT_USER_ACTION
|
||||||
}
|
}
|
||||||
|
if ev.Content["msgtype"].(string) == "m.image" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.video" ||
|
||||||
|
ev.Content["msgtype"].(string) == "m.file" {
|
||||||
|
flog.Debugf("ev: %#v", ev)
|
||||||
|
rmsg.Extra = make(map[string][]interface{})
|
||||||
|
url := ev.Content["url"].(string)
|
||||||
|
url = strings.Replace(url, "mxc://", b.Config.Server+"/_matrix/media/v1/download/", -1)
|
||||||
|
info := ev.Content["info"].(map[string]interface{})
|
||||||
|
size := info["size"].(float64)
|
||||||
|
name := ev.Content["body"].(string)
|
||||||
|
flog.Debugf("trying to download %#v with size %#v", name, size)
|
||||||
|
if size <= 1000000 {
|
||||||
|
data, err := helper.DownloadFile(url)
|
||||||
|
if err != nil {
|
||||||
|
flog.Errorf("download %s failed %#v", url, err)
|
||||||
|
} else {
|
||||||
|
flog.Debugf("download OK %#v %#v %#v", name, len(*data), len(url))
|
||||||
|
rmsg.Extra["file"] = append(rmsg.Extra["file"], config.FileInfo{Name: name, Data: data})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rmsg.Text = ""
|
||||||
|
}
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account)
|
flog.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account)
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
}
|
}
|
||||||
flog.Debugf("Received: %#v", ev)
|
|
||||||
})
|
})
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
@ -155,7 +155,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
if dest.Protocol != "discord" &&
|
if dest.Protocol != "discord" &&
|
||||||
dest.Protocol != "slack" &&
|
dest.Protocol != "slack" &&
|
||||||
dest.Protocol != "mattermost" &&
|
dest.Protocol != "mattermost" &&
|
||||||
dest.Protocol != "telegram" {
|
dest.Protocol != "telegram" &&
|
||||||
|
dest.Protocol != "matrix" {
|
||||||
if msg.Text == "" {
|
if msg.Text == "" {
|
||||||
return brMsgIDs
|
return brMsgIDs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user