mirror of
https://github.com/friendica/friendica
synced 2025-04-27 15:50:12 +00:00
Introduce Mastodon entity factories and API\Entity
This commit is contained in:
parent
c748a82e8f
commit
5a1abb8c7d
16 changed files with 411 additions and 224 deletions
46
src/Factory/Mastodon/Account.php
Normal file
46
src/Factory/Mastodon/Account.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\BaseFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Account extends BaseFactory
|
||||
{
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
|
||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->baseUrl = $baseURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contactId
|
||||
* @param int $uid User Id
|
||||
* @return \Friendica\Api\Entity\Mastodon\Account
|
||||
* @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);
|
||||
|
||||
return new \Friendica\Api\Entity\Mastodon\Account($this->baseUrl, $publicContact, $apcontact, $userContact);
|
||||
}
|
||||
}
|
47
src/Factory/Mastodon/FollowRequest.php
Normal file
47
src/Factory/Mastodon/FollowRequest.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Introduction $Introduction
|
||||
* @return \Friendica\Api\Entity\Mastodon\FollowRequest
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromIntroduction(Introduction $Introduction)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContacID($Introduction->{'contact-id'}, $Introduction->uid);
|
||||
|
||||
if (empty($cdata)) {
|
||||
$this->logger->warning('Wrong introduction data', ['Introduction' => $Introduction]);
|
||||
throw new HTTPException\InternalServerErrorException('Wrong introduction data');
|
||||
}
|
||||
|
||||
$publicContact = Contact::getById($cdata['public']);
|
||||
$userContact = Contact::getById($cdata['user']);
|
||||
|
||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
||||
|
||||
return new \Friendica\Api\Entity\Mastodon\FollowRequest($this->baseUrl, $Introduction->id, $publicContact, $apcontact, $userContact);
|
||||
}
|
||||
}
|
38
src/Factory/Mastodon/Relationship.php
Normal file
38
src/Factory/Mastodon/Relationship.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Mastodon;
|
||||
|
||||
use Friendica\Api\Entity\Mastodon\Relationship as RelationshipEntity;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
class Relationship extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* @param int $userContactId Contact row id with uid != 0
|
||||
* @return RelationshipEntity
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromContactId(int $userContactId)
|
||||
{
|
||||
return $this->createFromContact(Contact::getById($userContactId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userContact Full contact row record with uid != 0
|
||||
* @return RelationshipEntity
|
||||
*/
|
||||
public function createFromContact(array $userContact)
|
||||
{
|
||||
return new RelationshipEntity($userContact['id'], $userContact);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userContactId Contact row id with uid != 0
|
||||
* @return RelationshipEntity
|
||||
*/
|
||||
public function createDefaultFromContactId(int $userContactId)
|
||||
{
|
||||
return new RelationshipEntity($userContactId);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue