summaryrefslogtreecommitdiffstats
path: root/api/web_team_hub.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-10-15 10:44:04 -0400
committerJoramWilander <jwawilander@gmail.com>2015-10-16 11:48:55 -0400
commit2b5ec4a3c076bb1f18eeafbd96b0a80c6b8bfbaa (patch)
treee08561de76eb4939636d00317f8f5120b0db77e2 /api/web_team_hub.go
parent3c593af598b2bb986244099ed1b9a46ed3837911 (diff)
downloadchat-2b5ec4a3c076bb1f18eeafbd96b0a80c6b8bfbaa.tar.gz
chat-2b5ec4a3c076bb1f18eeafbd96b0a80c6b8bfbaa.tar.bz2
chat-2b5ec4a3c076bb1f18eeafbd96b0a80c6b8bfbaa.zip
Small refactor of websocket code on client and server
Diffstat (limited to 'api/web_team_hub.go')
-rw-r--r--api/web_team_hub.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/api/web_team_hub.go b/api/web_team_hub.go
index c57de550f..6a25b7d3d 100644
--- a/api/web_team_hub.go
+++ b/api/web_team_hub.go
@@ -53,7 +53,7 @@ func (h *TeamHub) Start() {
}
case msg := <-h.broadcast:
for webCon := range h.connections {
- if !(webCon.UserId == msg.UserId && msg.Action == model.ACTION_TYPING) {
+ if ShouldSendEvent(webCon, msg) {
select {
case webCon.Send <- msg:
default:
@@ -86,3 +86,32 @@ func (h *TeamHub) UpdateChannelAccessCache(userId string, channelId string) {
}
}
}
+
+func ShouldSendEvent(webCon *WebConn, msg *model.Message) bool {
+
+ if webCon.UserId == msg.UserId {
+ // Don't need to tell the user they are typing
+ if msg.Action == model.ACTION_TYPING {
+ return false
+ }
+ } else {
+ // Don't share a user's view events with other users
+ if msg.Action == model.ACTION_CHANNEL_VIEWED {
+ return false
+ }
+
+ // Only report events to a user who is the subject of the event, or is in the channel of the event
+ if len(msg.ChannelId) > 0 {
+ allowed, ok := webCon.ChannelAccessCache[msg.ChannelId]
+ if !ok {
+ allowed = webCon.updateChannelAccessCache(msg.ChannelId)
+ }
+
+ if !allowed {
+ return false
+ }
+ }
+ }
+
+ return true
+}