3 namespace Friendica\Factory\Api\Mastodon;
5 use Friendica\App\BaseURL;
6 use Friendica\BaseFactory;
7 use Friendica\Collection\Api\Mastodon\Fields;
8 use Friendica\Model\APContact;
9 use Friendica\Model\Contact;
10 use Friendica\Network\HTTPException;
11 use Friendica\Repository\PermissionSet;
12 use Friendica\Repository\ProfileField;
13 use Psr\Log\LoggerInterface;
15 class Account extends BaseFactory
19 /** @var ProfileField */
20 protected $profileField;
22 protected $mstdnField;
24 public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
26 parent::__construct($logger);
28 $this->baseUrl = $baseURL;
29 $this->profileField = $profileField;
30 $this->mstdnField = $mstdnField;
34 * @param int $contactId
35 * @param int $uid Public contact (=0) or owner user id
36 * @return \Friendica\Object\Api\Mastodon\Account
37 * @throws HTTPException\InternalServerErrorException
38 * @throws \ImagickException
40 public function createFromContactId(int $contactId, $uid = 0)
42 $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
44 $publicContact = Contact::getById($cdata['public']);
45 $userContact = Contact::getById($cdata['user']);
47 $publicContact = Contact::getById($contactId);
51 $apcontact = APContact::getByURL($publicContact['url'], false);
53 return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, new Fields(), $apcontact, $userContact);
58 * @return \Friendica\Object\Api\Mastodon\Account
59 * @throws HTTPException\InternalServerErrorException
60 * @throws \ImagickException
62 public function createFromUserId(int $userId)
64 $publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
66 $profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
67 $fields = $this->mstdnField->createFromProfileFields($profileFields);
69 $apcontact = APContact::getByURL($publicContact['url'], false);
71 return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact);