diff options
Diffstat (limited to 'api/web_hub.go')
-rw-r--r-- | api/web_hub.go | 59 |
1 files changed, 16 insertions, 43 deletions
diff --git a/api/web_hub.go b/api/web_hub.go index 18c218634..4a9719d80 100644 --- a/api/web_hub.go +++ b/api/web_hub.go @@ -64,7 +64,7 @@ func InvalidateCacheForChannel(channelId string) { func (h *Hub) Register(webConn *WebConn) { h.register <- webConn - msg := model.NewWebSocketEvent("", "", webConn.UserId, model.WEBSOCKET_EVENT_HELLO) + 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) } @@ -146,52 +146,25 @@ func (h *Hub) Start() { } func shouldSendEvent(webCon *WebConn, msg *model.WebSocketEvent) bool { - if webCon.UserId == msg.UserId { - // Don't need to tell the user they are typing - if msg.Event == model.WEBSOCKET_EVENT_TYPING { - return false - } - - // We have to make sure the user is in the channel. Otherwise system messages that - // post about users in channels they are not in trigger warnings. - if len(msg.ChannelId) > 0 { - allowed := webCon.IsMemberOfChannel(msg.ChannelId) - - if !allowed { - return false - } - } - } else { - // Don't share a user's view or preference events with other users - if msg.Event == model.WEBSOCKET_EVENT_CHANNEL_VIEWED { - return false - } else if msg.Event == model.WEBSOCKET_EVENT_PREFERENCE_CHANGED { - return false - } else if msg.Event == model.WEBSOCKET_EVENT_EPHEMERAL_MESSAGE { - // For now, ephemeral messages are sent directly to individual users - return false - } else if msg.Event == model.WEBSOCKET_EVENT_WEBRTC { - // No need to tell anyone that a webrtc event is going on - return false - } + // If the event is destined to a specific user + if len(msg.Broadcast.UserId) > 0 && webCon.UserId != msg.Broadcast.UserId { + return false + } - // Only report events to users who are in the team for the event - if len(msg.TeamId) > 0 { - allowed := webCon.IsMemberOfTeam(msg.TeamId) + // if the user is omitted don't send the message + if _, ok := msg.Broadcast.OmitUsers[webCon.UserId]; ok { + return false + } - if !allowed { - return false - } - } + // Only report events to users who are in the channel for the event + if len(msg.Broadcast.ChannelId) > 0 { + return webCon.IsMemberOfChannel(msg.Broadcast.ChannelId) + } - // Only report events to users who are in the channel for the event execept deleted events - if len(msg.ChannelId) > 0 && msg.Event != model.WEBSOCKET_EVENT_CHANNEL_DELETED { - allowed := webCon.IsMemberOfChannel(msg.ChannelId) + // Only report events to users who are in the team for the event + if len(msg.Broadcast.TeamId) > 0 { + return webCon.IsMemberOfTeam(msg.Broadcast.TeamId) - if !allowed { - return false - } - } } return true |