From 1ac9107e5f81fb00665b97565431a9daf31ce180 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 28 Jan 2020 07:33:37 -0500 Subject: [PATCH] Move Mastodon API factories to Factory\Api\Mastodon --- src/DI.php | 18 ++++---- src/Factory/{ => Api}/Mastodon/Account.php | 4 +- src/Factory/Api/Mastodon/Emoji.php | 46 +++++++++++++++++++ .../{ => Api}/Mastodon/FollowRequest.php | 4 +- .../{ => Api}/Mastodon/Relationship.php | 2 +- 5 files changed, 60 insertions(+), 14 deletions(-) rename src/Factory/{ => Api}/Mastodon/Account.php (96%) create mode 100644 src/Factory/Api/Mastodon/Emoji.php rename src/Factory/{ => Api}/Mastodon/FollowRequest.php (96%) rename src/Factory/{ => Api}/Mastodon/Relationship.php (95%) diff --git a/src/DI.php b/src/DI.php index 6eb1ed4b63..2c4163722e 100644 --- a/src/DI.php +++ b/src/DI.php @@ -141,7 +141,7 @@ abstract class DI } /** - * @return \Friendica\Core\PConfig\IPConfig + * @return Core\PConfig\IPConfig */ public static function pConfig() { @@ -221,31 +221,31 @@ abstract class DI // /** - * @return Factory\Mastodon\Account + * @return Factory\Api\Mastodon\Account */ public static function mstdnAccount() { - return self::$dice->create(Factory\Mastodon\Account::class); + return self::$dice->create(Factory\Api\Mastodon\Account::class); } /** - * @return Factory\Mastodon\FollowRequest + * @return Factory\Api\Mastodon\FollowRequest */ public static function mstdnFollowRequest() { - return self::$dice->create(Factory\Mastodon\FollowRequest::class); + return self::$dice->create(Factory\Api\Mastodon\FollowRequest::class); } /** - * @return Factory\Mastodon\Relationship + * @return Factory\Api\Mastodon\Relationship */ public static function mstdnRelationship() { - return self::$dice->create(Factory\Mastodon\Relationship::class); + return self::$dice->create(Factory\Api\Mastodon\Relationship::class); } /** - * @return \Friendica\Factory\Notification\Notification + * @return Factory\Notification\Notification */ public static function notification() { @@ -253,7 +253,7 @@ abstract class DI } /** - * @return \Friendica\Factory\Notification\Introduction + * @return Factory\Notification\Introduction */ public static function notificationIntro() { diff --git a/src/Factory/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php similarity index 96% rename from src/Factory/Mastodon/Account.php rename to src/Factory/Api/Mastodon/Account.php index e777e76fe9..60f9a76e11 100644 --- a/src/Factory/Mastodon/Account.php +++ b/src/Factory/Api/Mastodon/Account.php @@ -1,12 +1,12 @@ baseUrl = $baseURL; + } + + /** + * @param int $contactId + * @param int $uid User Id + * @return \Friendica\Api\Entity\Mastodon\Account + * @throws HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public function createFromContactId(int $contactId, $uid = 0) + { + $cdata = Contact::getPublicAndUserContacID($contactId, $uid); + if (!empty($cdata)) { + $publicContact = Contact::getById($cdata['public']); + $userContact = Contact::getById($cdata['user']); + } else { + $publicContact = Contact::getById($contactId); + $userContact = []; + } + + $apcontact = APContact::getByURL($publicContact['url'], false); + + return new \Friendica\Api\Entity\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact); + } +} diff --git a/src/Factory/Mastodon/FollowRequest.php b/src/Factory/Api/Mastodon/FollowRequest.php similarity index 96% rename from src/Factory/Mastodon/FollowRequest.php rename to src/Factory/Api/Mastodon/FollowRequest.php index 3aabe413d6..e0125613a9 100644 --- a/src/Factory/Mastodon/FollowRequest.php +++ b/src/Factory/Api/Mastodon/FollowRequest.php @@ -1,13 +1,13 @@