diff --git a/cmd/eksterd/memory.go b/cmd/eksterd/memory.go index 466b7ee..2130cd1 100644 --- a/cmd/eksterd/memory.go +++ b/cmd/eksterd/memory.go @@ -58,6 +58,16 @@ type channelSetting struct { ChannelType string } +type channelMessage struct { + Version int `json:"version"` + Channel microsub.Channel `json:"channel"` +} + +type newItemMessage struct { + Item microsub.Item `json:"item"` + Channel string `json:"channel"` +} + // Debug interface for easy of use in other packages type Debug interface { Debug() @@ -210,6 +220,8 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) { updateChannelInRedis(conn, channel.UID, DefaultPrio) + b.broker.Notifier <- sse.Message{Event: "new channel", Object: channelMessage{1, channel}} + return channel, nil } @@ -228,6 +240,8 @@ func (b *memoryBackend) ChannelsUpdate(uid, name string) (microsub.Channel, erro b.Channels[uid] = c b.lock.Unlock() + b.broker.Notifier <- sse.Message{Event: "update channel", Object: channelMessage{1, c}} + return c, nil } @@ -673,11 +687,6 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) error timelineBackend := b.getTimeline(channel) added, err := timelineBackend.AddItem(item) - type newItemMessage struct { - Item microsub.Item `json:"item"` - Channel string `json:"channel"` - } - // Sent message to Server-Sent-Events if added { b.broker.Notifier <- sse.Message{Event: "new item", Object: newItemMessage{item, channel}}