diff options
author | David Hill <dhill@mindcry.org> | 2018-12-15 16:57:54 -0500 |
---|---|---|
committer | Wim <wim@42.be> | 2018-12-15 23:13:53 +0100 |
commit | 315a038e001ead142e93eb104bd71d062a0391a2 (patch) | |
tree | cd6729264cbb068ff65382a114da903ad9c9b2f7 | |
parent | b3999b6e7188262006c8c0df806a5dfe53977e8d (diff) | |
download | matterbridge-msglm-315a038e001ead142e93eb104bd71d062a0391a2.tar.gz matterbridge-msglm-315a038e001ead142e93eb104bd71d062a0391a2.tar.bz2 matterbridge-msglm-315a038e001ead142e93eb104bd71d062a0391a2.zip |
Populate user on channel join (slack) (#644)
-rw-r--r-- | bridge/slack/handlers.go | 3 | ||||
-rw-r--r-- | bridge/slack/helpers.go | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/bridge/slack/handlers.go b/bridge/slack/handlers.go index 035c5af5..609fff18 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 26a4748e..a03feb7b 100644 --- a/bridge/slack/helpers.go +++ b/bridge/slack/helpers.go @@ -65,6 +65,26 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) { 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 { |