diff options
author | Andrew Dolgov <[email protected]> | 2021-02-24 15:07:31 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-24 15:07:31 +0300 |
commit | 553548b6897f8ef292ab56af9dcc196ef8ee0cb3 (patch) | |
tree | feae3a51d884e216d4d460634024ef7884227b14 /classes/rpc.php | |
parent | 9313ebf2e745731263a8e24d19473adb70dfee47 (diff) |
request label counters conditionally
Diffstat (limited to 'classes/rpc.php')
-rwxr-xr-x | classes/rpc.php | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/classes/rpc.php b/classes/rpc.php index b9fd492fa..2cc2e3879 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -73,11 +73,26 @@ class RPC extends Handler_Protected { } function getAllCounters() { - $feed_ids = array_map("intval", clean($_REQUEST["feed_ids"] ?? [])); @$seq = (int) $_REQUEST['seq']; + $feed_id_count = (int)$_REQUEST["feed_id_count"]; + $label_id_count = (int)$_REQUEST["label_id_count"]; + + // it seems impossible to distinguish empty array [] from a null - both become unset in $_REQUEST + // so, count is >= 0 means we had an array, -1 means null + // we need null because it means "return all counters"; [] would return nothing + if ($feed_id_count == -1) + $feed_ids = null; + else + $feed_ids = array_map("intval", clean($_REQUEST["feed_ids"] ?? [])); + + if ($label_id_count == -1) + $label_ids = null; + else + $label_ids = array_map("intval", clean($_REQUEST["label_ids"] ?? [])); + // @phpstan-ignore-next-line - $counters = count($feed_ids) > 0 ? Counters::get_for_feeds($feed_ids) : Counters::get_all(); + $counters = is_array($feed_ids) ? Counters::get_conditional($feed_ids, $label_ids) : Counters::get_all(); $reply = [ 'counters' => $counters, @@ -95,16 +110,20 @@ class RPC extends Handler_Protected { $ids = array_map("intval", clean($_REQUEST["ids"] ?? [])); $cmode = (int)clean($_REQUEST["cmode"]); - Article::_catchup_by_id($ids, $cmode); + if (count($ids) > 0) + Article::_catchup_by_id($ids, $cmode); - print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]); + print json_encode(["message" => "UPDATE_COUNTERS", + "labels" => Article::_labels_of($ids), + "feeds" => Article::_feeds_of($ids)]); } function markSelected() { $ids = array_map("intval", clean($_REQUEST["ids"] ?? [])); $cmode = (int)clean($_REQUEST["cmode"]); - $this->markArticlesById($ids, $cmode); + if (count($ids) > 0) + $this->markArticlesById($ids, $cmode); print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]); } @@ -113,7 +132,8 @@ class RPC extends Handler_Protected { $ids = array_map("intval", clean($_REQUEST["ids"] ?? [])); $cmode = (int)clean($_REQUEST["cmode"]); - $this->publishArticlesById($ids, $cmode); + if (count($ids) > 0) + $this->publishArticlesById($ids, $cmode); print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]); } |