From 0929535b2e44a01ac8085adfa4e2fd3b9c1599ef Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 25 Nov 2018 00:34:14 +0100 Subject: [PATCH 1/2] Do not post empty messages (slack). Fixes #574 --- bridge/slack/slack.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 0951fb10..307a9023 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -356,6 +356,10 @@ func (b *Bslack) editMessage(msg *config.Message, channelInfo *slack.Channel) (b } func (b *Bslack) postMessage(msg *config.Message, messageParameters *slack.PostMessageParameters, channelInfo *slack.Channel) (string, error) { + // don't post empty messages + if msg.Text == "" { + return "", nil + } for { _, id, err := b.rtm.PostMessage(channelInfo.ID, msg.Text, *messageParameters) if err == nil { From f00d4d7d3fe1c3b9366951f461a3f695ebb892fd Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 25 Nov 2018 00:23:42 +0100 Subject: [PATCH 2/2] Make sure threaded files stay in thread (slack). Fixes #590 --- bridge/slack/slack.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 307a9023..ad48edf0 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -389,11 +389,16 @@ func (b *Bslack) uploadFile(msg *config.Message, channelID string) { ts := time.Now() b.Log.Debugf("Adding file %s to cache at %s with timestamp", fi.Name, ts.String()) b.cache.Add("filename"+fi.Name, ts) + initialComment := fmt.Sprintf("File from %s", msg.Username) + if fi.Comment != "" { + initialComment += fmt.Sprintf("with comment: %s", fi.Comment) + } res, err := b.sc.UploadFile(slack.FileUploadParameters{ - Reader: bytes.NewReader(*fi.Data), - Filename: fi.Name, - Channels: []string{channelID}, - InitialComment: fi.Comment, + Reader: bytes.NewReader(*fi.Data), + Filename: fi.Name, + Channels: []string{channelID}, + InitialComment: initialComment, + ThreadTimestamp: msg.ParentID, }) if err != nil { b.Log.Errorf("uploadfile %#v", err)