diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/channel.go | 22 | ||||
-rw-r--r-- | api/web_conn.go | 4 | ||||
-rw-r--r-- | api/web_hub.go | 39 |
3 files changed, 43 insertions, 22 deletions
diff --git a/api/channel.go b/api/channel.go index d47109045..4b0e99b20 100644 --- a/api/channel.go +++ b/api/channel.go @@ -687,14 +687,20 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("name=" + channel.Name) - post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf( - c.T("api.channel.delete_channel.archived"), - user.Username)} - if _, err := CreatePost(c, post, false); err != nil { - l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err) - c.Err = model.NewLocAppError("deleteChannel", "api.channel.delete_channel.failed_send.app_error", nil, "") - return - } + go func() { + InvalidateCacheForChannel(channel.Id) + message := model.NewMessage(c.TeamId, channel.Id, c.Session.UserId, model.ACTION_CHANNEL_DELETED) + PublishAndForget(message) + + post := &model.Post{ + ChannelId: channel.Id, + Message: fmt.Sprintf(c.T("api.channel.delete_channel.archived"), user.Username), + Type: model.POST_CHANNEL_DELETED, + } + if _, err := CreatePost(c, post, false); err != nil { + l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err) + } + }() result := make(map[string]string) result["id"] = channel.Id diff --git a/api/web_conn.go b/api/web_conn.go index 397af0696..21b6f5b91 100644 --- a/api/web_conn.go +++ b/api/web_conn.go @@ -118,6 +118,10 @@ func (c *WebConn) InvalidateCache() { c.hasPermissionsToTeam = make(map[string]bool) } +func (c *WebConn) InvalidateCacheForChannel(channelId string) { + delete(c.hasPermissionsToChannel, channelId) +} + func (c *WebConn) HasPermissionsToTeam(teamId string) bool { perm, ok := c.hasPermissionsToTeam[teamId] if !ok { 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 { |