From 53e3e4932469965882134413fdd8acc78cce28d0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 16 Dec 2017 15:41:50 -0500 Subject: [PATCH 1/3] Add statuses/networkpublic_timeline api method --- include/api.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/include/api.php b/include/api.php index 2501fd237..bedac23ac 100644 --- a/include/api.php +++ b/include/api.php @@ -1661,6 +1661,71 @@ function api_statuses_public_timeline($type) /// @TODO move to top of file or somewhere better api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline', true); +/** + * @brief Returns the list of public federated posts this node knows about + * + * @param string $type Return format: json, xml, atom, rss + * @return array|string + * @throws ForbiddenException + */ +function api_statuses_networkpublic_timeline($type) +{ + $a = get_app(); + + if (api_user() === false) { + throw new ForbiddenException(); + } + + $user_info = api_get_user($a); + + $since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0; + $max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0; + + // pagination + $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 20; + $page = x($_REQUEST, 'page') ? $_REQUEST['page'] : 1; + if ($page < 1) { + $page = 1; + } + $start = ($page - 1) * $count; + + $sql_extra = ''; + if ($max_id > 0) { + $sql_extra = 'AND `item`.`id` <= ' . intval($max_id); + } + + $r = dba::p("SELECT " . item_fieldlists() . " + FROM `thread` + INNER JOIN `item` ON `item`.`id` = `thread`.`iid` + " . item_joins() . " + WHERE `thread`.`uid` = 0 + AND `verb` = ? + AND `item`.`id` > ? + $sql_extra + ORDER BY `thread`.`created` DESC + LIMIT " . intval($start) . ", " . intval($count), + ACTIVITY_POST, + $since_id + ); + + $r = dba::inArray($r); + + $ret = api_format_items($r, $user_info, false, $type); + + $data = array('status' => $ret); + switch ($type) { + case "atom": + case "rss": + $data = api_rss_extra($a, $data, $user_info); + break; + } + + return api_format_data("statuses", $type, $data); +} + +/// @TODO move to top of file or somewhere better +api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpublic_timeline', true); + /** * @TODO nothing to say? */ From dcc0a779495ec956c0d91201f152eea4b23da4e4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 17 Dec 2017 08:51:57 -0500 Subject: [PATCH 2/3] Add doc entry for statuses/networkpublic_timeline api --- doc/api.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/api.md b/doc/api.md index ca355eef6..159bc6991 100644 --- a/doc/api.md +++ b/doc/api.md @@ -338,6 +338,15 @@ Friendica doesn't allow showing the friends of other users. #### Unsupported parameters * trim_user +--- +### statuses/networkpublic_timeline (*; AUTH) +#### Parameters +* count: Items per page (default: 20) +* page: page number +* since_id: minimum id +* max_id: maximum id +* include_entities: "true" shows entities for pictures and links (Default: false) + --- ### statuses/replies (*; AUTH) #### Parameters From cdd5bd5615718094fba948e3d7d80a7082737be4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 17 Dec 2017 10:06:12 -0500 Subject: [PATCH 3/3] Improve networkpublic_timeline SQL performance - Use thread.iid for max_id and ordering --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index bedac23ac..b06629ff6 100644 --- a/include/api.php +++ b/include/api.php @@ -1691,7 +1691,7 @@ function api_statuses_networkpublic_timeline($type) $sql_extra = ''; if ($max_id > 0) { - $sql_extra = 'AND `item`.`id` <= ' . intval($max_id); + $sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id); } $r = dba::p("SELECT " . item_fieldlists() . " @@ -1702,7 +1702,7 @@ function api_statuses_networkpublic_timeline($type) AND `verb` = ? AND `item`.`id` > ? $sql_extra - ORDER BY `thread`.`created` DESC + ORDER BY `thread`.`iid` DESC LIMIT " . intval($start) . ", " . intval($count), ACTIVITY_POST, $since_id