From f40cd60e3936c9220dbc6d5c1ef4cc5e294b99b1 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 17 Feb 2023 11:09:16 -0500 Subject: [PATCH] Remove FollowRequest type and use mstdnAccount->createFromContactId instead --- src/DI.php | 8 --- src/Factory/Api/Mastodon/FollowRequest.php | 61 ---------------------- src/Module/Api/Mastodon/FollowRequests.php | 6 ++- 3 files changed, 4 insertions(+), 71 deletions(-) delete mode 100644 src/Factory/Api/Mastodon/FollowRequest.php diff --git a/src/DI.php b/src/DI.php index 24f06d2793..78eb5bee4c 100644 --- a/src/DI.php +++ b/src/DI.php @@ -382,14 +382,6 @@ abstract class DI return self::$dice->create(Factory\Api\Mastodon\Error::class); } - /** - * @return Factory\Api\Mastodon\FollowRequest - */ - public static function mstdnFollowRequest() - { - return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class); - } - /** * @return Factory\Api\Mastodon\Poll */ diff --git a/src/Factory/Api/Mastodon/FollowRequest.php b/src/Factory/Api/Mastodon/FollowRequest.php deleted file mode 100644 index 5674196a93..0000000000 --- a/src/Factory/Api/Mastodon/FollowRequest.php +++ /dev/null @@ -1,61 +0,0 @@ -. - * - */ - -namespace Friendica\Factory\Api\Mastodon; - -use Friendica\App\BaseURL; -use Friendica\BaseFactory; -use Friendica\Collection\Api\Mastodon\Fields; -use Friendica\Contact\Introduction\Entity\Introduction; -use Friendica\Database\DBA; -use Friendica\Network\HTTPException; -use ImagickException; -use Psr\Log\LoggerInterface; - -class FollowRequest extends BaseFactory -{ - /** @var BaseURL */ - private $baseUrl; - - public function __construct(LoggerInterface $logger, BaseURL $baseURL) - { - parent::__construct($logger); - - $this->baseUrl = $baseURL; - } - - /** - * @param Introduction $introduction - * @return \Friendica\Object\Api\Mastodon\Account - * @throws ImagickException|HTTPException\InternalServerErrorException - */ - public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\Account - { - $account = DBA::selectFirst('account-user-view', [], ['id' => $introduction->cid, - 'uid' => [0, $introduction->uid]]); - if (empty($account)) { - $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]); - throw new HTTPException\InternalServerErrorException('Wrong introduction data'); - } - - return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $account, new Fields()); - } -} diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index 723a98bcdd..dfe3aadf33 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -105,8 +105,10 @@ class FollowRequests extends BaseApi foreach ($introductions as $key => $introduction) { try { self::setBoundaries($introduction->id); - $return[] = DI::mstdnFollowRequest()->createFromIntroduction($introduction); - } catch (HTTPException\InternalServerErrorException $exception) { + $return[] = DI::mstdnAccount()->createFromContactId($introduction->cid, $introduction->uid); + } catch (HTTPException\InternalServerErrorException + | HTTPException\NotFoundException + | \ImagickException $exception) { DI::intro()->delete($introduction); unset($introductions[$key]); }