Merge pull request #9139 from annando/timeline-parameters

API: Fix the timeline parameters
This commit is contained in:
Tobias Diekershoff 2020-09-05 08:20:46 +02:00 committed by GitHub
commit 0bc4829af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@
namespace Friendica\Module\Api\Mastodon\Timelines; namespace Friendica\Module\Api\Mastodon\Timelines;
use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
@ -42,7 +43,7 @@ class PublicTimeline extends BaseApi
// Show only local statuses? Defaults to false. // Show only local statuses? Defaults to false.
$local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true'); $local = (bool)!isset($_REQUEST['local']) ? false : ($_REQUEST['local'] == 'true');
// Show only remote statuses? Defaults to false. // 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. // Show only statuses with media attached? Defaults to false.
$only_media = (bool)!isset($_REQUEST['only_media']) ? false : ($_REQUEST['only_media'] == 'true'); // Currently not supported $only_media = (bool)!isset($_REQUEST['only_media']) ? false : ($_REQUEST['only_media'] == 'true'); // Currently not supported
// Return results older than this id // Return results older than this id
@ -50,32 +51,47 @@ class PublicTimeline extends BaseApi
// Return results newer than this id // Return results newer than this id
$since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
// Return results immediately newer than this 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. // Maximum number of results to return. Defaults to 20.
$limit = (int)!isset($_REQUEST['limit']) ? 20 : $_REQUEST['limit']; $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) { if ($local) {
$condition['origin'] = true; $condition['origin'] = true;
} else { } else {
$condition['uid'] = 0; $condition['uid'] = 0;
} }
if ($remote) {
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `item` WHERE `origin`)"]);
}
if (!empty($max_id)) { if (!empty($max_id)) {
$condition = DBA::mergeConditions($condition, ["`id` <= ?", $max_id]); $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
} }
if (!empty($since_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 = []; $statuses = [];
foreach ($items as $item) { foreach ($items as $item) {
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']); $statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $item['uid']);
} }
if (!empty($min_id)) {
array_reverse($statuses);
}
System::jsonExit($statuses); System::jsonExit($statuses);
} }
} }