summaryrefslogtreecommitdiffstats
path: root/bridge/slack/handlers.go
diff options
context:
space:
mode:
authorJerry Heiselman <jheiselman@users.noreply.github.com>2018-12-19 15:01:05 -0600
committerWim <wim@42.be>2018-12-19 22:01:05 +0100
commitd82726cd1bafc4adbf4fd55b0200b853d5633e6d (patch)
tree13b1e603664af354f7c6edaa0f920f77e5b0be75 /bridge/slack/handlers.go
parent288f0a06bb7c0d9a9805697eb0cd71448cbeaaff (diff)
downloadmatterbridge-msglm-d82726cd1bafc4adbf4fd55b0200b853d5633e6d.tar.gz
matterbridge-msglm-d82726cd1bafc4adbf4fd55b0200b853d5633e6d.tar.bz2
matterbridge-msglm-d82726cd1bafc4adbf4fd55b0200b853d5633e6d.zip
Try downloading files again if slack is too slow (slack). Closes #655 (#656)
Diffstat (limited to 'bridge/slack/handlers.go')
-rw-r--r--bridge/slack/handlers.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go
index 40a9666a..be3951e5 100644
--- a/bridge/slack/handlers.go
+++ b/bridge/slack/handlers.go
@@ -257,7 +257,7 @@ func (b *Bslack) handleAttachments(ev *slack.MessageEvent, rmsg *config.Message)
// If we have files attached, download them (in memory) and put a pointer to it in msg.Extra.
for i := range ev.Files {
- if err := b.handleDownloadFile(rmsg, &ev.Files[i]); err != nil {
+ if err := b.handleDownloadFile(rmsg, &ev.Files[i], false); err != nil {
b.Log.Errorf("Could not download incoming file: %#v", err)
}
}
@@ -276,7 +276,7 @@ func (b *Bslack) handleTypingEvent(ev *slack.UserTypingEvent) (*config.Message,
}
// handleDownloadFile handles file download
-func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File) error {
+func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File, retry bool) error {
if b.fileCached(file) {
return nil
}
@@ -292,6 +292,12 @@ func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File) erro
return fmt.Errorf("download %s failed %#v", file.URLPrivateDownload, err)
}
+ if len(*data) != file.Size && !retry {
+ b.Log.Debugf("Data size (%d) is not equal to size declared (%d)\n", len(*data), file.Size)
+ time.Sleep(1 * time.Second)
+ return b.handleDownloadFile(rmsg, file, true)
+ }
+
// If a comment is attached to the file(s) it is in the 'Text' field of the Slack messge event
// and should be added as comment to only one of the files. We reset the 'Text' field to ensure
// that the comment is not duplicated.