From acb3973149db12eeb95ad207d2f476ab37a9e148 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 26 Mar 2019 08:53:26 -0400 Subject: [PATCH] Prototype implementation of Fever groups and feeds --- lib/Database.php | 2 +- lib/REST/Fever/API.php | 65 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/lib/Database.php b/lib/Database.php index bfbcfee1..86bb8b35 100644 --- a/lib/Database.php +++ b/lib/Database.php @@ -748,7 +748,7 @@ class Database { $q = new Query( "SELECT arsse_subscriptions.id as id, - arsse_subscriptions.feed, + arsse_subscriptions.feed as feed, url,favicon,source,folder,pinned,err_count,err_msg,order_type,added, arsse_feeds.updated as updated, topmost.top as top_folder, diff --git a/lib/REST/Fever/API.php b/lib/REST/Fever/API.php index c4ad36b4..0d24337a 100644 --- a/lib/REST/Fever/API.php +++ b/lib/REST/Fever/API.php @@ -12,9 +12,9 @@ use JKingWeb\Arsse\User; use JKingWeb\Arsse\Service; use JKingWeb\Arsse\Context\Context; use JKingWeb\Arsse\Misc\ValueInfo; +use JKingWeb\Arsse\Misc\Date; use JKingWeb\Arsse\AbstractException; use JKingWeb\Arsse\Db\ExceptionInput; -use JKingWeb\Arsse\Feed\Exception as FeedException; use JKingWeb\Arsse\REST\Target; use JKingWeb\Arsse\REST\Exception404; use JKingWeb\Arsse\REST\Exception405; @@ -65,7 +65,19 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { return $this->formatResponse($out, $xml); } // handle each possible parameter - # do stuff + if (array_key_exists("feeds", $inR) || array_key_exists("groups", $inR)) { + $groupData = (array) Arsse::$db->tagSummarize(Arsse::$user->id); + if (array_key_exists("groups", $inR)) { + $out['groups'] = $this->getGroups($groupData); + } + if (array_key_exists("feeds", $inR)) { + $out['feeds'] = $this->getFeeds(); + } + $out['feeds_groups'] = $this->getRelationships($groupData); + } + if (array_key_exists("favicons", $inR)) { + # deal with favicons + } // return the result return $this->formatResponse($out, $xml); break; @@ -97,4 +109,53 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { Arsse::$user->id = $s['user']; return true; } + + protected function getFeeds(): array { + $out = []; + foreach (arsse::$db->subscriptionList(Arsse::$user->id) as $sub) { + $out[] = [ + 'id' => (int) $sub['id'], + 'favicon_id' => (int) ($sub['favicon'] ? $sub['feed'] : 0), + 'title' => (string) $sub['title'], + 'url' => $sub['url'], + 'site_url' => $sub['source'], + 'is_spark' => 0, + 'lat_updated_on_time' => Date::transform($sub['updated'], "unix"), + ]; + } + return $out; + } + + protected function getGroups(array $data): array { + $out = []; + $seen = []; + foreach ($data as $member) { + if (!($seen[$member['id']] ?? false)) { + $seen[$member['id']] = true; + $out[] = [ + 'id' => (int) $member['id'], + 'title' => $member['name'], + ]; + } + } + return $out; + } + + protected function getRelationships(array $data): array { + $out = []; + $sets = []; + foreach ($data as $member) { + if (!isset($sets[$member['id']])) { + $sets[$member['id']] = []; + } + $sets[$member['id']][] = (int) $member['subscription']; + } + foreach ($sets as $id => $subs) { + $out[] = [ + 'group_id' => (int) $id, + 'feed_ids' => implode(",", $subs), + ]; + } + return $out; + } }