Commit 9d11dd43 authored by Joram Wilander's avatar Joram Wilander Committed by enahum

Send hello event containing server version on WebSocket connect (#3936)

parent 6c085594
......@@ -4,6 +4,7 @@
package api
import (
"fmt"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/einterfaces"
......@@ -61,6 +62,10 @@ func InvalidateCacheForChannel(channelId string) {
func (h *Hub) Register(webConn *WebConn) {
h.register <- webConn
msg := model.NewWebSocketEvent("", "", webConn.UserId, model.WEBSOCKET_EVENT_HELLO)
msg.Add("server_version", fmt.Sprintf("%v.%v", model.CurrentVersion, utils.CfgHash))
go Publish(msg)
}
func (h *Hub) Unregister(webConn *WebConn) {
......
......@@ -24,6 +24,7 @@ const (
WEBSOCKET_EVENT_PREFERENCE_CHANGED = "preference_changed"
WEBSOCKET_EVENT_EPHEMERAL_MESSAGE = "ephemeral_message"
WEBSOCKET_EVENT_STATUS_CHANGE = "status_change"
WEBSOCKET_EVENT_HELLO = "hello"
)
type WebSocketMessage interface {
......
......@@ -156,6 +156,10 @@ function handleEvent(msg) {
handleStatusChangedEvent(msg);
break;
case SocketEvents.HELLO:
handleHelloEvent(msg);
break;
default:
}
}
......@@ -284,3 +288,8 @@ function handleUserTypingEvent(msg) {
function handleStatusChangedEvent(msg) {
UserStore.setStatus(msg.user_id, msg.data.status);
}
function handleHelloEvent(msg) {
Client.serverVersion = msg.data.server_version;
AsyncClient.checkVersion();
}
......@@ -198,7 +198,8 @@ export const Constants = {
TYPING: 'typing',
PREFERENCE_CHANGED: 'preference_changed',
EPHEMERAL_MESSAGE: 'ephemeral_message',
STATUS_CHANGED: 'status_change'
STATUS_CHANGED: 'status_change',
HELLO: 'hello'
},
UserUpdateEvents: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment