Add offset parameter to Mastodon trending Links and Statuses endpoints

This commit is contained in:
Hank Grabowski 2023-02-17 11:59:30 -05:00
parent 6a94632131
commit e6c93d31c1
2 changed files with 4 additions and 2 deletions

View file

@ -41,6 +41,7 @@ class Links extends BaseApi
{
$request = $this->getRequest([
'limit' => 10, // Maximum number of results to return. Defaults to 10.
'offset' => 0, // Offset page, Defaults to 0.
], $request);
$condition = ["EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-view`.`uri-id` AND `type` = ? AND NOT `name` IS NULL AND NOT `description` IS NULL) AND NOT `private` AND `commented` > ? AND `created` > ?",
@ -48,7 +49,7 @@ class Links extends BaseApi
$condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
$trending = [];
$statuses = Post::selectPostThread(['uri-id', 'total-comments', 'total-actors'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
$statuses = Post::selectPostThread(['uri-id', 'total-comments', 'total-actors'], $condition, ['limit' => [$request['offset'], $request['limit']], 'offset' => $request['offset'], 'order' => ['total-actors' => true]]);
while ($status = Post::fetch($statuses)) {
$history = [['day' => (string)time(), 'uses' => (string)$status['total-comments'], 'accounts' => (string)$status['total-actors']]];
$trending[] = DI::mstdnCard()->createFromUriId($status['uri-id'], $history)->toArray();

View file

@ -44,6 +44,7 @@ class Statuses extends BaseApi
$request = $this->getRequest([
'limit' => 10, // Maximum number of results to return. Defaults to 10.
'offset' => 0, // Offset page, Defaults to 0.
], $request);
$condition = ["NOT `private` AND `commented` > ? AND `created` > ?", DateTimeFormat::utc('now -1 day'), DateTimeFormat::utc('now -1 week')];
@ -52,7 +53,7 @@ class Statuses extends BaseApi
$display_quotes = self::appSupportsQuotes();
$trending = [];
$statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
$statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => [$request['offset'], $request['limit']], 'order' => ['total-actors' => true]]);
while ($status = Post::fetch($statuses)) {
try {
$trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid, $display_quotes);