2020-01-05 17:29:54 -05:00
|
|
|
<?php
|
|
|
|
|
2020-01-28 07:33:37 -05:00
|
|
|
namespace Friendica\Factory\Api\Mastodon;
|
2020-01-05 17:29:54 -05:00
|
|
|
|
|
|
|
use Friendica\App\BaseURL;
|
2020-01-28 07:33:37 -05:00
|
|
|
use Friendica\BaseFactory;
|
2020-01-23 09:06:50 -05:00
|
|
|
use Friendica\Collection\Api\Mastodon\Fields;
|
2020-01-05 17:29:54 -05:00
|
|
|
use Friendica\Model\APContact;
|
|
|
|
use Friendica\Model\Contact;
|
|
|
|
use Friendica\Network\HTTPException;
|
2020-01-23 09:06:50 -05:00
|
|
|
use Friendica\Repository\PermissionSet;
|
|
|
|
use Friendica\Repository\ProfileField;
|
2020-01-05 17:29:54 -05:00
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class Account extends BaseFactory
|
|
|
|
{
|
|
|
|
/** @var BaseURL */
|
|
|
|
protected $baseUrl;
|
2020-01-23 09:06:50 -05:00
|
|
|
/** @var ProfileField */
|
|
|
|
protected $profileField;
|
|
|
|
/** @var Field */
|
|
|
|
protected $mstdnField;
|
2020-01-05 17:29:54 -05:00
|
|
|
|
2020-01-23 09:06:50 -05:00
|
|
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
2020-01-05 17:29:54 -05:00
|
|
|
{
|
|
|
|
parent::__construct($logger);
|
|
|
|
|
|
|
|
$this->baseUrl = $baseURL;
|
2020-01-23 09:06:50 -05:00
|
|
|
$this->profileField = $profileField;
|
|
|
|
$this->mstdnField = $mstdnField;
|
2020-01-05 17:29:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $contactId
|
2020-01-23 09:06:50 -05:00
|
|
|
* @param int $uid Public contact (=0) or owner user id
|
2020-01-27 20:01:32 -05:00
|
|
|
* @return \Friendica\Object\Api\Mastodon\Account
|
2020-01-05 17:29:54 -05:00
|
|
|
* @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);
|
|
|
|
|
2020-01-23 09:06:50 -05:00
|
|
|
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $userId
|
|
|
|
* @return \Friendica\Object\Api\Mastodon\Account
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
|
|
|
* @throws \ImagickException
|
|
|
|
*/
|
|
|
|
public function createFromUserId(int $userId)
|
|
|
|
{
|
|
|
|
$publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
|
|
|
|
|
|
|
|
$profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
|
|
|
|
$fields = $this->mstdnField->createFromProfileFields($profileFields);
|
|
|
|
|
|
|
|
$apcontact = APContact::getByURL($publicContact['url'], false);
|
|
|
|
|
|
|
|
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact);
|
2020-01-05 17:29:54 -05:00
|
|
|
}
|
|
|
|
}
|