diff options
| author | 2023-11-08 20:23:54 +0100 | |
|---|---|---|
| committer | 2023-11-08 20:23:54 +0100 | |
| commit | 348028a29043b7d1d0f80544c44f0454b2c375c3 (patch) | |
| tree | 8f01badaa6983341f27e8afb05e2e9d42992b9b0 /app/Models | |
| parent | 7d26dcc8475e4c7c3f68358405e9074ed61e018c (diff) | |
New feature important feeds (#5782)
* New feature important feeds
* Fix PHPStan
* Initial style for important feeds + keep unread
* Change UI order
* Count important unread
* Never mark as read important feeds during scroll
* Fix i18n conf.iew.normal regression
* Fix reader view
* More fix reader view
* Create important.svg
* Fix title
* Fix counter
* Account for important during mark-all-as-read
* Fix underline colour
* đ
* Changelog
---------
Co-authored-by: math-gh <>
Co-authored-by: maTh <1645099+math-GH@users.noreply.github.com>
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/CategoryDAO.php | 4 | ||||
| -rw-r--r-- | app/Models/Context.php | 28 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 43 | ||||
| -rw-r--r-- | app/Models/Feed.php | 3 | ||||
| -rw-r--r-- | app/Models/Themes.php | 1 |
5 files changed, 56 insertions, 23 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index eeb3e9843..72971f44b 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -284,11 +284,11 @@ SQL; . ($details ? 'f.* ' : 'f.id, f.name, f.url, f.kind, f.website, f.priority, f.error, f.`cache_nbEntries`, f.`cache_nbUnreads`, f.ttl ') . 'FROM `_category` c ' . 'LEFT OUTER JOIN `_feed` f ON f.category=c.id ' - . 'WHERE f.priority >= :priority_normal ' + . 'WHERE f.priority >= :priority ' . 'GROUP BY f.id, c_id ' . 'ORDER BY c.name, f.name'; $stm = $this->pdo->prepare($sql); - $values = [ ':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL ]; + $values = [ ':priority' => FreshRSS_Feed::PRIORITY_CATEGORY ]; if ($stm !== false && $stm->execute($values)) { $res = $stm->fetchAll(PDO::FETCH_ASSOC) ?: []; /** @var array<array{'c_name':string,'c_id':int,'c_kind':int,'c_last_update':int,'c_error':int|bool,'c_attributes'?:string, diff --git a/app/Models/Context.php b/app/Models/Context.php index c1fa96ae7..9fac52d44 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -19,6 +19,7 @@ final class FreshRSS_Context { public static string $name = ''; public static string $description = ''; public static int $total_unread = 0; + public static int $total_important_unread = 0; /** @var array{'all':int,'read':int,'unread':int} */ public static array $total_starred = [ @@ -29,10 +30,11 @@ final class FreshRSS_Context { public static int $get_unread = 0; - /** @var array{'all':bool,'starred':bool,'feed':int|false,'category':int|false,'tag':int|false,'tags':bool} */ + /** @var array{'all':bool,'starred':bool,'important':bool,'feed':int|false,'category':int|false,'tag':int|false,'tags':bool} */ public static array $current_get = [ 'all' => false, 'starred' => false, + 'important' => false, 'feed' => false, 'category' => false, 'tag' => false, @@ -154,9 +156,8 @@ final class FreshRSS_Context { // Update number of read / unread variables. $entryDAO = FreshRSS_Factory::createEntryDao(); self::$total_starred = $entryDAO->countUnreadReadFavorites(); - self::$total_unread = FreshRSS_CategoryDAO::countUnread( - self::$categories, 1 - ); + self::$total_unread = FreshRSS_CategoryDAO::countUnread(self::$categories, FreshRSS_Feed::PRIORITY_MAIN_STREAM); + self::$total_important_unread = FreshRSS_CategoryDAO::countUnread(self::$categories, FreshRSS_Feed::PRIORITY_IMPORTANT); self::_get(Minz_Request::paramString('get') ?: 'a'); @@ -208,12 +209,14 @@ final class FreshRSS_Context { * Return the current get as a string or an array. * * If $array is true, the first item of the returned value is 'f' or 'c' or 't' and the second is the id. - * @phpstan-return ($asArray is true ? array{'a'|'c'|'f'|'s'|'t'|'T',bool|int} : string) + * @phpstan-return ($asArray is true ? array{'a'|'c'|'f'|'i'|'s'|'t'|'T',bool|int} : string) * @return string|array{string,bool|int} */ public static function currentGet(bool $asArray = false) { if (self::$current_get['all']) { return $asArray ? ['a', true] : 'a'; + } elseif (self::$current_get['important']) { + return $asArray ? ['i', true] : 'i'; } elseif (self::$current_get['starred']) { return $asArray ? ['s', true] : 's'; } elseif (self::$current_get['feed']) { @@ -248,6 +251,13 @@ final class FreshRSS_Context { } /** + * @return bool true if the current request targets important feeds, false otherwise. + */ + public static function isImportant(): bool { + return self::$current_get['important'] != false; + } + + /** * @return bool true if the current request targets a category, false otherwise. */ public static function isCategory(): bool { @@ -278,6 +288,8 @@ final class FreshRSS_Context { switch($type) { case 'a': return self::$current_get['all']; + case 'i': + return self::$current_get['important']; case 's': return self::$current_get['starred']; case 'f': @@ -325,6 +337,12 @@ final class FreshRSS_Context { self::$description = self::$system_conf->meta_description; self::$get_unread = self::$total_unread; break; + case 'i': + self::$current_get['important'] = true; + self::$name = _t('index.menu.important'); + self::$description = self::$system_conf->meta_description; + self::$get_unread = self::$total_unread; + break; case 's': self::$current_get['starred'] = true; self::$name = _t('index.feed.title_fav'); diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index 017754e04..f2711d448 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -425,7 +425,7 @@ SQL; * @param string $idMax fail safe article ID * @return int|false affected rows */ - public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, int $priorityMin = 0, + public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, ?int $priorityMin = null, ?int $prioritMax = null, ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { FreshRSS_UserDAO::touch(); if ($idMax == '0') { @@ -434,12 +434,22 @@ SQL; } $sql = 'UPDATE `_entry` SET is_read = ? WHERE is_read <> ? AND id <= ?'; + $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax]; if ($onlyFavorites) { $sql .= ' AND is_favorite=1'; - } elseif ($priorityMin >= 0) { - $sql .= ' AND id_feed IN (SELECT f.id FROM `_feed` f WHERE f.priority > ' . intval($priorityMin) . ')'; } - $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax]; + if ($priorityMin !== null || $prioritMax !== null) { + $sql .= ' AND id_feed IN (SELECT f.id FROM `_feed` f WHERE 1=1'; + if ($priorityMin !== null) { + $sql .= ' AND f.priority >= ?'; + $values[] = $priorityMin; + } + if ($prioritMax !== null) { + $sql .= ' AND f.priority < ?'; + $values[] = $prioritMax; + } + $sql .= ')'; + } [$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state); @@ -1019,7 +1029,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'i'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type * @param int $id category/feed/tag ID * @param 'ASC'|'DESC' $order * @return array{0:array<int|string>,1:string} @@ -1034,20 +1044,23 @@ SQL; $values = []; switch ($type) { case 'a': //All PRIORITY_MAIN_STREAM - $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_NORMAL . ' '; + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_MAIN_STREAM . ' '; break; case 'A': //All except PRIORITY_ARCHIVED - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' '; + $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; + break; + case 'i': //Priority important feeds + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_IMPORTANT . ' '; break; case 's': //Starred. Deprecated: use $state instead - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' '; + $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_ARCHIVED . ' '; $where .= 'AND e.is_favorite=1 '; break; case 'S': //Starred $where .= 'e.is_favorite=1 '; break; case 'c': //Category - $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_NORMAL . ' '; + $where .= 'f.priority >= ' . FreshRSS_Feed::PRIORITY_CATEGORY . ' '; $where .= 'AND f.category=? '; $values[] = $id; break; @@ -1083,7 +1096,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST' $type * @param 'ASC'|'DESC' $order * @param int $id category/feed/tag ID * @return PDOStatement|false @@ -1118,7 +1131,7 @@ SQL; } /** - * @phpstan-param 'a'|'A'|'s'|'S'|'c'|'f'|'t'|'T'|'ST' $type + * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST' $type * @param int $id category/feed/tag ID * @param 'ASC'|'DESC' $order * @return Traversable<FreshRSS_Entry> @@ -1360,20 +1373,20 @@ SELECT c FROM ( FROM `_entry` AS e1 JOIN `_feed` AS f1 ON e1.id_feed = f1.id WHERE e1.is_favorite = 1 - AND f1.priority >= :priority_normal1 + AND f1.priority >= :priority1 UNION SELECT COUNT(e2.id) AS c, 2 AS o FROM `_entry` AS e2 JOIN `_feed` AS f2 ON e2.id_feed = f2.id WHERE e2.is_favorite = 1 - AND e2.is_read = 0 AND f2.priority >= :priority_normal2 + AND e2.is_read = 0 AND f2.priority >= :priority2 ) u ORDER BY o SQL; //Binding a value more than once is not standard and does not work with native prepared statements (e.g. MySQL) https://bugs.php.net/bug.php?id=40417 $res = $this->fetchColumn($sql, 0, [ - ':priority_normal1' => FreshRSS_Feed::PRIORITY_NORMAL, - ':priority_normal2' => FreshRSS_Feed::PRIORITY_NORMAL, + ':priority1' => FreshRSS_Feed::PRIORITY_CATEGORY, + ':priority2' => FreshRSS_Feed::PRIORITY_CATEGORY, ]); if ($res === null) { return ['all' => -1, 'unread' => -1, 'read' => -1]; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 405327ceb..b75d12b4e 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -28,8 +28,9 @@ class FreshRSS_Feed extends Minz_Model { */ public const KIND_JSON_XPATH = 20; + public const PRIORITY_IMPORTANT = 20; public const PRIORITY_MAIN_STREAM = 10; - public const PRIORITY_NORMAL = 0; + public const PRIORITY_CATEGORY = 0; public const PRIORITY_ARCHIVED = -10; public const TTL_DEFAULT = 0; diff --git a/app/Models/Themes.php b/app/Models/Themes.php index ab99ea63c..902d3c94b 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -101,6 +101,7 @@ class FreshRSS_Themes extends Minz_Model { 'FreshRSS-logo' => 'â', 'help' => 'âšī¸', //â 'icon' => 'â', + 'important' => 'đ', 'key' => 'đ', //âŋ 'label' => 'đˇī¸', 'link' => 'âī¸', //â |
