Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit e390f6b908f5ba31d3caf02c14391a72a7ab4a6a Author: Wim <wim@42.be> Date: Fri Feb 23 00:49:32 2018 +0000 Add share support between slack instances. Closes #369 diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 422f0f4..a794591 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -1378 +1377 @@ func (b *Bslack) Send(msg config.Message) (string, error) {   if b.Config.WebhookURL != "" {   if msg.Extra != nil {   for _, rmsg := range helper.HandleExtra(&msg, b.General) { - matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL, Channel: channel, UserName: rmsg.Username, - Text: rmsg.Text} + matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL, Channel: channel, UserName: rmsg.Username, Text: rmsg.Text}   b.mh.Send(matterMessage)   }   if len(msg.Extra["file"]) > 0 { @@ -1508 +14915 @@ func (b *Bslack) Send(msg config.Message) (string, error) {   }   }   } + // if we have native slack_attachments add them + var attachs []slack.Attachment + if len(msg.Extra["slack_attachment"]) > 0 { + for _, attach := range msg.Extra["slack_attachment"] { + attachs = append(attachs, attach.([]slack.Attachment)...) + } + }   - matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL} + matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL, Attachments: attachs}   matterMessage.Channel = channel   matterMessage.UserName = nick   matterMessage.Type = "" @@ -1786 +18411 @@ func (b *Bslack) Send(msg config.Message) (string, error) {   }   np.Attachments = append(np.Attachments, slack.Attachment{CallbackID: "matterbridge"})   np.Attachments = append(np.Attachments, b.createAttach(msg.Extra)...) + if len(msg.Extra["slack_attachment"]) > 0 { + for _, attach := range msg.Extra["slack_attachment"] { + np.Attachments = append(np.Attachments, attach.([]slack.Attachment)...) + } + }     // replace mentions   np.LinkNames = 1 @@ -3086 +31911 @@ func (b *Bslack) handleSlack() {   msg.Event = config.EVENT_TOPIC_CHANGE   }   + // save the attachments, so that we can send them to other slack (compatible) bridges + if len(message.Raw.Attachments) > 0 { + msg.Extra["slack_attachment"] = append(msg.Extra["slack_attachment"], message.Raw.Attachments) + } +   // if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra   if message.Raw.File != nil {   // limit to 1MB for now