diff options
Diffstat (limited to 'api/web_conn.go')
-rw-r--r-- | api/web_conn.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/api/web_conn.go b/api/web_conn.go index c906b7c95..a2b801904 100644 --- a/api/web_conn.go +++ b/api/web_conn.go @@ -7,6 +7,7 @@ import ( "fmt" "time" + "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" @@ -111,6 +112,12 @@ func (c *WebConn) writePump() { return } + if msg.EventType() == model.WEBSOCKET_EVENT_POSTED { + if einterfaces.GetMetricsInterface() != nil { + einterfaces.GetMetricsInterface().IncrementPostBroadcast() + } + } + case <-ticker.C: c.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT)) if err := c.WebSocket.WriteMessage(websocket.PingMessage, []byte{}); err != nil { @@ -140,7 +147,16 @@ func (webCon *WebConn) InvalidateCache() { } func (webCon *WebConn) isAuthenticated() bool { - return webCon.SessionToken != "" + if webCon.SessionToken == "" { + return false + } + + session := GetSession(webCon.SessionToken) + if session == nil || session.IsExpired() { + return false + } + + return true } func (webCon *WebConn) SendHello() { @@ -171,6 +187,18 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool { // Only report events to users who are in the channel for the event if len(msg.Broadcast.ChannelId) > 0 { + // Only broadcast typing messages if less than 1K people in channel + if msg.Event == model.WEBSOCKET_EVENT_TYPING { + if result := <-Srv.Store.Channel().GetMemberCount(msg.Broadcast.ChannelId, true); result.Err != nil { + l4g.Error("webhub.shouldSendEvent: " + result.Err.Error()) + return false + } else { + if result.Data.(int64) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel { + return false + } + } + } + if model.GetMillis()-webCon.LastAllChannelMembersTime > 1000*60*15 { // 15 minutes webCon.AllChannelMembers = nil webCon.LastAllChannelMembersTime = 0 |