Use boolean unread

This commit is contained in:
Peter Stuifzand 2018-04-08 16:22:59 +02:00
parent faa685e291
commit a2cd294b80
3 changed files with 13 additions and 6 deletions

View File

@ -368,11 +368,18 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) {
return return
} }
_, err = b.Redis.Do("SADD", channelKey, itemKey) added, err := redis.Int64(b.Redis.Do("SADD", channelKey, itemKey))
if err != nil { if err != nil {
log.Printf("error while adding item %s to channel %s for redis: %v\n", itemKey, channelKey, err) log.Printf("error while adding item %s to channel %s for redis: %v\n", itemKey, channelKey, err)
return return
} }
if added > 0 {
if c, e := b.Channels[channel]; e {
c.Unread = true
b.Channels[channel] = c
}
}
} }
type redisItem struct { type redisItem struct {

View File

@ -28,10 +28,10 @@ type NullBackend struct {
// ChannelsGetList gets no channels // ChannelsGetList gets no channels
func (b *NullBackend) ChannelsGetList() []microsub.Channel { func (b *NullBackend) ChannelsGetList() []microsub.Channel {
return []microsub.Channel{ return []microsub.Channel{
microsub.Channel{"0000", "default", 0}, microsub.Channel{UID: "0000", Name: "default", Unread: false},
microsub.Channel{"0001", "notifications", 0}, microsub.Channel{UID: "0001", Name: "notifications", Unread: false},
microsub.Channel{"1000", "Friends", 0}, microsub.Channel{UID: "1000", Name: "Friends", Unread: false},
microsub.Channel{"1001", "Family", 0}, microsub.Channel{UID: "1001", Name: "Family", Unread: false},
} }
} }

View File

@ -34,7 +34,7 @@ type Channel struct {
// UID is a unique id for the channel // UID is a unique id for the channel
UID string `json:"uid"` UID string `json:"uid"`
Name string `json:"name"` Name string `json:"name"`
Unread int `json:"unread"` Unread bool `json:"unread"`
} }
type Author struct { type Author struct {