mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-25 00:41:37 +00:00
Populate user on channel join (slack) (#644)
This commit is contained in:
parent
b3999b6e71
commit
315a038e00
@ -89,7 +89,10 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
b.Log.Fatalf("Invalid Token %#v", ev)
|
b.Log.Fatalf("Invalid Token %#v", ev)
|
||||||
case *slack.ConnectionErrorEvent:
|
case *slack.ConnectionErrorEvent:
|
||||||
b.Log.Errorf("Connection failed %#v %#v", ev.Error(), ev.ErrorObj)
|
b.Log.Errorf("Connection failed %#v %#v", ev.Error(), ev.ErrorObj)
|
||||||
|
case *slack.MemberJoinedChannelEvent:
|
||||||
|
b.populateUser(ev.User)
|
||||||
default:
|
default:
|
||||||
|
b.Log.Debugf("Unhandled incoming event: %T", ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,26 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
|
|||||||
|
|
||||||
const minimumRefreshInterval = 10 * time.Second
|
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() {
|
func (b *Bslack) populateUsers() {
|
||||||
b.refreshMutex.Lock()
|
b.refreshMutex.Lock()
|
||||||
if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress {
|
if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress {
|
||||||
|
Loading…
Reference in New Issue
Block a user