From 96620a3c2c3ab70d0e451a19dccd20ee76416937 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 29 Oct 2016 21:05:33 +0200 Subject: [PATCH] Drop first received message on connection to avoid duplicates (slack). Fixes #55 --- bridge/slack/slack.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 5c28172c..f9432863 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -157,23 +157,29 @@ func (b *Bslack) handleSlack() { } func (b *Bslack) handleSlackClient(mchan chan *MMMessage) { + count := 0 for msg := range b.rtm.IncomingEvents { switch ev := msg.Data.(type) { case *slack.MessageEvent: - flog.Debugf("Receiving from slackclient %#v", ev) - channel, err := b.rtm.GetChannelInfo(ev.Channel) - if err != nil { - continue + // ignore first message + if count > 0 { + flog.Debugf("Receiving from slackclient %#v", ev) + //ev.ReplyTo + channel, err := b.rtm.GetChannelInfo(ev.Channel) + if err != nil { + continue + } + user, err := b.rtm.GetUserInfo(ev.User) + if err != nil { + continue + } + m := &MMMessage{} + m.Username = user.Name + m.Channel = channel.Name + m.Text = ev.Text + mchan <- m } - user, err := b.rtm.GetUserInfo(ev.User) - if err != nil { - continue - } - m := &MMMessage{} - m.Username = user.Name - m.Channel = channel.Name - m.Text = ev.Text - mchan <- m + count++ case *slack.OutgoingErrorEvent: flog.Debugf("%#v", ev.Error()) case *slack.ConnectedEvent: