From cb7875b0356621e9ceff2fe7f167946d5cefe080 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 25 Dec 2019 05:41:35 -0500 Subject: [PATCH] Rename Api\Mastodon\Account::createFromContact to just create - Retrieve public contact in Api\Mastodon\FollowRequests instead of user contact --- src/Api/Mastodon/Account.php | 2 +- src/Api/Mastodon/Instance.php | 10 +++++----- src/Module/Api/Mastodon/FollowRequests.php | 11 ++++++++--- src/Module/Api/Mastodon/Instance.php | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Api/Mastodon/Account.php b/src/Api/Mastodon/Account.php index 2a2212482b..ca6efcb573 100644 --- a/src/Api/Mastodon/Account.php +++ b/src/Api/Mastodon/Account.php @@ -61,7 +61,7 @@ class Account * @return Account * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function createFromContact(array $publicContact, array $apcontact = []) + public static function create(array $publicContact, array $apcontact = []) { $account = new Account(); $account->id = $publicContact['id']; diff --git a/src/Api/Mastodon/Instance.php b/src/Api/Mastodon/Instance.php index 73541ee237..6d1dfb7337 100644 --- a/src/Api/Mastodon/Instance.php +++ b/src/Api/Mastodon/Instance.php @@ -3,8 +3,6 @@ namespace Friendica\Api\Mastodon; use Friendica\App; -use Friendica\Api\Mastodon\Account; -use Friendica\Api\Mastodon\Stats; use Friendica\Core\Config; use Friendica\Database\DBA; use Friendica\DI; @@ -58,15 +56,17 @@ class Instance { $register_policy = intval(Config::get('config', 'register_policy')); + $baseUrl = DI::baseUrl(); + $instance = new Instance(); - $instance->uri = DI::baseUrl()->get(); + $instance->uri = $baseUrl->get(); $instance->title = Config::get('config', 'sitename'); $instance->description = Config::get('config', 'info'); $instance->email = Config::get('config', 'admin_email'); $instance->version = FRIENDICA_VERSION; $instance->urls = []; // Not supported $instance->stats = Stats::get(); - $instance->thumbnail = DI::baseUrl()->get() . (Config::get('system', 'shortcut_icon') ?? 'images/friendica-32.png'); + $instance->thumbnail = $baseUrl->get() . (Config::get('system', 'shortcut_icon') ?? 'images/friendica-32.png'); $instance->languages = [Config::get('system', 'language')]; $instance->max_toot_chars = (int)Config::get('config', 'api_import_size', Config::get('config', 'max_import_size')); $instance->registrations = ($register_policy != Register::CLOSED); @@ -79,7 +79,7 @@ class Instance if (!empty($administrator)) { $adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]); $apcontact = APContact::getByURL($adminContact['url'], false); - $instance->contact_account = Account::createFromContact($adminContact, $apcontact); + $instance->contact_account = Account::create($adminContact, $apcontact); } } diff --git a/src/Module/Api/Mastodon/FollowRequests.php b/src/Module/Api/Mastodon/FollowRequests.php index 6cafb44a66..304f78767f 100644 --- a/src/Module/Api/Mastodon/FollowRequests.php +++ b/src/Module/Api/Mastodon/FollowRequests.php @@ -87,9 +87,14 @@ class FollowRequests extends Api $return = []; foreach ($intros as $intro) { - $contact = Contact::getById($intro['contact-id']); - $apcontact = APContact::getByURL($contact['url'], false); - $account = Mastodon\Account::createFromContact($contact, $apcontact); + $cdata = Contact::getPublicAndUserContacID($intro['contact-id'], $intro['uid']); + if (empty($cdata['public'])) { + continue; + } + + $publicContact = Contact::getById($cdata['public']); + $apcontact = APContact::getByURL($publicContact['url'], false); + $account = Mastodon\Account::create($publicContact, $apcontact); // Not ideal, the same "account" can have multiple ids depending on the context $account->id = $intro['id']; diff --git a/src/Module/Api/Mastodon/Instance.php b/src/Module/Api/Mastodon/Instance.php index 559fa68cc4..96d4db3302 100644 --- a/src/Module/Api/Mastodon/Instance.php +++ b/src/Module/Api/Mastodon/Instance.php @@ -13,7 +13,7 @@ class Instance extends Api { /** * @param array $parameters - * @throws HTTPException\InternalServerErrorException + * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function rawContent(array $parameters = []) {