Improve notifications
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2019-02-16 07:41:03 +01:00
parent e2361daa0e
commit e545f796ee
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -287,18 +287,21 @@ func (b *memoryBackend) run() {
case <-b.ticker.C: case <-b.ticker.C:
feeds := b.getFeeds() feeds := b.getFeeds()
count := 0
for uid := range feeds { for uid := range feeds {
for _, feedURL := range feeds[uid] { for _, feedURL := range feeds[uid] {
resp, err := b.Fetch3(uid, feedURL) resp, err := b.Fetch3(uid, feedURL)
if err != nil { if err != nil {
_ = b.channelAddItem("notifications", microsub.Item{ _ = b.channelAddItem("notifications", microsub.Item{
Type: "entry", Type: "entry",
Name: fmt.Sprintf("Error while Fetch3 of %s: %v", feedURL, err), Name: "Error while fetching feed",
Content: &microsub.Content{ Content: &microsub.Content{
Text: "error while fetching feed", Text: fmt.Sprintf("Error while updating feed %s: %v", feedURL, err),
}, },
UID: time.Now().String(), UID: time.Now().String(),
}) })
count++
log.Printf("Error while Fetch3 of %s: %v\n", feedURL, err) log.Printf("Error while Fetch3 of %s: %v\n", feedURL, err)
continue continue
} }
@ -307,6 +310,10 @@ func (b *memoryBackend) run() {
} }
} }
if count > 0 {
_ = b.updateChannelUnreadCount("notifications")
}
case <-b.quit: case <-b.quit:
b.ticker.Stop() b.ticker.Stop()
return return
@ -343,12 +350,13 @@ func (b *memoryBackend) FollowURL(uid string, url string) (microsub.Feed, error)
if err != nil { if err != nil {
_ = b.channelAddItem("notifications", microsub.Item{ _ = b.channelAddItem("notifications", microsub.Item{
Type: "entry", Type: "entry",
Name: fmt.Sprintf("Error while Fetch3 of %s: %v", feed.URL, err), Name: "Error while fetching feed",
Content: &microsub.Content{ Content: &microsub.Content{
Text: "error while fetching feed", Text: fmt.Sprintf("Error while Fetch3 of %s: %v", feed.URL, err),
}, },
UID: time.Now().String(), UID: time.Now().String(),
}) })
_ = b.updateChannelUnreadCount("notifications")
return feed, err return feed, err
} }
defer resp.Body.Close() defer resp.Body.Close()