Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35736bbbfe | ||
|
|
85fa4df39d | ||
|
|
859b084814 | ||
|
|
315a038e00 | ||
|
|
b3999b6e71 |
@@ -75,7 +75,7 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
// When we join a channel we update the full list of users as
|
// When we join a channel we update the full list of users as
|
||||||
// well as the information for the channel that we joined as this
|
// well as the information for the channel that we joined as this
|
||||||
// should now tell that we are a member of it.
|
// should now tell that we are a member of it.
|
||||||
b.populateUsers()
|
b.populateUsers(false)
|
||||||
|
|
||||||
b.channelsMutex.Lock()
|
b.channelsMutex.Lock()
|
||||||
b.channelsByID[ev.Channel.ID] = &ev.Channel
|
b.channelsByID[ev.Channel.ID] = &ev.Channel
|
||||||
@@ -83,13 +83,16 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
b.channelsMutex.Unlock()
|
b.channelsMutex.Unlock()
|
||||||
case *slack.ConnectedEvent:
|
case *slack.ConnectedEvent:
|
||||||
b.si = ev.Info
|
b.si = ev.Info
|
||||||
b.populateChannels()
|
b.populateChannels(true)
|
||||||
b.populateUsers()
|
b.populateUsers(true)
|
||||||
case *slack.InvalidAuthEvent:
|
case *slack.InvalidAuthEvent:
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +196,7 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
|
|||||||
func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message) bool {
|
func (b *Bslack) handleStatusEvent(ev *slack.MessageEvent, rmsg *config.Message) bool {
|
||||||
switch ev.SubType {
|
switch ev.SubType {
|
||||||
case sChannelJoined, sMemberJoined:
|
case sChannelJoined, sMemberJoined:
|
||||||
b.populateUsers()
|
b.populateUsers(false)
|
||||||
// There's no further processing needed on channel events
|
// There's no further processing needed on channel events
|
||||||
// so we return 'true'.
|
// so we return 'true'.
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -65,15 +65,38 @@ func (b *Bslack) getChannelByID(ID string) (*slack.Channel, error) {
|
|||||||
|
|
||||||
const minimumRefreshInterval = 10 * time.Second
|
const minimumRefreshInterval = 10 * time.Second
|
||||||
|
|
||||||
func (b *Bslack) populateUsers() {
|
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(wait bool) {
|
||||||
b.refreshMutex.Lock()
|
b.refreshMutex.Lock()
|
||||||
if time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress {
|
if !wait && (time.Now().Before(b.earliestUserRefresh) || b.refreshInProgress) {
|
||||||
b.Log.Debugf("Not refreshing user list as it was done less than %v ago.",
|
b.Log.Debugf("Not refreshing user list as it was done less than %v ago.",
|
||||||
minimumRefreshInterval)
|
minimumRefreshInterval)
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for b.refreshInProgress {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
b.refreshInProgress = true
|
b.refreshInProgress = true
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
@@ -109,14 +132,17 @@ func (b *Bslack) populateUsers() {
|
|||||||
b.refreshInProgress = false
|
b.refreshInProgress = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bslack) populateChannels() {
|
func (b *Bslack) populateChannels(wait bool) {
|
||||||
b.refreshMutex.Lock()
|
b.refreshMutex.Lock()
|
||||||
if time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress {
|
if !wait && (time.Now().Before(b.earliestChannelRefresh) || b.refreshInProgress) {
|
||||||
b.Log.Debugf("Not refreshing channel list as it was done less than %v seconds ago.",
|
b.Log.Debugf("Not refreshing channel list as it was done less than %v seconds ago.",
|
||||||
minimumRefreshInterval)
|
minimumRefreshInterval)
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for b.refreshInProgress {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
b.refreshInProgress = true
|
b.refreshInProgress = true
|
||||||
b.refreshMutex.Unlock()
|
b.refreshMutex.Unlock()
|
||||||
|
|
||||||
@@ -251,7 +277,7 @@ func (b *Bslack) populateMessageWithBotInfo(ev *slack.MessageEvent, rmsg *config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bot.Name != "" && bot.Name != "Slack API Tester" {
|
if bot.Name != "" {
|
||||||
rmsg.Username = bot.Name
|
rmsg.Username = bot.Name
|
||||||
if ev.Username != "" {
|
if ev.Username != "" {
|
||||||
rmsg.Username = ev.Username
|
rmsg.Username = ev.Username
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func (b *Bslack) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b.populateChannels()
|
b.populateChannels(false)
|
||||||
|
|
||||||
channelInfo, err := b.getChannel(channel.Name)
|
channelInfo, err := b.getChannel(channel.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# v1.12.3
|
||||||
|
## Bugfix
|
||||||
|
* slack: Fix bot (legacy token) messages not being send. Closes #571
|
||||||
|
* slack: Populate user on channel join (slack) (#644)
|
||||||
|
* slack: Add wait option for populateUsers/Channels (slack) Fixes #579 (#653)
|
||||||
|
|
||||||
# v1.12.2
|
# v1.12.2
|
||||||
|
|
||||||
## Bugfix
|
## Bugfix
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "1.12.2"
|
version = "1.12.3"
|
||||||
githash string
|
githash string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user