3 namespace Friendica\Factory\Api\Mastodon;
5 use Friendica\App\BaseURL;
6 use Friendica\BaseFactory;
7 use Friendica\Model\APContact;
8 use Friendica\Model\Contact;
9 use Friendica\Model\Introduction;
10 use Friendica\Network\HTTPException;
11 use Psr\Log\LoggerInterface;
13 class FollowRequest extends BaseFactory
18 public function __construct(LoggerInterface $logger, BaseURL $baseURL)
20 parent::__construct($logger);
22 $this->baseUrl = $baseURL;
26 * @param Introduction $introduction
27 * @return \Friendica\Object\Api\Mastodon\FollowRequest
28 * @throws HTTPException\InternalServerErrorException
29 * @throws \ImagickException
31 public function createFromIntroduction(Introduction $introduction)
33 $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
36 $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
37 throw new HTTPException\InternalServerErrorException('Wrong introduction data');
40 $publicContact = Contact::getById($cdata['public']);
41 $userContact = Contact::getById($cdata['user']);
43 $apcontact = APContact::getByURL($publicContact['url'], false);
45 return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);