Rename Api\Mastodon\Account::createFromContact to just create

- Retrieve public contact in Api\Mastodon\FollowRequests instead of user contact
This commit is contained in:
Hypolite Petovan 2019-12-25 05:41:35 -05:00
parent 9ed8479b32
commit cb7875b035
4 changed files with 15 additions and 10 deletions

View file

@ -61,7 +61,7 @@ class Account
* @return Account * @return Account
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @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 = new Account();
$account->id = $publicContact['id']; $account->id = $publicContact['id'];

View file

@ -3,8 +3,6 @@
namespace Friendica\Api\Mastodon; namespace Friendica\Api\Mastodon;
use Friendica\App; use Friendica\App;
use Friendica\Api\Mastodon\Account;
use Friendica\Api\Mastodon\Stats;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
@ -58,15 +56,17 @@ class Instance
{ {
$register_policy = intval(Config::get('config', 'register_policy')); $register_policy = intval(Config::get('config', 'register_policy'));
$baseUrl = DI::baseUrl();
$instance = new Instance(); $instance = new Instance();
$instance->uri = DI::baseUrl()->get(); $instance->uri = $baseUrl->get();
$instance->title = Config::get('config', 'sitename'); $instance->title = Config::get('config', 'sitename');
$instance->description = Config::get('config', 'info'); $instance->description = Config::get('config', 'info');
$instance->email = Config::get('config', 'admin_email'); $instance->email = Config::get('config', 'admin_email');
$instance->version = FRIENDICA_VERSION; $instance->version = FRIENDICA_VERSION;
$instance->urls = []; // Not supported $instance->urls = []; // Not supported
$instance->stats = Stats::get(); $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->languages = [Config::get('system', 'language')];
$instance->max_toot_chars = (int)Config::get('config', 'api_import_size', Config::get('config', 'max_import_size')); $instance->max_toot_chars = (int)Config::get('config', 'api_import_size', Config::get('config', 'max_import_size'));
$instance->registrations = ($register_policy != Register::CLOSED); $instance->registrations = ($register_policy != Register::CLOSED);
@ -79,7 +79,7 @@ class Instance
if (!empty($administrator)) { if (!empty($administrator)) {
$adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]); $adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]);
$apcontact = APContact::getByURL($adminContact['url'], false); $apcontact = APContact::getByURL($adminContact['url'], false);
$instance->contact_account = Account::createFromContact($adminContact, $apcontact); $instance->contact_account = Account::create($adminContact, $apcontact);
} }
} }

View file

@ -87,9 +87,14 @@ class FollowRequests extends Api
$return = []; $return = [];
foreach ($intros as $intro) { foreach ($intros as $intro) {
$contact = Contact::getById($intro['contact-id']); $cdata = Contact::getPublicAndUserContacID($intro['contact-id'], $intro['uid']);
$apcontact = APContact::getByURL($contact['url'], false); if (empty($cdata['public'])) {
$account = Mastodon\Account::createFromContact($contact, $apcontact); 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 // Not ideal, the same "account" can have multiple ids depending on the context
$account->id = $intro['id']; $account->id = $intro['id'];

View file

@ -13,7 +13,7 @@ class Instance extends Api
{ {
/** /**
* @param array $parameters * @param array $parameters
* @throws HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {