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\Core\System;
25 use Friendica\Database\DBA;
27 use Friendica\Module\BaseApi;
30 * @see https://docs.joinmastodon.org/methods/timelines/lists/
32 * Currently the output will be unordered since we use public contact ids in the api and not user contact ids.
34 class Accounts extends BaseApi
36 public static function delete(array $parameters = [])
38 self::unsupported('delete');
41 public static function post(array $parameters = [])
43 self::unsupported('post');
47 * @param array $parameters
48 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
50 public static function rawContent(array $parameters = [])
53 $uid = self::getCurrentUserID();
55 if (empty($parameters['id'])) {
56 DI::mstdnError()->RecordNotFound();
59 $id = $parameters['id'];
60 if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
61 DI::mstdnError()->RecordNotFound();
64 // Return results older than this id
65 $max_id = (int)!isset($_REQUEST['max_id']) ? 0 : $_REQUEST['max_id'];
66 // Return results newer than this id
67 $since_id = (int)!isset($_REQUEST['since_id']) ? 0 : $_REQUEST['since_id'];
68 // Maximum number of results to return. Defaults to 20.
69 $limit = (int)!isset($_REQUEST['limit']) ? 40 : $_REQUEST['limit'];
72 $params = ['order' => ['contact-id' => true], 'limit' => $limit];
74 $condition = ['gid' => $id];
76 if (!empty($max_id)) {
77 $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]);
80 if (!empty($since_id)) {
81 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]);
84 if (!empty($min_id)) {
85 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
87 $params['order'] = ['contact-id'];
90 $members = DBA::select('group_member', ['contact-id'], $condition, $params);
91 while ($member = DBA::fetch($members)) {
92 $accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
96 if (!empty($min_id)) {
97 array_reverse($accounts);
100 System::jsonExit($accounts);