diff options
author | Gary Kim <gary@garykim.dev> | 2021-05-27 15:44:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-27 21:44:54 +0200 |
commit | efec01a92f3d7c3aec3ada8bf873d728e349eee6 (patch) | |
tree | c6f6b94d83386a3fdbb1aa75d7e1c0f336e120ad /bridge/nctalk/nctalk.go | |
parent | 4fcad8e04befeec2c7e468b36500fa33eb22af51 (diff) | |
download | matterbridge-msglm-efec01a92f3d7c3aec3ada8bf873d728e349eee6.tar.gz matterbridge-msglm-efec01a92f3d7c3aec3ada8bf873d728e349eee6.tar.bz2 matterbridge-msglm-efec01a92f3d7c3aec3ada8bf873d728e349eee6.zip |
Support sending file URLs (nctalk) (#1489)
* nctalk: support sending file URLs
Signed-off-by: Gary Kim <gary@garykim.dev>
* nctalk: reduce nesting
Co-authored-by: Wim <wim@42.be>
Signed-off-by: Gary Kim <gary@garykim.dev>
Co-authored-by: Wim <wim@42.be>
Diffstat (limited to 'bridge/nctalk/nctalk.go')
-rw-r--r-- | bridge/nctalk/nctalk.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bridge/nctalk/nctalk.go b/bridge/nctalk/nctalk.go index 2f12e4e2..4537989c 100644 --- a/bridge/nctalk/nctalk.go +++ b/bridge/nctalk/nctalk.go @@ -135,9 +135,19 @@ func (b *Btalk) Send(msg config.Message) (string, error) { if msg.Event != "" { return "", nil } + + // Handle sending files if they are included + err := b.handleSendingFile(&msg, r) + if err != nil { + b.Log.Errorf("Could not send files in message to room %v from %v: %v", msg.Channel, msg.Username, err) + + return "", nil + } + sentMessage, err := r.room.SendMessage(msg.Username + msg.Text) if err != nil { b.Log.Errorf("Could not send message to room %v from %v: %v", msg.Channel, msg.Username, err) + return "", nil } return strconv.Itoa(sentMessage.ID), nil @@ -177,6 +187,27 @@ func (b *Btalk) handleFiles(mmsg *config.Message, message *ocs.TalkRoomMessageDa return nil } +func (b *Btalk) handleSendingFile(msg *config.Message, r *Broom) error { + for _, f := range msg.Extra["file"] { + fi := f.(config.FileInfo) + if fi.URL == "" { + continue + } + + message := msg.Username + if fi.Comment != "" { + message += fi.Comment + " " + } + message += fi.URL + _, err := r.room.SendMessage(message) + if err != nil { + return err + } + } + + 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 { |