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\Api\ApiResponse;
29 use Friendica\Module\BaseApi;
32 * @see https://docs.joinmastodon.org/methods/timelines/lists/#accounts-in-a-list
34 * Currently the output will be unordered since we use public contact ids in the api and not user contact ids.
36 class Accounts extends BaseApi
38 public static function delete(array $parameters = [])
40 DI::apiResponse()->unsupported(Router::DELETE);
43 public static function post(array $parameters = [])
45 DI::apiResponse()->unsupported(Router::POST);
49 * @param array $parameters
50 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
52 public static function rawContent(array $parameters = [])
54 self::checkAllowedScope(self::SCOPE_READ);
55 $uid = self::getCurrentUserID();
57 if (empty($parameters['id'])) {
58 DI::mstdnError()->UnprocessableEntity();
61 $id = $parameters['id'];
62 if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
63 DI::mstdnError()->RecordNotFound();
66 $request = self::getRequest([
67 'max_id' => 0, // Return results older than this id
68 'since_id' => 0, // Return results newer than this id
69 'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination.
72 $params = ['order' => ['contact-id' => true]];
74 if ($request['limit'] != 0) {
75 $params['limit'] = min($request['limit'], 40);
78 $condition = ['gid' => $id];
80 if (!empty($request['max_id'])) {
81 $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $request['max_id']]);
84 if (!empty($request['since_id'])) {
85 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['since_id']]);
88 if (!empty($min_id)) {
89 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
91 $params['order'] = ['contact-id'];
96 $members = DBA::select('group_member', ['contact-id'], $condition, $params);
97 while ($member = DBA::fetch($members)) {
98 self::setBoundaries($member['contact-id']);
99 $accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
101 DBA::close($members);
103 if (!empty($min_id)) {
104 array_reverse($accounts);
107 self::setLinkHeader();
108 System::jsonExit($accounts);