mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:00:16 +00:00
Merge pull request #9139 from annando/timeline-parameters
API: Fix the timeline parameters
This commit is contained in:
commit
0bc4829af2
1 changed files with 22 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue