3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Mastodon\Lists;
24 use Friendica\App\Router;
25 use Friendica\Core\System;
26 use Friendica\Database\DBA;
28 use Friendica\Module\BaseApi;
31 * @see https://docs.joinmastodon.org/methods/timelines/lists/#accounts-in-a-list
33 * Currently the output will be unordered since we use public contact ids in the api and not user contact ids.
35 class Accounts extends BaseApi
37 public static function delete(array $parameters = [])
39 self::unsupported(Router::DELETE);
42 public static function post(array $parameters = [])
44 self::unsupported(Router::POST);
48 * @param array $parameters
49 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
51 public static function rawContent(array $parameters = [])
53 self::checkAllowedScope(self::SCOPE_READ);
54 $uid = self::getCurrentUserID();
56 if (empty($parameters['id'])) {
57 DI::mstdnError()->UnprocessableEntity();
60 $id = $parameters['id'];
61 if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
62 DI::mstdnError()->RecordNotFound();
65 // @todo provide HTTP link header
67 $request = self::getRequest([
68 'max_id' => 0, // Return results older than this id
69 'since_id' => 0, // Return results newer than this id
70 'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination.
73 $params = ['order' => ['contact-id' => true]];
75 if ($request['limit'] != 0) {
76 $params['limit'] = min($request['limit'], 40);
79 $condition = ['gid' => $id];
81 if (!empty($request['max_id'])) {
82 $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $request['max_id']]);
85 if (!empty($request['since_id'])) {
86 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['since_id']]);
89 if (!empty($min_id)) {
90 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
92 $params['order'] = ['contact-id'];
97 $members = DBA::select('group_member', ['contact-id'], $condition, $params);
98 while ($member = DBA::fetch($members)) {
99 self::setBoundaries($member['contact-id']);
100 $accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
102 DBA::close($members);
104 if (!empty($min_id)) {
105 array_reverse($accounts);
108 self::setLinkHeader();
109 System::jsonExit($accounts);