mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Prevent divide by zero if there are no hubs (#8763)
This commit is contained in:
committed by
Derrick Anderson
parent
823b22c403
commit
68340d4715
@@ -125,6 +125,10 @@ func (a *App) HubStop() {
|
||||
}
|
||||
|
||||
func (a *App) GetHubForUserId(userId string) *Hub {
|
||||
if len(a.Hubs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
hash := fnv.New32a()
|
||||
hash.Write([]byte(userId))
|
||||
index := hash.Sum32() % uint32(len(a.Hubs))
|
||||
@@ -132,11 +136,17 @@ func (a *App) GetHubForUserId(userId string) *Hub {
|
||||
}
|
||||
|
||||
func (a *App) HubRegister(webConn *WebConn) {
|
||||
a.GetHubForUserId(webConn.UserId).Register(webConn)
|
||||
hub := a.GetHubForUserId(webConn.UserId)
|
||||
if hub != nil {
|
||||
hub.Register(webConn)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) HubUnregister(webConn *WebConn) {
|
||||
a.GetHubForUserId(webConn.UserId).Unregister(webConn)
|
||||
hub := a.GetHubForUserId(webConn.UserId)
|
||||
if hub != nil {
|
||||
hub.Unregister(webConn)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) Publish(message *model.WebSocketEvent) {
|
||||
|
||||
Reference in New Issue
Block a user