2019-12-05 13:16:13 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2021-03-29 06:40:20 +00:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 14:45:36 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-12-05 13:16:13 +00:00
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Mastodon;
|
|
|
|
|
|
|
|
use Friendica\Core\System;
|
2019-12-15 22:28:01 +00:00
|
|
|
use Friendica\DI;
|
2020-01-28 02:18:42 +00:00
|
|
|
use Friendica\Module\BaseApi;
|
2019-12-05 13:16:13 +00:00
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
|
|
|
|
/**
|
2020-01-05 22:50:33 +00:00
|
|
|
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests
|
2019-12-05 13:16:13 +00:00
|
|
|
*/
|
2020-01-28 02:18:42 +00:00
|
|
|
class FollowRequests extends BaseApi
|
2019-12-05 13:16:13 +00:00
|
|
|
{
|
2019-12-25 10:58:54 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @throws HTTPException\BadRequestException
|
|
|
|
* @throws HTTPException\ForbiddenException
|
2020-01-05 22:50:33 +00:00
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2019-12-25 10:58:54 +00:00
|
|
|
* @throws HTTPException\NotFoundException
|
|
|
|
* @throws HTTPException\UnauthorizedException
|
2020-01-05 22:50:33 +00:00
|
|
|
* @throws \ImagickException
|
|
|
|
*
|
2019-12-25 10:58:54 +00:00
|
|
|
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
|
|
|
|
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
|
|
|
|
*/
|
2019-12-11 08:50:09 +00:00
|
|
|
public static function post(array $parameters = [])
|
|
|
|
{
|
2021-06-08 12:00:22 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_FOLLOW);
|
2021-05-15 15:02:15 +00:00
|
|
|
$uid = self::getCurrentUserID();
|
2019-12-11 08:50:09 +00:00
|
|
|
|
2021-05-15 15:02:15 +00:00
|
|
|
$introduction = DI::intro()->selectFirst(['id' => $parameters['id'], 'uid' => $uid]);
|
2019-12-11 08:50:09 +00:00
|
|
|
|
2020-01-05 22:50:33 +00:00
|
|
|
$contactId = $introduction->{'contact-id'};
|
2019-12-11 08:50:09 +00:00
|
|
|
|
|
|
|
switch ($parameters['action']) {
|
|
|
|
case 'authorize':
|
2020-01-05 22:50:33 +00:00
|
|
|
$introduction->confirm();
|
|
|
|
|
2021-05-15 15:02:15 +00:00
|
|
|
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
2019-12-11 08:50:09 +00:00
|
|
|
break;
|
|
|
|
case 'ignore':
|
2020-01-05 22:50:33 +00:00
|
|
|
$introduction->ignore();
|
|
|
|
|
2021-05-15 15:02:15 +00:00
|
|
|
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
2019-12-11 08:50:09 +00:00
|
|
|
break;
|
|
|
|
case 'reject':
|
2020-01-05 22:50:33 +00:00
|
|
|
$introduction->discard();
|
|
|
|
|
2021-05-15 15:02:15 +00:00
|
|
|
$relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
|
2019-12-11 08:50:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"');
|
|
|
|
}
|
|
|
|
|
|
|
|
System::jsonExit($relationship);
|
|
|
|
}
|
|
|
|
|
2019-12-05 13:16:13 +00:00
|
|
|
/**
|
|
|
|
* @param array $parameters
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
2019-12-25 10:58:54 +00:00
|
|
|
* @throws \ImagickException
|
2021-05-18 19:26:46 +00:00
|
|
|
* @see https://docs.joinmastodon.org/methods/accounts/follow_requests/
|
2019-12-05 13:16:13 +00:00
|
|
|
*/
|
|
|
|
public static function rawContent(array $parameters = [])
|
|
|
|
{
|
2021-06-08 12:00:22 +00:00
|
|
|
self::checkAllowedScope(self::SCOPE_READ);
|
2021-05-15 15:02:15 +00:00
|
|
|
$uid = self::getCurrentUserID();
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
$request = self::getRequest([
|
|
|
|
'min_id' => 0,
|
|
|
|
'max_id' => 0,
|
|
|
|
'limit' => 40, // Maximum number of results to return. Defaults to 40. Paginate using the HTTP Link header.
|
|
|
|
]);
|
2019-12-05 13:16:13 +00:00
|
|
|
|
2020-01-05 22:50:33 +00:00
|
|
|
$introductions = DI::intro()->selectByBoundaries(
|
2021-05-15 15:02:15 +00:00
|
|
|
['`uid` = ? AND NOT `ignore`', $uid],
|
2020-01-05 22:50:33 +00:00
|
|
|
['order' => ['id' => 'DESC']],
|
2021-05-18 19:26:46 +00:00
|
|
|
$request['min_id'],
|
|
|
|
$request['max_id'],
|
|
|
|
$request['limit']
|
2019-12-05 13:16:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$return = [];
|
2019-12-25 10:41:35 +00:00
|
|
|
|
2020-01-05 22:50:33 +00:00
|
|
|
foreach ($introductions as $key => $introduction) {
|
|
|
|
try {
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setBoundaries($introduction->id);
|
2020-01-05 22:50:33 +00:00
|
|
|
$return[] = DI::mstdnFollowRequest()->createFromIntroduction($introduction);
|
|
|
|
} catch (HTTPException\InternalServerErrorException $exception) {
|
|
|
|
DI::intro()->delete($introduction);
|
|
|
|
unset($introductions[$key]);
|
|
|
|
}
|
2019-12-05 13:16:13 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setLinkHeader();
|
2019-12-05 13:16:13 +00:00
|
|
|
System::jsonExit($return);
|
|
|
|
}
|
|
|
|
}
|