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;
24 use Friendica\Core\System;
26 use Friendica\Model\Contact;
27 use Friendica\Module\BaseApi;
28 use Friendica\Network\HTTPException;
31 * @see https://docs.joinmastodon.org/methods/accounts/follow_requests
33 class FollowRequests extends BaseApi
36 * @param array $parameters
37 * @throws HTTPException\BadRequestException
38 * @throws HTTPException\InternalServerErrorException
39 * @throws HTTPException\NotFoundException
40 * @throws HTTPException\UnauthorizedException
41 * @throws \ImagickException
43 * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
44 * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
46 public static function post(array $parameters = [])
48 self::checkAllowedScope(self::SCOPE_FOLLOW);
49 $uid = self::getCurrentUserID();
51 $introduction = DI::intro()->selectOneById($parameters['id'], $uid);
53 $contactId = $introduction->cid;
55 switch ($parameters['action']) {
57 Contact\Introduction::confirm($introduction);
58 $relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
60 DI::intro()->delete($introduction);
63 $introduction->ignore();
64 $relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
66 DI::intro()->save($introduction);
69 Contact\Introduction::discard($introduction);
70 $relationship = DI::mstdnRelationship()->createFromContactId($contactId, $uid);
72 DI::intro()->delete($introduction);
75 throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"');
78 System::jsonExit($relationship);
82 * @param array $parameters
83 * @throws HTTPException\InternalServerErrorException
84 * @throws \ImagickException
85 * @see https://docs.joinmastodon.org/methods/accounts/follow_requests/
87 public static function rawContent(array $parameters = [])
89 self::checkAllowedScope(self::SCOPE_READ);
90 $uid = self::getCurrentUserID();
92 $request = self::getRequest([
95 'limit' => 40, // Maximum number of results to return. Defaults to 40. Paginate using the HTTP Link header.
98 $introductions = DI::intro()->selectForUser($uid, $request['min_id'], $request['max_id'], $request['limit']);
102 foreach ($introductions as $key => $introduction) {
104 self::setBoundaries($introduction->id);
105 $return[] = DI::mstdnFollowRequest()->createFromIntroduction($introduction);
106 } catch (HTTPException\InternalServerErrorException $exception) {
107 DI::intro()->delete($introduction);
108 unset($introductions[$key]);
112 self::setLinkHeader();
113 System::jsonExit($return);