From efec01a92f3d7c3aec3ada8bf873d728e349eee6 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Thu, 27 May 2021 15:44:54 -0400 Subject: Support sending file URLs (nctalk) (#1489) * nctalk: support sending file URLs Signed-off-by: Gary Kim * nctalk: reduce nesting Co-authored-by: Wim Signed-off-by: Gary Kim Co-authored-by: Wim --- bridge/nctalk/nctalk.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'bridge') 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 { -- cgit v1.2.3