From a7aca6c0abfd905669004c1e4f7c8328060df27e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 19 Sep 2021 10:56:38 +0200 Subject: Improved feed action filters (#3303) * Re-order some feed options * Option to auto mark as read existing titles * Option to keep at max n unread articles per feed --- app/Models/Feed.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'app/Models/Feed.php') diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 012bdced8..423b913b0 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -15,6 +15,7 @@ class FreshRSS_Feed extends Minz_Model { private $category = 1; private $nbEntries = -1; private $nbNotRead = -1; + private $nbPendingNotRead = 0; private $name = ''; private $website = ''; private $description = ''; @@ -141,13 +142,13 @@ class FreshRSS_Feed extends Minz_Model { return $this->nbEntries; } - public function nbNotRead() { + public function nbNotRead($includePending = false) { if ($this->nbNotRead < 0) { $feedDAO = FreshRSS_Factory::createFeedDao(); $this->nbNotRead = $feedDAO->countNotRead($this->id()); } - return $this->nbNotRead; + return $this->nbNotRead + ($includePending ? $this->nbPendingNotRead : 0); } public function faviconPrepare() { require_once(LIB_PATH . '/favicons.php'); @@ -475,6 +476,24 @@ class FreshRSS_Feed extends Minz_Model { } } + /** + * To keep track of some new potentially unread articles since last commit+fetch from database + */ + public function incPendingUnread($n = 1) { + $this->nbPendingNotRead += $n; + } + + public function keepMaxUnread() { + $keepMaxUnread = $this->attributes('keep_max_n_unread'); + if ($keepMaxUnread == false) { + $keepMaxUnread = FreshRSS_Context::$user_conf->mark_when['max_n_unread']; + } + if ($keepMaxUnread > 0 && $this->nbNotRead(false) + $this->nbPendingNotRead > $keepMaxUnread) { + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead)); + } + } + public function cleanOldEntries() { //Remember to call updateCachedValue($id_feed) or updateCachedValues() just after $archiving = $this->attributes('archiving'); if ($archiving == null) { -- cgit v1.2.3