X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FApi%2FMastodon%2FLists%2FAccounts.php;h=feb670b271182644400a5353212e7744df9ca73a;hb=87084a3e854b72290fcc49e66fd0ccdf737672ee;hp=cb2bd208f30f9ce1db610dcd314e032378afb4e0;hpb=9125d296a15ad147f3807dd3eb135ec103779308;p=friendica.git diff --git a/src/Module/Api/Mastodon/Lists/Accounts.php b/src/Module/Api/Mastodon/Lists/Accounts.php index cb2bd208f3..feb670b271 100644 --- a/src/Module/Api/Mastodon/Lists/Accounts.php +++ b/src/Module/Api/Mastodon/Lists/Accounts.php @@ -21,74 +21,72 @@ namespace Friendica\Module\Api\Mastodon\Lists; +use Friendica\App\Router; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Module\Api\ApiResponse; use Friendica\Module\BaseApi; /** - * @see https://docs.joinmastodon.org/methods/timelines/lists/ + * @see https://docs.joinmastodon.org/methods/timelines/lists/#accounts-in-a-list * * Currently the output will be unordered since we use public contact ids in the api and not user contact ids. */ class Accounts extends BaseApi { - public static function delete(array $parameters = []) + public function delete() { - self::unsupported('delete'); + DI::apiResponse()->unsupported(Router::DELETE); } - public static function post(array $parameters = []) + public function post() { - self::unsupported('post'); + DI::apiResponse()->unsupported(Router::POST); } /** - * @param array $parameters * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function rawContent(array $parameters = []) + public function rawContent() { - self::login(); + self::checkAllowedScope(self::SCOPE_READ); $uid = self::getCurrentUserID(); - if (empty($parameters['id'])) { + if (empty($this->parameters['id'])) { DI::mstdnError()->UnprocessableEntity(); } - $id = $parameters['id']; + $id = $this->parameters['id']; if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) { DI::mstdnError()->RecordNotFound(); } - // Return results older than this id - $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id']; - // Return results newer than this id - $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id']; - // Maximum number of results. Defaults to 40. Max 40. - // Set to 0 in order to get all accounts without pagination. - $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit']; - + $request = self::getRequest([ + 'max_id' => 0, // Return results older than this id + 'since_id' => 0, // Return results newer than this id + 'min_id' => 0, // Return results immediately newer than id + 'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination. + ]); $params = ['order' => ['contact-id' => true]]; - if ($limit != 0) { - $params['limit'] = $limit; - + if ($request['limit'] != 0) { + $params['limit'] = min($request['limit'], 40); } - + $condition = ['gid' => $id]; - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]); + if (!empty($request['max_id'])) { + $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $request['max_id']]); } - if (!empty($since_id)) { - $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]); + if (!empty($request['since_id'])) { + $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['since_id']]); } - if (!empty($min_id)) { - $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]); + if (!empty($request['min_id'])) { + $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['min_id']]); $params['order'] = ['contact-id']; } @@ -97,14 +95,16 @@ class Accounts extends BaseApi $members = DBA::select('group_member', ['contact-id'], $condition, $params); while ($member = DBA::fetch($members)) { + self::setBoundaries($member['contact-id']); $accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid); } DBA::close($members); - if (!empty($min_id)) { + if (!empty($request['min_id'])) { array_reverse($accounts); } + self::setLinkHeader(); System::jsonExit($accounts); } }