From c3ed31bb8f57fc6ca61393b34d3d6cf72354076b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Sep 2020 05:38:12 +0000 Subject: [PATCH] API: Fix the timeline parameters --- .../Api/Mastodon/Timelines/PublicTimeline.php | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php index d97d8e4f5c..9a42521d90 100644 --- a/src/Module/Api/Mastodon/Timelines/PublicTimeline.php +++ b/src/Module/Api/Mastodon/Timelines/PublicTimeline.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon\Timelines; +use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; @@ -42,7 +43,7 @@ class PublicTimeline extends BaseApi // Show only local statuses? Defaults to false. $local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true'); // Show only remote statuses? Defaults to false. - $remote = (bool)!isset($_REQUEST['remote']) ? false : ($_REQUEST['remote'] == 'true'); // Currently not supported + $remote = (bool)!isset($_REQUEST['remote']) ? false : ($_REQUEST['remote'] == 'true'); // Show only statuses with media attached? Defaults to false. $only_media = (bool)!isset($_REQUEST['only_media']) ? false : ($_REQUEST['only_media'] == 'true'); // Currently not supported // Return results older than this id @@ -50,32 +51,47 @@ class PublicTimeline extends BaseApi // Return results newer than this id $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; // Return results immediately newer than this id - $min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id']; // Currently not supported + $min_id = (int)!isset($_REQUEST['min_id']) ? 0 : $_REQUEST['min_id']; // Maximum number of results to return. Defaults to 20. $limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit']; - $condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC]; + $params = ['order' => ['uri-id' => true], 'limit' => $limit]; + + $condition = ['gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => Item::PUBLIC, 'network' => Protocol::FEDERATED]; if ($local) { $condition['origin'] = true; } else { $condition['uid'] = 0; } + if ($remote) { + $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `origin`)"]); + } + if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`id` <= ?", $max_id]); + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]); } if (!empty($since_id)) { - $condition = DBA::mergeConditions($condition, ["`id` >= ?", $since_id]); + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]); } - $items = Item::selectForUser(0, ['uri-id', 'uid'], $condition, ['order' => ['id' => true], 'limit' => $limit]); + if (!empty($min_id)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]); + $params['order'] = ['uri-id']; + } + + $items = Item::selectForUser(0, ['uri-id', 'uid'], $condition, $params); $statuses = []; foreach ($items as $item) { $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']); } + if (!empty($min_id)) { + array_reverse($statuses); + } + System::jsonExit($statuses); } }