3 namespace Friendica\Module\Api\Mastodon;
5 use Friendica\Api\Mastodon\Account;
6 use Friendica\App\BaseURL;
7 use Friendica\Core\System;
8 use Friendica\Database\DBA;
9 use Friendica\Model\Contact;
10 use Friendica\Module\Base\Api;
11 use Friendica\Network\HTTPException;
14 * @see https://docs.joinmastodon.org/api/rest/follow-requests/
16 class FollowRequests extends Api
18 public static function init(array $parameters = [])
20 parent::init($parameters);
26 * @param array $parameters
27 * @throws HTTPException\InternalServerErrorException
28 * @see https://docs.joinmastodon.org/api/rest/follow-requests/#get-api-v1-follow-requests
30 public static function rawContent(array $parameters = [])
32 $since_id = $_GET['since_id'] ?? null;
33 $max_id = $_GET['max_id'] ?? null;
34 $limit = intval($_GET['limit'] ?? 40);
36 if (isset($since_id) && isset($max_id)) {
37 $condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` > ? AND `id` < ?', self::$current_user_id, $since_id, $max_id];
38 } elseif (isset($since_id)) {
39 $condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` > ?', self::$current_user_id, $since_id];
40 } elseif (isset($max_id)) {
41 $condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` < ?', self::$current_user_id, $max_id];
43 $condition = ['`uid` = ? AND NOT `self` AND `pending`', self::$current_user_id];
46 $count = DBA::count('contact', $condition);
48 $contacts = Contact::selectToArray(
51 ['order' => ['id' => 'DESC'], 'limit' => $limit]
55 foreach ($contacts as $contact) {
56 $account = Account::createFromContact($contact);
62 if (isset($_GET['limit'])) {
63 $base_query['limit'] = $limit;
66 /** @var BaseURL $BaseURL */
67 $BaseURL = self::getClass(BaseURL::class);
70 if ($count > $limit) {
71 $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $contacts[count($contacts) - 1]['id']]) . '>; rel="next"';
73 $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $contacts[0]['id']]) . '>; rel="prev"';
75 header('Link: ' . implode(', ', $links));
77 System::jsonExit($return);