PLT-3734 Cleaning up shouldSendEvent function (#4024)

* PLT-3734 Cleaning up shouldSendEvent function

* Fix LHS unread highlight and jewel mentions
Этот коммит содержится в:
enahum
2016-09-27 11:19:50 -03:00
коммит произвёл Christopher Speller
родитель bfca752940
Коммит 60347559c7
17 изменённых файлов: 117 добавлений и 110 удалений

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

@@ -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
}
// If the event is destined to a specific user
if len(msg.Broadcast.UserId) > 0 && webCon.UserId != msg.Broadcast.UserId {
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 the user is omitted don't send the message
if _, ok := msg.Broadcast.OmitUsers[webCon.UserId]; ok {
return false
}
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
}
// 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 team for the event
if len(msg.TeamId) > 0 {
allowed := webCon.IsMemberOfTeam(msg.TeamId)
// 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
}
}
// 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)
if !allowed {
return false
}
}
}
return true