mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-26 03:11:37 +00:00
Fix Slack edit usernames (#570)
This commit is contained in:
parent
399789811e
commit
ea86849a58
@ -150,16 +150,6 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
|
|||||||
return rmsg, nil
|
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)
|
b.handleAttachments(ev, rmsg)
|
||||||
|
|
||||||
// Verify that we have the right information and the message
|
// Verify that we have the right information and the message
|
||||||
|
@ -167,6 +167,15 @@ func (b *Bslack) populateReceivedMessage(ev *slack.MessageEvent) (*config.Messag
|
|||||||
rmsg.Channel = "ID:" + channel.ID
|
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 {
|
if err = b.populateMessageWithUserInfo(ev, rmsg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -178,6 +187,8 @@ func (b *Bslack) populateMessageWithUserInfo(ev *slack.MessageEvent, rmsg *confi
|
|||||||
return nil
|
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) == "" {
|
if ev.BotID != "" && b.GetString(outgoingWebhookConfig) == "" {
|
||||||
bot, err := b.rtm.GetBotInfo(ev.BotID)
|
bot, err := b.rtm.GetBotInfo(ev.BotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -192,17 +203,26 @@ 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 != "" {
|
if ev.User != "" {
|
||||||
user := b.getUser(ev.User)
|
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 {
|
if user == nil {
|
||||||
return fmt.Errorf("could not find information for user with id %s", ev.User)
|
return fmt.Errorf("could not find information for user with id %s", ev.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
rmsg.UserID = user.ID
|
rmsg.UserID = user.ID
|
||||||
rmsg.Username = user.Name
|
rmsg.Username = user.Name
|
||||||
if user.Profile.DisplayName != "" {
|
if user.Profile.DisplayName != "" {
|
||||||
rmsg.Username = user.Profile.DisplayName
|
rmsg.Username = user.Profile.DisplayName
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user