From a3470f8aec6f38efbb80f9bf2ec0776421e687de Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 7 Sep 2017 23:47:23 +0200 Subject: Send first message after connect (slack). Closes #252 --- bridge/slack/slack.go | 89 ++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 47 deletions(-) (limited to 'bridge') diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index e681c784..68ff8f8b 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -257,65 +257,60 @@ 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: - // ignore first message - if count > 0 { - flog.Debugf("Receiving from slackclient %#v", ev) - if len(ev.Attachments) > 0 { - // skip messages we made ourselves - if ev.Attachments[0].CallbackID == "matterbridge" { - continue - } - } - if !b.Config.EditDisable && ev.SubMessage != nil && ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp { - flog.Debugf("SubMessage %#v", ev.SubMessage) - ev.User = ev.SubMessage.User - ev.Text = ev.SubMessage.Text + b.Config.EditSuffix + flog.Debugf("Receiving from slackclient %#v", ev) + if len(ev.Attachments) > 0 { + // skip messages we made ourselves + if ev.Attachments[0].CallbackID == "matterbridge" { + continue } - // use our own func because rtm.GetChannelInfo doesn't work for private channels - channel, err := b.getChannelByID(ev.Channel) + } + if !b.Config.EditDisable && ev.SubMessage != nil && ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp { + flog.Debugf("SubMessage %#v", ev.SubMessage) + ev.User = ev.SubMessage.User + ev.Text = ev.SubMessage.Text + b.Config.EditSuffix + } + // use our own func because rtm.GetChannelInfo doesn't work for private channels + channel, err := b.getChannelByID(ev.Channel) + if err != nil { + continue + } + m := &MMMessage{} + if ev.BotID == "" { + user, err := b.rtm.GetUserInfo(ev.User) if err != nil { continue } - m := &MMMessage{} - if ev.BotID == "" { - user, err := b.rtm.GetUserInfo(ev.User) - if err != nil { - continue + m.UserID = user.ID + m.Username = user.Name + } + m.Channel = channel.Name + m.Text = ev.Text + if m.Text == "" { + for _, attach := range ev.Attachments { + if attach.Text != "" { + m.Text = attach.Text + } else { + m.Text = attach.Fallback } - m.UserID = user.ID - m.Username = user.Name } - m.Channel = channel.Name - m.Text = ev.Text - if m.Text == "" { - for _, attach := range ev.Attachments { - if attach.Text != "" { - m.Text = attach.Text - } else { - m.Text = attach.Fallback - } - } + } + m.Raw = ev + m.Text = b.replaceMention(m.Text) + // when using webhookURL we can't check if it's our webhook or not for now + if ev.BotID != "" && b.Config.WebhookURL == "" { + bot, err := b.rtm.GetBotInfo(ev.BotID) + if err != nil { + continue } - m.Raw = ev - m.Text = b.replaceMention(m.Text) - // when using webhookURL we can't check if it's our webhook or not for now - if ev.BotID != "" && b.Config.WebhookURL == "" { - bot, err := b.rtm.GetBotInfo(ev.BotID) - if err != nil { - continue - } - if bot.Name != "" { - m.Username = bot.Name - m.UserID = bot.ID - } + if bot.Name != "" { + m.Username = bot.Name + m.UserID = bot.ID } - mchan <- m } - count++ + mchan <- m case *slack.OutgoingErrorEvent: flog.Debugf("%#v", ev.Error()) case *slack.ChannelJoinedEvent: -- cgit v1.2.3