From 246d12aaf23fa3a2c23225b33a333effff76253b Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 14 Jul 2015 15:12:04 -0800 Subject: fixes mm-1348 removing dependency on redis --- api/web_hub.go | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'api/web_hub.go') diff --git a/api/web_hub.go b/api/web_hub.go index bf5fbb321..c7be19cac 100644 --- a/api/web_hub.go +++ b/api/web_hub.go @@ -5,12 +5,14 @@ package api import ( l4g "code.google.com/p/log4go" + "github.com/mattermost/platform/model" ) type Hub struct { teamHubs map[string]*TeamHub register chan *WebConn unregister chan *WebConn + broadcast chan *model.Message stop chan string } @@ -18,9 +20,16 @@ var hub = &Hub{ register: make(chan *WebConn), unregister: make(chan *WebConn), teamHubs: make(map[string]*TeamHub), + broadcast: make(chan *model.Message), stop: make(chan string), } +func PublishAndForget(message *model.Message) { + go func() { + hub.Broadcast(message) + }() +} + func (h *Hub) Register(webConn *WebConn) { h.register <- webConn } @@ -29,8 +38,14 @@ func (h *Hub) Unregister(webConn *WebConn) { h.unregister <- webConn } -func (h *Hub) Stop(teamId string) { - h.stop <- teamId +func (h *Hub) Broadcast(message *model.Message) { + if message != nil { + h.broadcast <- message + } +} + +func (h *Hub) Stop() { + h.stop <- "all" } func (h *Hub) Start() { @@ -53,18 +68,17 @@ func (h *Hub) Start() { if nh, ok := h.teamHubs[c.TeamId]; ok { nh.Unregister(c) } - + case msg := <-h.broadcast: + nh := h.teamHubs[msg.TeamId] + if nh != nil { + nh.broadcast <- msg + } case s := <-h.stop: - if len(s) == 0 { - l4g.Debug("stopping all connections") - for _, v := range h.teamHubs { - v.Stop() - } - return - } else if nh, ok := h.teamHubs[s]; ok { - delete(h.teamHubs, s) - nh.Stop() + l4g.Debug("stopping %v connections", s) + for _, v := range h.teamHubs { + v.Stop() } + return } } }() -- cgit v1.2.3-1-g7c22