summaryrefslogtreecommitdiffstats
path: root/bridge/mattermost/mattermost.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-09-21 23:15:04 +0200
committerWim <wim@42.be>2017-09-21 23:15:04 +0200
commit7aabe12acfb054561b85c95f34169d734a28b1eb (patch)
treebfceacb4ffc956d8187adfbcdee83dcc8564317a /bridge/mattermost/mattermost.go
parentc4b75e5754c58758c920c79b0458171e98269961 (diff)
downloadmatterbridge-msglm-7aabe12acfb054561b85c95f34169d734a28b1eb.tar.gz
matterbridge-msglm-7aabe12acfb054561b85c95f34169d734a28b1eb.tar.bz2
matterbridge-msglm-7aabe12acfb054561b85c95f34169d734a28b1eb.zip
Fix loop, make megacheck happy
Diffstat (limited to 'bridge/mattermost/mattermost.go')
-rw-r--r--bridge/mattermost/mattermost.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index 985d0d76..3274d81d 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -180,18 +180,23 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
return msg.ID, b.mc.DeleteMessage(msg.ID)
}
if msg.Extra != nil {
- for _, f := range msg.Extra["file"] {
- fi := f.(config.FileInfo)
- id, err := b.mc.UploadFile(*fi.Data, b.mc.GetChannelId(channel, ""), fi.Name)
- if err != nil {
- flog.Debugf("ERROR %#v", err)
- return "", err
- }
- message = "uploaded a file: " + fi.Name
- if b.Config.PrefixMessagesWithNick {
- message = nick + "uploaded a file: " + fi.Name
+ if len(msg.Extra["file"]) > 0 {
+ var err error
+ var res, id string
+ for _, f := range msg.Extra["file"] {
+ fi := f.(config.FileInfo)
+ id, err = b.mc.UploadFile(*fi.Data, b.mc.GetChannelId(channel, ""), fi.Name)
+ if err != nil {
+ flog.Debugf("ERROR %#v", err)
+ return "", err
+ }
+ message = "uploaded a file: " + fi.Name
+ if b.Config.PrefixMessagesWithNick {
+ message = nick + "uploaded a file: " + fi.Name
+ }
+ res, err = b.mc.PostMessageWithFiles(b.mc.GetChannelId(channel, ""), message, []string{id})
}
- return b.mc.PostMessageWithFiles(b.mc.GetChannelId(channel, ""), message, []string{id})
+ return res, err
}
}
if msg.ID != "" {