From ff7d8bbfd3f9e66f16c3b43c91c1a74bf1f2abf6 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 4 Oct 2018 20:00:09 +0200 Subject: [PATCH] Notify everyone when new public channel is created or updated --- sam/service/events.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sam/service/events.go b/sam/service/events.go index 39d1d2271..e8f2a4639 100644 --- a/sam/service/events.go +++ b/sam/service/events.go @@ -23,6 +23,7 @@ type ( } ) +// Sends sends events back to all subscribers func Event() EventService { return (&event{events: repository.Events()}).With(context.Background()) } @@ -38,8 +39,16 @@ func (svc *event) Message(m *types.Message) error { return svc.push(payload.Message(m), m.ChannelID) } -func (svc *event) Channel(m *types.Channel) error { - return svc.push(payload.Channel(m), m.ID) +// Channel notifies subscribers about channel change +// +// If this is a public channel we notify everyone +func (svc *event) Channel(ch *types.Channel) error { + sub := ch.ID + if ch.Type == types.ChannelTypePublic { + sub = 0 + } + + return svc.push(payload.Channel(ch), sub) } func (svc *event) push(m outgoing.MessageEncoder, sub uint64) error {