From b06a574cc51feb7195c312ceabb5634275e66d97 Mon Sep 17 00:00:00 2001 From: "Jonathan Walker (Keenan)" Date: Sat, 16 Oct 2021 17:36:30 -0400 Subject: [PATCH] Invalidate user in cache on user change event (#1604) Co-authored-by: Wim --- bridge/slack/handlers.go | 2 ++ bridge/slack/users_channels.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index d05a358ca2..4dc57d0d6e 100644 --- a/bridge/slack/handlers.go +++ b/bridge/slack/handlers.go @@ -95,6 +95,8 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) { b.users.populateUser(ev.User) case *slack.HelloEvent, *slack.LatencyReport, *slack.ConnectingEvent: continue + case *slack.UserChangeEvent: + b.users.invalidateUser(ev.User.ID) default: b.Log.Debugf("Unhandled incoming event: %T", ev) } diff --git a/bridge/slack/users_channels.go b/bridge/slack/users_channels.go index 41fd0bd824..9b34b779d8 100644 --- a/bridge/slack/users_channels.go +++ b/bridge/slack/users_channels.go @@ -113,6 +113,12 @@ func (b *users) populateUser(userID string) { b.users[userID] = user } +func (b *users) invalidateUser(userID string) { + b.usersMutex.Lock() + defer b.usersMutex.Unlock() + delete(b.users, userID) +} + func (b *users) populateUsers(wait bool) { b.refreshMutex.Lock() if !wait && (time.Now().Before(b.earliestRefresh) || b.refreshInProgress) {