Browse Source

Do not omit zero-unread items in TTRSS getCounter operation

Though TTRSS itself (usually) omits items that have a counter of zero, at least one client takes this to mean the last-seen counter is unchanged, rather than zero.
microsub
J. King 6 years ago
parent
commit
af42bceac0
  1. 1
      README.md
  2. 27
      lib/REST/TinyTinyRSS/API.php

1
README.md

@ -140,6 +140,7 @@ We are not aware of any other extensions to the TTRSS protocol. If you know of a
- Article hashes are normally SHA1; The Arsse uses SHA256 hashes
- Article attachments normally have unique IDs; The Arsse always gives attachments an ID of `"0"`
- The default sort order of the `getHeadlines` operation normally uses custom sorting for "special" feeds; The Arsse's default sort order is equivalent to `feed_dates` for all feeds
- The `getCounters` operation normally omits members with zero unread; The Arsse includes everything to appease some clients
#### Errors and ambiguities

27
lib/REST/TinyTinyRSS/API.php

@ -230,14 +230,12 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
$categories[] = ['id' => self::CAT_LABELS, 'name' => Arsse::$lang->msg("API.TTRSS.Category.Labels"), 'parent' => 0, 'children' => 0, 'counter' => 0];
// prepare data for each subscription; we also add unread counts for their host categories
foreach (Arsse::$db->subscriptionList($user) as $f) {
if ($f['unread']) {
// add the feed to the list of feeds
$feeds[] = ['id' => (string) $f['id'], 'updated' => Date::transform($f['updated'], "iso8601", "sql"),'counter' => $f['unread'], 'has_img' => (int) (strlen((string) $f['favicon']) > 0)]; // ID is cast to string for consistency with TTRSS
// add the feed's unread count to the global unread count
$countAll += $f['unread'];
// add the feed's unread count to its category unread count
$categories[$catmap[(int) $f['folder']]]['counter'] += $f['unread'];
}
// add the feed to the list of feeds
$feeds[] = ['id' => (string) $f['id'], 'updated' => Date::transform($f['updated'], "iso8601", "sql"),'counter' => $f['unread'], 'has_img' => (int) (strlen((string) $f['favicon']) > 0)]; // ID is cast to string for consistency with TTRSS
// add the feed's unread count to the global unread count
$countAll += $f['unread'];
// add the feed's unread count to its category unread count
$categories[$catmap[(int) $f['folder']]]['counter'] += $f['unread'];
// increment the global feed count
$countSubs += 1;
}
@ -247,9 +245,8 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
$labels[] = ['id' => $this->labelOut($l['id']), 'counter' => $unread, 'auxcounter' => $l['articles']];
$categories[$catmap[self::CAT_LABELS]]['counter'] += $unread;
}
// do a second pass on categories, summing descendant unread counts for ancestors
// do a second pass on categories, summing descendant unread counts for ancestors and building a final list
$cats = $categories;
$catCounts = [];
while ($cats) {
foreach ($cats as $c) {
if ($c['children']) {
@ -261,18 +258,12 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
$cats[$catmap[$c['parent']]]['counter'] += $c['counter'];
$cats[$catmap[$c['parent']]]['children'] -= 1;
}
$catCounts[$c['id']] = $c['counter'];
// output the category
$cats[] = ['id' => $c['id'], 'kind' => "cat", 'counter' => $c['counter']];
// remove the category from the input list
unset($cats[$catmap[$c['id']]]);
}
}
// do a third pass on categories, building a final category list
foreach ($categories as $c) {
// only include categories with unread articles
if ($catCounts[$c['id']]) {
$cats[] = ['id' => $c['id'], 'kind' => "cat", 'counter' => $catCounts[$c['id']]];
}
}
// prepare data for the virtual feeds and other counters
$special = [
['id' => "global-unread", 'counter' => $countAll], //this should not count archived articles, but we do not have an archive

Loading…
Cancel
Save