From 7695cbd1b4a62b1cc7c31b16f70309a287296385 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 27 Apr 2016 16:05:39 -0400 Subject: Add websocket event and cache invalidation for deleting channels (#2807) --- api/web_hub.go | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'api/web_hub.go') diff --git a/api/web_hub.go b/api/web_hub.go index 241ebcef0..066ae3474 100644 --- a/api/web_hub.go +++ b/api/web_hub.go @@ -10,21 +10,23 @@ import ( ) type Hub struct { - connections map[*WebConn]bool - register chan *WebConn - unregister chan *WebConn - broadcast chan *model.Message - stop chan string - invalidateUser chan string + connections map[*WebConn]bool + register chan *WebConn + unregister chan *WebConn + broadcast chan *model.Message + stop chan string + invalidateUser chan string + invalidateChannel chan string } var hub = &Hub{ - register: make(chan *WebConn), - unregister: make(chan *WebConn), - connections: make(map[*WebConn]bool), - broadcast: make(chan *model.Message), - stop: make(chan string), - invalidateUser: make(chan string), + register: make(chan *WebConn), + unregister: make(chan *WebConn), + connections: make(map[*WebConn]bool), + broadcast: make(chan *model.Message), + stop: make(chan string), + invalidateUser: make(chan string), + invalidateChannel: make(chan string), } func PublishAndForget(message *model.Message) { @@ -37,6 +39,10 @@ func InvalidateCacheForUser(userId string) { hub.invalidateUser <- userId } +func InvalidateCacheForChannel(channelId string) { + hub.invalidateChannel <- channelId +} + func (h *Hub) Register(webConn *WebConn) { h.register <- webConn } @@ -74,6 +80,11 @@ func (h *Hub) Start() { } } + case channelId := <-h.invalidateChannel: + for webCon := range h.connections { + webCon.InvalidateCacheForChannel(channelId) + } + case msg := <-h.broadcast: for webCon := range h.connections { if shouldSendEvent(webCon, msg) { @@ -136,8 +147,8 @@ func shouldSendEvent(webCon *WebConn, msg *model.Message) bool { } } - // Only report events to users who are in the channel for the event - if len(msg.ChannelId) > 0 { + // Only report events to users who are in the channel for the event execept deleted events + if len(msg.ChannelId) > 0 && msg.Action != model.ACTION_CHANNEL_DELETED { allowed := webCon.HasPermissionsToChannel(msg.ChannelId) if !allowed { -- cgit v1.2.3-1-g7c22