From 192fe89789cb8d35b0be990b7fb9eb4ae2be9d60 Mon Sep 17 00:00:00 2001 From: David Hill Date: Sat, 15 Dec 2018 16:57:54 -0500 Subject: Populate user on channel join (slack) (#644) --- bridge/slack/handlers.go | 3 +++ bridge/slack/helpers.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index 89c800da..b9011c92 100644 --- a/bridge/slack/handlers.go +++ b/bridge/slack/handlers.go @@ -89,7 +89,10 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) { b.Log.Fatalf("Invalid Token %#v", ev) case *slack.ConnectionErrorEvent: b.Log.Errorf("Connection failed %#v %#v", ev.Error(), ev.ErrorObj) + case *slack.MemberJoinedChannelEvent: + b.populateUser(ev.User) default: + b.Log.Debugf("Unhandled incoming event: %T", ev) } } } diff --git a/bridge/slack/helpers.go b/bridge/slack/helpers.go index ff039c58..6f049561 100644 --- a/bridge/slack/helpers.go +++ b/bridge/slack/helpers.go @@ -63,6 +63,26 @@ func (b *Bslack) getChannelBy(lookupKey string, lookupMap map[string]*slack.Chan const minimumRefreshInterval = 10 * time.Second +func (b *Bslack) populateUser(userID string) { + b.usersMutex.RLock() + _, exists := b.users[userID] + b.usersMutex.RUnlock() + if exists { + // already in cache + return + } + + user, err := b.sc.GetUserInfo(userID) + if err != nil { + b.Log.Debugf("GetUserInfo failed for %v: %v", userID, err) + return + } + + b.usersMutex.Lock() + b.users[userID] = user + b.usersMutex.Unlock() +} + func (b *Bslack) populateUsers() { b.refreshMutex.Lock() if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress { -- cgit v1.2.3