diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php new file mode 100644 index 000000000..515dc451c --- /dev/null +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -0,0 +1,79 @@ + ? AND `id` < ?', self::$current_user_id, $since_id, $max_id]; + } elseif (isset($since_id)) { + $condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` > ?', self::$current_user_id, $since_id]; + } elseif (isset($max_id)) { + $condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` < ?', self::$current_user_id, $max_id]; + } else { + $condition = ['`uid` = ? AND NOT `self` AND `pending`', self::$current_user_id]; + } + + $count = DBA::count('contact', $condition); + + $contacts = Contact::selectToArray( + [], + $condition, + ['order' => ['id' => 'DESC'], 'limit' => $limit] + ); + + $return = []; + foreach ($contacts as $contact) { + $account = Account::createFromContact($contact); + + $return[] = $account; + } + + $base_query = []; + if (isset($_GET['limit'])) { + $base_query['limit'] = $limit; + } + + /** @var BaseURL $BaseURL */ + $BaseURL = self::getClass(BaseURL::class); + + $links = []; + if ($count > $limit) { + $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $contacts[count($contacts) - 1]['id']]) . '>; rel="next"'; + } + $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $contacts[0]['id']]) . '>; rel="prev"'; + + header('Link: ' . implode(', ', $links)); + + System::jsonExit($return); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index f5b44aec2..d8113c5c5 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -27,6 +27,12 @@ return [ '/recovery' => [Module\TwoFactor\Recovery::class, [R::GET, R::POST]], ], + '/api' => [ + '/v1' => [ + '/follow_requests' => [Module\Api\Mastodon\FollowRequests::class, [R::GET ]], + ], + ], + '/admin' => [ '[/]' => [Module\Admin\Summary::class, [R::GET]],