Compare commits

...

2 Commits

Author SHA1 Message Date
e545f796ee
Improve notifications
All checks were successful
the build was successful
2019-02-16 07:41:03 +01:00
e2361daa0e
Remove extraneous mutex locks 2019-02-16 07:40:26 +01:00

View File

@ -231,9 +231,6 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
func (b *memoryBackend) ChannelsUpdate(uid, name string) (microsub.Channel, error) { func (b *memoryBackend) ChannelsUpdate(uid, name string) (microsub.Channel, error) {
defer b.save() defer b.save()
b.lock.RLock()
defer b.lock.RUnlock()
b.lock.RLock() b.lock.RLock()
c, e := b.Channels[uid] c, e := b.Channels[uid]
b.lock.RUnlock() b.lock.RUnlock()
@ -290,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
} }
@ -310,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
@ -346,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()