From 348028a29043b7d1d0f80544c44f0454b2c375c3 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 8 Nov 2023 20:23:54 +0100 Subject: New feature important feeds (#5782) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- app/Models/EntryDAO.php | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'app/Models/EntryDAO.php') 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,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 @@ -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]; -- cgit v1.2.3