selfoss icon indicating copy to clipboard operation
selfoss copied to clipboard

Query read items from the api

Open davidoskky opened this issue 4 years ago • 4 comments

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?

davidoskky avatar Mar 21 '21 16:03 davidoskky

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

jtojnar avatar Mar 22 '21 00:03 jtojnar

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

davidoskky avatar Mar 22 '21 06:03 davidoskky

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';
+                }
             }
         }
 

jtojnar avatar Mar 22 '21 09:03 jtojnar

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

davidoskky avatar Mar 22 '21 09:03 davidoskky