]> git.mxchange.org Git - friendica.git/blob - src/Factory/Api/Mastodon/Emoji.php
Move Mastodon API factories to Factory\Api\Mastodon
[friendica.git] / src / Factory / Api / Mastodon / Emoji.php
1 <?php
2
3 namespace Friendica\Factory\Api\Mastodon;
4
5 use Friendica\App\BaseURL;
6 use Friendica\BaseFactory;
7 use Friendica\Model\APContact;
8 use Friendica\Model\Contact;
9 use Friendica\Network\HTTPException;
10 use Psr\Log\LoggerInterface;
11
12 class Emoji extends BaseFactory
13 {
14         /** @var BaseURL */
15         protected $baseUrl;
16
17         public function __construct(LoggerInterface $logger, BaseURL $baseURL)
18         {
19                 parent::__construct($logger);
20
21                 $this->baseUrl = $baseURL;
22         }
23
24         /**
25          * @param int $contactId
26          * @param int $uid        User Id
27          * @return \Friendica\Api\Entity\Mastodon\Account
28          * @throws HTTPException\InternalServerErrorException
29          * @throws \ImagickException
30          */
31         public function createFromContactId(int $contactId, $uid = 0)
32         {
33                 $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
34                 if (!empty($cdata)) {
35                         $publicContact = Contact::getById($cdata['public']);
36                         $userContact = Contact::getById($cdata['user']);
37                 } else {
38                         $publicContact = Contact::getById($contactId);
39                         $userContact = [];
40                 }
41
42                 $apcontact = APContact::getByURL($publicContact['url'], false);
43
44                 return new \Friendica\Api\Entity\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
45         }
46 }