diff --git a/cmd/server/fetch.go b/cmd/server/fetch.go index 624b372..b2cf42a 100644 --- a/cmd/server/fetch.go +++ b/cmd/server/fetch.go @@ -368,11 +368,18 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) { return } - _, err = b.Redis.Do("SADD", channelKey, itemKey) + added, err := redis.Int64(b.Redis.Do("SADD", channelKey, itemKey)) if err != nil { log.Printf("error while adding item %s to channel %s for redis: %v\n", itemKey, channelKey, err) return } + + if added > 0 { + if c, e := b.Channels[channel]; e { + c.Unread = true + b.Channels[channel] = c + } + } } type redisItem struct { diff --git a/cmd/server/null.go b/cmd/server/null.go index d1a0c04..8f8d286 100644 --- a/cmd/server/null.go +++ b/cmd/server/null.go @@ -28,10 +28,10 @@ type NullBackend struct { // ChannelsGetList gets no channels func (b *NullBackend) ChannelsGetList() []microsub.Channel { return []microsub.Channel{ - microsub.Channel{"0000", "default", 0}, - microsub.Channel{"0001", "notifications", 0}, - microsub.Channel{"1000", "Friends", 0}, - microsub.Channel{"1001", "Family", 0}, + microsub.Channel{UID: "0000", Name: "default", Unread: false}, + microsub.Channel{UID: "0001", Name: "notifications", Unread: false}, + microsub.Channel{UID: "1000", Name: "Friends", Unread: false}, + microsub.Channel{UID: "1001", Name: "Family", Unread: false}, } } diff --git a/microsub/protocol.go b/microsub/protocol.go index 82efad9..8b26694 100644 --- a/microsub/protocol.go +++ b/microsub/protocol.go @@ -34,7 +34,7 @@ type Channel struct { // UID is a unique id for the channel UID string `json:"uid"` Name string `json:"name"` - Unread int `json:"unread"` + Unread bool `json:"unread"` } type Author struct {