diff options
author | Alexander <korelskiy@uteka.ru> | 2022-03-30 23:22:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-30 22:22:37 +0200 |
commit | d7b7ff7bb49e1e808de7d417ebd882b46bd6251b (patch) | |
tree | 293a1f9b7ad3bbaae6c285a5d643d5cb9b3c62ed | |
parent | 6fe0cff342e701aabc069a9b2ea2ec2d26006f8b (diff) | |
download | matterbridge-msglm-d7b7ff7bb49e1e808de7d417ebd882b46bd6251b.tar.gz matterbridge-msglm-d7b7ff7bb49e1e808de7d417ebd882b46bd6251b.tar.bz2 matterbridge-msglm-d7b7ff7bb49e1e808de7d417ebd882b46bd6251b.zip |
Preserve threading for messages with files (slack) (#1781)
* Preserve threading for slack messages with files
* Update bridge/slack/slack.go
Co-authored-by: Wim <wim@42.be>
-rw-r--r-- | bridge/slack/slack.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 55231c38..c39c6082 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -321,7 +321,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { } // Upload a file if it exists. - if msg.Extra != nil { + if len(msg.Extra) > 0 { extraMsgs := helper.HandleExtra(&msg, b.General) for i := range extraMsgs { rmsg := &extraMsgs[i] @@ -332,7 +332,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { } } // Upload files if necessary (from Slack, Telegram or Mattermost). - b.uploadFile(&msg, channelInfo.ID) + return b.uploadFile(&msg, channelInfo.ID) } // Post message. @@ -443,7 +443,8 @@ func (b *Bslack) postMessage(msg *config.Message, channelInfo *slack.Channel) (s } // uploadFile handles native upload of files -func (b *Bslack) uploadFile(msg *config.Message, channelID string) { +func (b *Bslack) uploadFile(msg *config.Message, channelID string) (string, error) { + var messageID string for _, f := range msg.Extra["file"] { fi, ok := f.(config.FileInfo) if !ok { @@ -471,13 +472,22 @@ func (b *Bslack) uploadFile(msg *config.Message, channelID string) { }) if err != nil { b.Log.Errorf("uploadfile %#v", err) - return + return "", err } if res.ID != "" { b.Log.Debugf("Adding file ID %s to cache with timestamp %s", res.ID, ts.String()) b.cache.Add("file"+res.ID, ts) + + // search for message id by uploaded file in private/public channels, get thread timestamp from uploaded file + if v, ok := res.Shares.Private[channelID]; ok && len(v) > 0 { + messageID = v[0].Ts + } + if v, ok := res.Shares.Public[channelID]; ok && len(v) > 0 { + messageID = v[0].Ts + } } } + return messageID, nil } func (b *Bslack) prepareMessageOptions(msg *config.Message) []slack.MsgOption { |