2021-05-09 09:35:51 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2021-05-09 09:35:51 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Mastodon\Lists;
|
|
|
|
|
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
2022-10-19 13:00:43 +00:00
|
|
|
use Friendica\Model\Group;
|
2021-05-09 09:35:51 +00:00
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
|
|
|
|
/**
|
2021-05-19 06:18:42 +00:00
|
|
|
* @see https://docs.joinmastodon.org/methods/timelines/lists/#accounts-in-a-list
|
2021-05-09 09:35:51 +00:00
|
|
|
*
|
|
|
|
* Currently the output will be unordered since we use public contact ids in the api and not user contact ids.
|
|
|
|
*/
|
|
|
|
class Accounts extends BaseApi
|
|
|
|
{
|
2021-11-28 12:44:42 +00:00
|
|
|
protected function delete(array $request = [])
|
2021-05-09 09:35:51 +00:00
|
|
|
{
|
2022-02-19 22:16:21 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_WRITE);
|
|
|
|
|
|
|
|
$request = $this->getRequest([
|
|
|
|
'account_ids' => [], // Array of account IDs to remove from the list
|
|
|
|
], $request);
|
|
|
|
|
|
|
|
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
|
|
|
DI::mstdnError()->UnprocessableEntity();
|
|
|
|
}
|
2022-02-20 13:10:57 +00:00
|
|
|
|
2022-02-19 22:16:21 +00:00
|
|
|
return Group::removeMembers($this->parameters['id'], $request['account_ids']);
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 12:44:42 +00:00
|
|
|
protected function post(array $request = [])
|
2021-05-09 09:35:51 +00:00
|
|
|
{
|
2022-02-19 22:16:21 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_WRITE);
|
|
|
|
|
|
|
|
$request = $this->getRequest([
|
|
|
|
'account_ids' => [], // Array of account IDs to add to the list
|
|
|
|
], $request);
|
|
|
|
|
|
|
|
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
|
|
|
DI::mstdnError()->UnprocessableEntity();
|
|
|
|
}
|
2022-02-20 13:10:57 +00:00
|
|
|
|
2022-10-19 13:00:43 +00:00
|
|
|
Group::addMembers($this->parameters['id'], $request['account_ids']);
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
|
|
*/
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2021-05-09 09:35:51 +00:00
|
|
|
{
|
2021-06-08 12:00:22 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_READ);
|
2021-05-09 09:35:51 +00:00
|
|
|
$uid = self::getCurrentUserID();
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
if (empty($this->parameters['id'])) {
|
2021-05-12 14:00:15 +00:00
|
|
|
DI::mstdnError()->UnprocessableEntity();
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
$id = $this->parameters['id'];
|
2021-05-09 09:35:51 +00:00
|
|
|
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
|
|
|
|
DI::mstdnError()->RecordNotFound();
|
|
|
|
}
|
|
|
|
|
2021-11-28 12:22:27 +00:00
|
|
|
$request = $this->getRequest([
|
2021-05-18 19:26:46 +00:00
|
|
|
'max_id' => 0, // Return results older than this id
|
|
|
|
'since_id' => 0, // Return results newer than this id
|
2023-01-01 14:36:24 +00:00
|
|
|
'min_id' => 0, // Return results immediately newer than id
|
2021-05-18 19:26:46 +00:00
|
|
|
'limit' => 40, // Maximum number of results. Defaults to 40. Max 40. Set to 0 in order to get all accounts without pagination.
|
2021-11-27 23:30:41 +00:00
|
|
|
], $request);
|
2021-05-09 09:35:51 +00:00
|
|
|
|
2021-05-11 23:39:08 +00:00
|
|
|
$params = ['order' => ['contact-id' => true]];
|
2021-05-09 09:35:51 +00:00
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if ($request['limit'] != 0) {
|
|
|
|
$params['limit'] = min($request['limit'], 40);
|
2021-05-11 23:39:08 +00:00
|
|
|
}
|
2021-07-30 06:19:02 +00:00
|
|
|
|
2021-05-09 09:35:51 +00:00
|
|
|
$condition = ['gid' => $id];
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['max_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $request['max_id']]);
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['since_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['since_id']]);
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 14:47:18 +00:00
|
|
|
if (!empty($request['min_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $request['min_id']]);
|
2021-05-09 09:35:51 +00:00
|
|
|
|
|
|
|
$params['order'] = ['contact-id'];
|
|
|
|
}
|
|
|
|
|
2021-05-11 23:39:08 +00:00
|
|
|
$accounts = [];
|
|
|
|
|
2021-05-09 09:35:51 +00:00
|
|
|
$members = DBA::select('group_member', ['contact-id'], $condition, $params);
|
|
|
|
while ($member = DBA::fetch($members)) {
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setBoundaries($member['contact-id']);
|
2022-11-06 06:42:33 +00:00
|
|
|
try {
|
|
|
|
$accounts[] = DI::mstdnAccount()->createFromContactId($member['contact-id'], $uid);
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
}
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
DBA::close($members);
|
|
|
|
|
2021-11-21 14:47:18 +00:00
|
|
|
if (!empty($request['min_id'])) {
|
2021-12-05 06:22:04 +00:00
|
|
|
$accounts = array_reverse($accounts);
|
2021-05-09 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setLinkHeader();
|
2021-05-09 09:35:51 +00:00
|
|
|
System::jsonExit($accounts);
|
|
|
|
}
|
|
|
|
}
|