2020-01-05 17:29:54 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Factory\Mastodon;
|
|
|
|
|
|
|
|
use Friendica\App\BaseURL;
|
|
|
|
use Friendica\Model\APContact;
|
|
|
|
use Friendica\Model\Contact;
|
|
|
|
use Friendica\Model\Introduction;
|
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
use Friendica\BaseFactory;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class FollowRequest extends BaseFactory
|
|
|
|
{
|
|
|
|
/** @var BaseURL */
|
|
|
|
protected $baseUrl;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
|
|
|
{
|
|
|
|
parent::__construct($logger);
|
|
|
|
|
|
|
|
$this->baseUrl = $baseURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-05 17:50:33 -05:00
|
|
|
* @param Introduction $introduction
|
2020-01-05 17:29:54 -05:00
|
|
|
* @return \Friendica\Api\Entity\Mastodon\FollowRequest
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
|
|
|
* @throws \ImagickException
|
|
|
|
*/
|
2020-01-05 17:50:33 -05:00
|
|
|
public function createFromIntroduction(Introduction $introduction)
|
2020-01-05 17:29:54 -05:00
|
|
|
{
|
2020-01-05 17:50:33 -05:00
|
|
|
$cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
|
2020-01-05 17:29:54 -05:00
|
|
|
|
|
|
|
if (empty($cdata)) {
|
2020-01-05 17:50:33 -05:00
|
|
|
$this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
|
2020-01-05 17:29:54 -05:00
|
|
|
throw new HTTPException\InternalServerErrorException('Wrong introduction data');
|
|
|
|
}
|
|
|
|
|
|
|
|
$publicContact = Contact::getById($cdata['public']);
|
|
|
|
$userContact = Contact::getById($cdata['user']);
|
|
|
|
|
|
|
|
$apcontact = APContact::getByURL($publicContact['url'], false);
|
|
|
|
|
2020-01-05 17:50:33 -05:00
|
|
|
return new \Friendica\Api\Entity\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
|
2020-01-05 17:29:54 -05:00
|
|
|
}
|
|
|
|
}
|