From 8adfb562742b30ad1e8cf786d59ed5cbdf260625 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 17 Apr 2022 00:09:26 +0200 Subject: [PATCH] Problem: item counts don't update Solution: re-enable updateChannelUnreadCount --- cmd/eksterd/memory.go | 29 ++++++++++++++++------------- pkg/timeline/postgres.go | 5 +++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/eksterd/memory.go b/cmd/eksterd/memory.go index 981051e..682a61d 100644 --- a/cmd/eksterd/memory.go +++ b/cmd/eksterd/memory.go @@ -860,19 +860,22 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) (bool } func (b *memoryBackend) updateChannelUnreadCount(channel string) error { - // tl := b.getTimeline(channel) - // unread, err := tl.Count() - // if err != nil { - // return err - // } - // - // currentCount := c.Unread.UnreadCount - // c.Unread = microsub.Unread{Type: microsub.UnreadCount, UnreadCount: unread} - // - // // Sent message to Server-Sent-Events - // if currentCount != unread { - // b.broker.Notifier <- sse.Message{Event: "new item in channel", Object: c} - // } + tl := b.getTimeline(channel) + unread, err := tl.Count() + if err != nil { + return err + } + + var c microsub.Channel + c.UID = channel + + currentCount := c.Unread.UnreadCount + c.Unread = microsub.Unread{Type: microsub.UnreadCount, UnreadCount: unread} + + // Sent message to Server-Sent-Events + if currentCount != unread { + b.broker.Notifier <- sse.Message{Event: "new item in channel", Object: c} + } return nil } diff --git a/pkg/timeline/postgres.go b/pkg/timeline/postgres.go index b5e98ee..4bd4713 100644 --- a/pkg/timeline/postgres.go +++ b/pkg/timeline/postgres.go @@ -225,10 +225,11 @@ func (p *postgresStream) Count() (int, error) { if row == nil { return 0, nil } + var count int err = row.Scan(&count) - if err != nil { - return -1, err + if err != nil && err == sql.ErrNoRows { + return 0, nil } return count, nil