diff options
Diffstat (limited to 'bridge')
-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 { |