1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Prototype implementation of Fever groups and feeds

This commit is contained in:
J. King 2019-03-26 08:53:26 -04:00
parent 9c61f967e3
commit acb3973149
2 changed files with 64 additions and 3 deletions

View file

@ -748,7 +748,7 @@ class Database {
$q = new Query( $q = new Query(
"SELECT "SELECT
arsse_subscriptions.id as id, 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, url,favicon,source,folder,pinned,err_count,err_msg,order_type,added,
arsse_feeds.updated as updated, arsse_feeds.updated as updated,
topmost.top as top_folder, topmost.top as top_folder,

View file

@ -12,9 +12,9 @@ use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Service; use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Context\Context; use JKingWeb\Arsse\Context\Context;
use JKingWeb\Arsse\Misc\ValueInfo; use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\AbstractException; use JKingWeb\Arsse\AbstractException;
use JKingWeb\Arsse\Db\ExceptionInput; use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Feed\Exception as FeedException;
use JKingWeb\Arsse\REST\Target; use JKingWeb\Arsse\REST\Target;
use JKingWeb\Arsse\REST\Exception404; use JKingWeb\Arsse\REST\Exception404;
use JKingWeb\Arsse\REST\Exception405; use JKingWeb\Arsse\REST\Exception405;
@ -65,7 +65,19 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
return $this->formatResponse($out, $xml); return $this->formatResponse($out, $xml);
} }
// handle each possible parameter // 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 the result
return $this->formatResponse($out, $xml); return $this->formatResponse($out, $xml);
break; break;
@ -97,4 +109,53 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
Arsse::$user->id = $s['user']; Arsse::$user->id = $s['user'];
return true; 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;
}
} }