1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Highlight and sort feeds with unread entries in feeds list

This commit is contained in:
pennae 2021-06-02 21:01:21 +00:00 committed by GitHub
parent 1fc95a83b6
commit 4b2a25eed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 3 deletions

View file

@ -9,12 +9,27 @@ import (
"errors"
"fmt"
"runtime"
"sort"
"miniflux.app/config"
"miniflux.app/logger"
"miniflux.app/model"
)
type byStateAndName struct{ f model.Feeds }
func (l byStateAndName) Len() int { return len(l.f) }
func (l byStateAndName) Swap(i, j int) { l.f[i], l.f[j] = l.f[j], l.f[i] }
func (l byStateAndName) Less(i, j int) bool {
if l.f[i].UnreadCount > 0 && l.f[j].UnreadCount == 0 {
return true
} else if l.f[i].UnreadCount == 0 && l.f[j].UnreadCount > 0 {
return false
} else {
return l.f[i].Title < l.f[j].Title
}
}
// FeedExists checks if the given feed exists.
func (s *Storage) FeedExists(userID, feedID int64) bool {
var result bool
@ -121,13 +136,22 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
return builder.GetFeeds()
}
func getFeedsSorted(builder *FeedQueryBuilder) (model.Feeds, error) {
result, err := builder.GetFeeds()
if err == nil {
sort.Sort(byStateAndName{result})
return result, nil
}
return result, err
}
// FeedsWithCounters returns all feeds of the given user with counters of read and unread entries.
func (s *Storage) FeedsWithCounters(userID int64) (model.Feeds, error) {
builder := NewFeedQueryBuilder(s, userID)
builder.WithCounters()
builder.WithOrder(model.DefaultFeedSorting)
builder.WithDirection(model.DefaultFeedSortingDirection)
return builder.GetFeeds()
return getFeedsSorted(builder)
}
// FeedsByCategoryWithCounters returns all feeds of the given user/category with counters of read and unread entries.
@ -137,7 +161,7 @@ func (s *Storage) FeedsByCategoryWithCounters(userID, categoryID int64) (model.F
builder.WithCounters()
builder.WithOrder(model.DefaultFeedSorting)
builder.WithDirection(model.DefaultFeedSortingDirection)
return builder.GetFeeds()
return getFeedsSorted(builder)
}
// WeeklyFeedEntryCount returns the weekly entry count for a feed.