diff options
| author | 2025-12-27 16:26:02 +0100 | |
|---|---|---|
| committer | 2025-12-27 16:26:02 +0100 | |
| commit | 7c0370b4eacdd62c06c7324a39f092361e84a2bc (patch) | |
| tree | b7b96bde135dab5189728e668e8b6b03f2079ef4 /app/Models/Category.php | |
| parent | 40533684bb255264fec76296aed3ea4d35cd5317 (diff) | |
Do not include hidden feeds when counting unread articles in categories (#8357)
fix https://github.com/FreshRSS/FreshRSS/issues/8347
Diffstat (limited to 'app/Models/Category.php')
| -rw-r--r-- | app/Models/Category.php | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php index 4d7740ed1..2bdad2904 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -18,11 +18,11 @@ class FreshRSS_Category extends Minz_Model { private int $kind = 0; private string $name; private int $nbFeeds = -1; + /** Number of unread articles in feeds with visibility FreshRSS_Feed::PRIORITY_FEED */ private int $nbNotRead = -1; /** @var array<int,FreshRSS_Feed>|null where the key is the feed ID */ private ?array $feeds = null; - /** @var bool|int */ - private $hasFeedsWithError = false; + private bool|int $hasFeedsWithError = false; private int $lastUpdate = 0; private bool $error = false; @@ -39,8 +39,10 @@ class FreshRSS_Category extends Minz_Model { foreach ($feeds as $feed) { $feed->_category($this); $this->nbFeeds++; - $this->nbNotRead += $feed->nbNotRead(); - $this->hasFeedsWithError |= ($feed->inError() && !$feed->mute()); + if ($feed->priority() > FreshRSS_Feed::PRIORITY_HIDDEN) { + $this->nbNotRead += $feed->nbNotRead(); + $this->hasFeedsWithError |= ($feed->inError() && !$feed->mute()); + } } } } @@ -90,13 +92,25 @@ class FreshRSS_Category extends Minz_Model { * @throws Minz_ConfigurationNamespaceException * @throws Minz_PDOConnectionException */ - public function nbNotRead(): int { - if ($this->nbNotRead < 0) { + public function nbNotRead(int $minPriority = FreshRSS_Feed::PRIORITY_FEED): int { + if ($this->nbNotRead > 0 && $minPriority === FreshRSS_Feed::PRIORITY_FEED) { + return $this->nbNotRead; + } + if ($this->feeds === null) { $catDAO = FreshRSS_Factory::createCategoryDao(); - $this->nbNotRead = $catDAO->countNotRead($this->id()); + $nb = $catDAO->countNotRead($this->id(), $minPriority); + if ($minPriority === FreshRSS_Feed::PRIORITY_FEED) { + $this->nbNotRead = $nb; + } + return $nb; } - - return $this->nbNotRead; + $nb = 0; + foreach ($this->feeds as $feed) { + if ($feed->priority() >= $minPriority) { + $nb += $feed->nbNotRead(); + } + } + return $nb; } /** @return array<int,mixed> */ @@ -117,8 +131,10 @@ class FreshRSS_Category extends Minz_Model { $this->nbNotRead = 0; foreach ($this->feeds as $feed) { $this->nbFeeds++; - $this->nbNotRead += $feed->nbNotRead(); - $this->hasFeedsWithError |= ($feed->inError() && !$feed->mute()); + if ($feed->priority() > FreshRSS_Feed::PRIORITY_HIDDEN) { + $this->nbNotRead += $feed->nbNotRead(); + $this->hasFeedsWithError |= ($feed->inError() && !$feed->mute()); + } } $this->sortFeeds(); } @@ -290,14 +306,10 @@ class FreshRSS_Category extends Minz_Model { /** * @param array<FreshRSS_Category> $categories */ - public static function countUnread(array $categories, int $minPriority = 0): int { + public static function countUnread(array $categories, int $minPriority = FreshRSS_Feed::PRIORITY_FEED): int { $n = 0; foreach ($categories as $category) { - foreach ($category->feeds() as $feed) { - if ($feed->priority() >= $minPriority) { - $n += $feed->nbNotRead(); - } - } + $n += $category->nbNotRead($minPriority); } return $n; } |
