Add paging to Account/Statuses Mastodon endpoint

pull/12904/head
Hank Grabowski 2023-03-17 22:13:17 -04:00
parent 5d92083a6f
commit e969ecd351
1 changed files with 14 additions and 23 deletions

View File

@ -31,6 +31,7 @@ use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Verb;
use Friendica\Module\BaseApi;
use Friendica\Object\Api\Mastodon\TimelineOrderByTypes;
use Friendica\Protocol\Activity;
/**
@ -56,19 +57,18 @@ class Statuses extends BaseApi
$request = $this->getRequest([
'only_media' => false, // Show only statuses with media attached? Defaults to false.
'max_id' => 0, // Return results older than this id
'since_id' => 0, // Return results newer than this id
'min_id' => 0, // Return results immediately newer than this id
'max_id' => null, // Return results older than this id
'since_id' => null, // Return results newer than this id
'min_id' => null, // Return results immediately newer than this id
'limit' => 20, // Maximum number of results to return. Defaults to 20.
'pinned' => false, // Only pinned posts
'exclude_replies' => false, // Don't show comments
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
'exclude_reblogs' => false, // Undocumented parameter
'tagged' => false, // Undocumented parameter
'friendica_order' => TimelineOrderByTypes::ID, // order options (defaults to ID)
], $request);
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
if ($request['pinned']) {
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'type' => Post\Collection::FEATURED];
} elseif ($request['only_media']) {
@ -80,6 +80,9 @@ class Statuses extends BaseApi
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
}
$condition = $this->addPagingConditions($request, $condition);
$params = $this->buildOrderAndLimitParams($request);
if (!$request['pinned'] && !$request['only_media']) {
if ($request['exclude_replies']) {
$condition = DBA::mergeConditions($condition, ["(`gravity` = ? OR (`gravity` = ? AND `vid` = ? AND `protocol` != ?))",
@ -92,19 +95,6 @@ class Statuses extends BaseApi
$condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
}
if (!empty($request['max_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
}
if (!empty($request['since_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
}
if (!empty($request['min_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
$params['order'] = ['uri-id'];
}
if ($request['pinned']) {
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
} elseif ($request['only_media']) {
@ -117,11 +107,12 @@ class Statuses extends BaseApi
$statuses = [];
while ($item = Post::fetch($items)) {
self::setBoundaries($item['uri-id']);
try {
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
} catch (\Exception $exception) {
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'exception' => $exception]);
$status = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid, $display_quotes);
$this->updateBoundaries($status, $item, $request['friendica_order']);
$statuses[] = $status;
} catch (\Throwable $th) {
Logger::info('Post not fetchable', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'error' => $th]);
}
}
DBA::close($items);
@ -130,7 +121,7 @@ class Statuses extends BaseApi
$statuses = array_reverse($statuses);
}
self::setLinkHeader();
self::setLinkHeader($request['friendica_order'] != TimelineOrderByTypes::ID);
System::jsonExit($statuses);
}
}