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 function delete()
40 DI::apiResponse()->unsupported(Router::DELETE);
43 public function post()
45 DI::apiResponse()->unsupported(Router::POST);
49 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
51 public function rawContent()
53 self::checkAllowedScope(self::SCOPE_READ);
54 $uid = self::getCurrentUserID();
56 if (empty($this->parameters['id'])) {
57 DI::mstdnError()->UnprocessableEntity();
60 $id = $this->parameters['id'];
61 if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
62 DI::mstdnError()->RecordNotFound();
65 $request = self::getRequest([
66 'max_id' => 0, // Return results older than this id
67 'since_id' => 0, // Return results newer than this id
68 'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination.
71 $params = ['order' => ['contact-id' => true]];
73 if ($request['limit'] != 0) {
74 $params['limit'] = min($request['limit'], 40);
77 $condition = ['gid' => $id];
79 if (!empty($request['max_id'])) {
80 $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $request['max_id']]);
83 if (!empty($request['since_id'])) {
84 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['since_id']]);
87 if (!empty($min_id)) {
88 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
90 $params['order'] = ['contact-id'];
95 $members = DBA::select('group_member', ['contact-id'], $condition, $params);
96 while ($member = DBA::fetch($members)) {
97 self::setBoundaries($member['contact-id']);
98 $accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
100 DBA::close($members);
102 if (!empty($min_id)) {
103 array_reverse($accounts);
106 self::setLinkHeader();
107 System::jsonExit($accounts);