diff options
author | Gary Kim <gary@garykim.dev> | 2020-10-19 17:16:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 23:16:34 +0200 |
commit | 950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8 (patch) | |
tree | a6071c7741df26ae883aa8f791df141786dc7580 /bridge | |
parent | 25c82ddf023a9f16ff2ef31093ee215b69c345be (diff) | |
download | matterbridge-msglm-950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8.tar.gz matterbridge-msglm-950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8.tar.bz2 matterbridge-msglm-950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8.zip |
Add support for downloading files (nctalk) (#1249)
Signed-off-by: Gary Kim <gary@garykim.dev>
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/nctalk/nctalk.go | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/bridge/nctalk/nctalk.go b/bridge/nctalk/nctalk.go index 23b59135..6af819af 100644 --- a/bridge/nctalk/nctalk.go +++ b/bridge/nctalk/nctalk.go @@ -9,7 +9,6 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" - talk "gomod.garykim.dev/nc-talk" "gomod.garykim.dev/nc-talk/ocs" "gomod.garykim.dev/nc-talk/room" "gomod.garykim.dev/nc-talk/user" @@ -61,8 +60,12 @@ func (b *Btalk) Disconnect() error { } func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { + tr, err := room.NewTalkRoom(b.user, channel.Name) + if err != nil { + return err + } newRoom := Broom{ - room: talk.NewRoom(b.user, channel.Name), + room: tr, } newRoom.ctx, newRoom.ctxCancel = context.WithCancel(context.Background()) c, err := newRoom.room.ReceiveMessages(newRoom.ctx) @@ -79,6 +82,7 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { go func() { for msg := range c { + msg := msg // ignore messages that are one of the following // * not a message from a user // * from ourselves @@ -97,6 +101,15 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error { if msg.ID != 0 { remoteMessage.ID = strconv.Itoa(msg.ID) } + + // Handle Files + err = b.handleFiles(&remoteMessage, &msg) + if err != nil { + b.Log.Errorf("Error handling file: %#v", msg) + + continue + } + b.Log.Debugf("<= Message is %#v", remoteMessage) b.Remote <- remoteMessage } @@ -132,6 +145,31 @@ func (b *Btalk) getRoom(token string) *Broom { return nil } +func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageData) error { + for _, parameter := range message.MessageParameters { + if parameter.Type == ocs.ROSTypeFile { + // Get the file + file, err := b.user.DownloadFile(parameter.Path) + if err != nil { + return err + } + + if mmsg.Extra == nil { + mmsg.Extra = make(map[string][]interface{}) + } + + mmsg.Extra["file"] = append(mmsg.Extra["file"], config.FileInfo{ + Name: parameter.Name, + Data: file, + Size: int64(len(*file)), + Avatar: false, + }) + } + } + + return nil +} + // Spec: https://github.com/nextcloud/server/issues/1706#issue-182308785 func formatRichObjectString(message string, parameters map[string]ocs.RichObjectString) string { for id, parameter := range parameters { @@ -142,7 +180,7 @@ func formatRichObjectString(message string, parameters map[string]ocs.RichObject text = "@" + text case ocs.ROSTypeFile: if parameter.Link != "" { - text = parameter.Link + text = parameter.Name } } |