Only send WS hello event once authenticated (#4509)

Этот коммит содержится в:
Joram Wilander
2016-11-10 09:20:36 -05:00
коммит произвёл Harrison Healey
родитель 70e0d5c298
Коммит 39675afab4
3 изменённых файлов: 12 добавлений и 3 удалений

Просмотреть файл

@@ -8,6 +8,7 @@ import (
"time"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/websocket"
@@ -142,6 +143,13 @@ func (webCon *WebConn) isAuthenticated() bool {
return webCon.SessionToken != ""
}
func (webCon *WebConn) SendHello() {
msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", webCon.UserId, nil)
msg.Add("server_version", fmt.Sprintf("%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.CfgHash))
msg.DoPreComputeJson()
webCon.Send <- msg
}
func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// IMPORTANT: Do not send event if WebConn does not have a session
if !webCon.isAuthenticated() {

Просмотреть файл

@@ -119,9 +119,9 @@ func InvalidateCacheForUserSkipClusterSend(userId string) {
func (h *Hub) Register(webConn *WebConn) {
h.register <- webConn
msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", webConn.UserId, nil)
msg.Add("server_version", fmt.Sprintf("%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.CfgHash))
go Publish(msg)
if webConn.isAuthenticated() {
webConn.SendHello()
}
}
func (h *Hub) Unregister(webConn *WebConn) {

Просмотреть файл

@@ -57,6 +57,7 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
resp := model.NewWebSocketResponse(model.STATUS_OK, r.Seq, nil)
resp.DoPreComputeJson()
conn.Send <- resp
conn.SendHello()
}
return