summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuco van Amstel <duco.vanamstel@gmail.com>2018-11-08 19:07:21 +0000
committerWim <wim@42.be>2018-11-08 20:07:21 +0100
commitea86849a5855e58fd4633117416a21fde753751f (patch)
treef244438e4689064370b0405202f4dd321906c725
parent399789811ecab11f7dfb775f83d063b20167bb1d (diff)
downloadmatterbridge-msglm-ea86849a5855e58fd4633117416a21fde753751f.tar.gz
matterbridge-msglm-ea86849a5855e58fd4633117416a21fde753751f.tar.bz2
matterbridge-msglm-ea86849a5855e58fd4633117416a21fde753751f.zip
Fix Slack edit usernames (#570)
-rw-r--r--bridge/slack/handlers.go10
-rw-r--r--bridge/slack/helpers.go38
2 files changed, 29 insertions, 19 deletions
diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go
index 9bcafde6..4307e7b9 100644
--- a/bridge/slack/handlers.go
+++ b/bridge/slack/handlers.go
@@ -150,16 +150,6 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
return rmsg, nil
}
- // Handle 'edit' messages.
- if ev.SubMessage != nil && !b.GetBool(editDisableConfig) {
- rmsg.ID = "slack " + ev.SubMessage.Timestamp
- if ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
- b.Log.Debugf("SubMessage %#v", ev.SubMessage)
- rmsg.Username = ev.SubMessage.User
- rmsg.Text = ev.SubMessage.Text + b.GetString(editSuffixConfig)
- }
- }
-
b.handleAttachments(ev, rmsg)
// Verify that we have the right information and the message
diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go
index e46a71ab..19ac5d09 100644
--- a/bridge/slack/helpers.go
+++ b/bridge/slack/helpers.go
@@ -167,6 +167,15 @@ func (b *Bslack) populateReceivedMessage(ev *slack.MessageEvent) (*config.Messag
rmsg.Channel = "ID:" + channel.ID
}
+ // Handle 'edit' messages.
+ if ev.SubMessage != nil && !b.GetBool(editDisableConfig) {
+ rmsg.ID = "slack " + ev.SubMessage.Timestamp
+ if ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
+ b.Log.Debugf("SubMessage %#v", ev.SubMessage)
+ rmsg.Text = ev.SubMessage.Text + b.GetString(editSuffixConfig)
+ }
+ }
+
if err = b.populateMessageWithUserInfo(ev, rmsg); err != nil {
return nil, err
}
@@ -178,6 +187,8 @@ func (b *Bslack) populateMessageWithUserInfo(ev *slack.MessageEvent, rmsg *confi
return nil
}
+ // First, deal with bot-originating messages but only do so when not using webhooks: we
+ // would not be able to distinguish which bot would be sending them.
if ev.BotID != "" && b.GetString(outgoingWebhookConfig) == "" {
bot, err := b.rtm.GetBotInfo(ev.BotID)
if err != nil {
@@ -192,16 +203,25 @@ func (b *Bslack) populateMessageWithUserInfo(ev *slack.MessageEvent, rmsg *confi
}
}
+ // Second, deal with "real" users if we have the necessary information.
+ var userID string
if ev.User != "" {
- user := b.getUser(ev.User)
- if user == nil {
- return fmt.Errorf("could not find information for user with id %s", ev.User)
- }
- rmsg.UserID = user.ID
- rmsg.Username = user.Name
- if user.Profile.DisplayName != "" {
- rmsg.Username = user.Profile.DisplayName
- }
+ userID = ev.User
+ } else if ev.SubMessage != nil && ev.SubMessage.User != "" {
+ userID = ev.SubMessage.User
+ } else {
+ return nil
+ }
+
+ user := b.getUser(userID)
+ if user == nil {
+ return fmt.Errorf("could not find information for user with id %s", ev.User)
+ }
+
+ rmsg.UserID = user.ID
+ rmsg.Username = user.Name
+ if user.Profile.DisplayName != "" {
+ rmsg.Username = user.Profile.DisplayName
}
return nil
}