Add GET /api/v1/follow_requests Mastodon API endpoint
This commit is contained in:
parent
b365ffc3b5
commit
8016cb3cee
79
src/Module/Api/Mastodon/FollowRequests.php
Normal file
79
src/Module/Api/Mastodon/FollowRequests.php
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Module\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\Api\Mastodon\Account;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
|
use Friendica\Core\System;
|
||||||
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Module\Base\Api;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://docs.joinmastodon.org/api/rest/follow-requests/
|
||||||
|
*/
|
||||||
|
class FollowRequests extends Api
|
||||||
|
{
|
||||||
|
public static function init(array $parameters = [])
|
||||||
|
{
|
||||||
|
parent::init($parameters);
|
||||||
|
|
||||||
|
self::login();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $parameters
|
||||||
|
* @throws HTTPException\InternalServerErrorException
|
||||||
|
* @see https://docs.joinmastodon.org/api/rest/follow-requests/#get-api-v1-follow-requests
|
||||||
|
*/
|
||||||
|
public static function rawContent(array $parameters = [])
|
||||||
|
{
|
||||||
|
$since_id = $_GET['since_id'] ?? null;
|
||||||
|
$max_id = $_GET['max_id'] ?? null;
|
||||||
|
$limit = intval($_GET['limit'] ?? 40);
|
||||||
|
|
||||||
|
if (isset($since_id) && isset($max_id)) {
|
||||||
|
$condition = ['`uid` = ? AND NOT `self` AND `pending` AND `id` > ? 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,12 @@ return [
|
||||||
'/recovery' => [Module\TwoFactor\Recovery::class, [R::GET, R::POST]],
|
'/recovery' => [Module\TwoFactor\Recovery::class, [R::GET, R::POST]],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'/api' => [
|
||||||
|
'/v1' => [
|
||||||
|
'/follow_requests' => [Module\Api\Mastodon\FollowRequests::class, [R::GET ]],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
'/admin' => [
|
'/admin' => [
|
||||||
'[/]' => [Module\Admin\Summary::class, [R::GET]],
|
'[/]' => [Module\Admin\Summary::class, [R::GET]],
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue