From e6c93d31c17760c76909f0569176a1ec3050dc78 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 17 Feb 2023 11:59:30 -0500 Subject: [PATCH] Add offset parameter to Mastodon trending Links and Statuses endpoints --- src/Module/Api/Mastodon/Trends/Links.php | 3 ++- src/Module/Api/Mastodon/Trends/Statuses.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Module/Api/Mastodon/Trends/Links.php b/src/Module/Api/Mastodon/Trends/Links.php index 5cf2ed471..e2a160087 100644 --- a/src/Module/Api/Mastodon/Trends/Links.php +++ b/src/Module/Api/Mastodon/Trends/Links.php @@ -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(); diff --git a/src/Module/Api/Mastodon/Trends/Statuses.php b/src/Module/Api/Mastodon/Trends/Statuses.php index cf287e59c..6ae9c83dd 100644 --- a/src/Module/Api/Mastodon/Trends/Statuses.php +++ b/src/Module/Api/Mastodon/Trends/Statuses.php @@ -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);