5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-09-19 15:49:36 +00:00

Populate user on channel join (slack) (#644)

This commit is contained in:
David Hill 2018-12-15 16:57:54 -05:00 committed by Wim
parent 959ca3cef3
commit 192fe89789
2 changed files with 23 additions and 0 deletions

View File

@ -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)
}
}
}

View File

@ -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 {