fossar / selfoss

multipurpose rss reader, live stream, mashup, aggregation web application
https://selfoss.aditu.de
GNU General Public License v3.0
2.38k stars 345 forks source link

Query read items from the api #1252

Open davidoskky opened 3 years ago

davidoskky commented 3 years ago

I believe it was previously possible to query read items from the api calling /items with the parameter type set to read. Would it be possible to add back this functionality in order to selectively get read items?

jtojnar commented 3 years ago

I do not think it was possible to filter for read but we can add it here:

https://github.com/fossar/selfoss/blob/c35fb9c8cc12d2a589d4ded6e9791eac6a9effbe/src/daos/mysql/Items.php#L234-L245

davidoskky commented 3 years ago

Oh, then I am sorry if I have to make you add a new functionality, but I believe it would be really useful.

jtojnar commented 3 years ago

It is quite simple change:

--- a/src/daos/mysql/Items.php
+++ b/src/daos/mysql/Items.php
@@ -231,16 +231,19 @@ class Items implements \daos\ItemsInterface {
         $where = [$stmt::bool(true)];
         $order = 'DESC';

-        // only starred
-        if (isset($options['type']) && $options['type'] === 'starred') {
-            $where[] = $stmt::isTrue('starred');
-        }
-
-        // only unread
-        elseif (isset($options['type']) && $options['type'] === 'unread') {
-            $where[] = $stmt::isTrue('unread');
-            if (\F3::get('unread_order') === 'asc') {
-                $order = 'ASC';
+        if (isset($options['type'])) {
+            if ($options['type'] === 'starred') {
+                // only starred
+                $where[] = $stmt::isTrue('starred');
+            } elseif ($options['type'] === 'read') {
+                // only read
+                $where[] = $stmt::isFalse('unread');
+            } elseif ($options['type'] === 'unread') {
+                // only unread
+                $where[] = $stmt::isTrue('unread');
+                if (\F3::get('unread_order') === 'asc') {
+                    $order = 'ASC';
+                }
             }
         }
davidoskky commented 3 years ago

I tested this, it works exactly as expected, thank you!