Merge pull request #10373 from nupplaphil/feat/cleanup_factory_behaviour
Cleanup Mastodon Factories
This commit is contained in:
commit
2cc522cdbe
21 changed files with 294 additions and 202 deletions
17
src/Collection/Api/Mastodon/Mentions.php
Normal file
17
src/Collection/Api/Mastodon/Mentions.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Collection\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\BaseCollection;
|
||||||
|
use Friendica\Object\Api\Mastodon\Mention;
|
||||||
|
|
||||||
|
class Mentions extends BaseCollection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return Mention
|
||||||
|
*/
|
||||||
|
public function current(): Mention
|
||||||
|
{
|
||||||
|
return parent::current();
|
||||||
|
}
|
||||||
|
}
|
24
src/DI.php
24
src/DI.php
|
@ -287,14 +287,6 @@ abstract class DI
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Error::class);
|
return self::$dice->create(Factory\Api\Mastodon\Error::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Factory\Api\Mastodon\Field
|
|
||||||
*/
|
|
||||||
public static function mstdnField()
|
|
||||||
{
|
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Field::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Factory\Api\Mastodon\FollowRequest
|
* @return Factory\Api\Mastodon\FollowRequest
|
||||||
*/
|
*/
|
||||||
|
@ -327,14 +319,6 @@ abstract class DI
|
||||||
return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
|
return self::$dice->create(Factory\Api\Mastodon\ListEntity::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Factory\Api\Mastodon\Mention
|
|
||||||
*/
|
|
||||||
public static function mstdnMention()
|
|
||||||
{
|
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Mention::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Factory\Api\Mastodon\Notification
|
* @return Factory\Api\Mastodon\Notification
|
||||||
*/
|
*/
|
||||||
|
@ -343,14 +327,6 @@ abstract class DI
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Notification::class);
|
return self::$dice->create(Factory\Api\Mastodon\Notification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Factory\Api\Mastodon\Tag
|
|
||||||
*/
|
|
||||||
public static function mstdnTag()
|
|
||||||
{
|
|
||||||
return self::$dice->create(Factory\Api\Mastodon\Tag::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Factory\Api\Twitter\User
|
* @return Factory\Api\Twitter\User
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,34 +29,36 @@ use Friendica\Model\Contact;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Repository\PermissionSet;
|
use Friendica\Repository\PermissionSet;
|
||||||
use Friendica\Repository\ProfileField;
|
use Friendica\Repository\ProfileField;
|
||||||
|
use ImagickException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Account extends BaseFactory
|
class Account extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
protected $baseUrl;
|
private $baseUrl;
|
||||||
/** @var ProfileField */
|
/** @var ProfileField */
|
||||||
protected $profileField;
|
private $profileFieldRepo;
|
||||||
/** @var Field */
|
/** @var Field */
|
||||||
protected $mstdnField;
|
private $mstdnFieldFactory;
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileFieldRepo, Field $mstdnFieldFactory)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
|
||||||
$this->baseUrl = $baseURL;
|
$this->baseUrl = $baseURL;
|
||||||
$this->profileField = $profileField;
|
$this->profileFieldRepo = $profileFieldRepo;
|
||||||
$this->mstdnField = $mstdnField;
|
$this->mstdnFieldFactory = $mstdnFieldFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $contactId
|
* @param int $contactId
|
||||||
* @param int $uid Public contact (=0) or owner user id
|
* @param int $uid Public contact (=0) or owner user id
|
||||||
|
*
|
||||||
* @return \Friendica\Object\Api\Mastodon\Account
|
* @return \Friendica\Object\Api\Mastodon\Account
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws ImagickException|HTTPException\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function createFromContactId(int $contactId, $uid = 0)
|
public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account
|
||||||
{
|
{
|
||||||
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
||||||
if (!empty($cdata)) {
|
if (!empty($cdata)) {
|
||||||
|
@ -64,7 +66,7 @@ class Account extends BaseFactory
|
||||||
$userContact = Contact::getById($cdata['user']);
|
$userContact = Contact::getById($cdata['user']);
|
||||||
} else {
|
} else {
|
||||||
$publicContact = Contact::getById($contactId);
|
$publicContact = Contact::getById($contactId);
|
||||||
$userContact = [];
|
$userContact = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($publicContact)) {
|
if (empty($publicContact)) {
|
||||||
|
@ -75,8 +77,8 @@ class Account extends BaseFactory
|
||||||
|
|
||||||
$self_contact = Contact::selectFirst(['uid'], ['nurl' => $publicContact['nurl'], 'self' => true]);
|
$self_contact = Contact::selectFirst(['uid'], ['nurl' => $publicContact['nurl'], 'self' => true]);
|
||||||
if (!empty($self_contact['uid'])) {
|
if (!empty($self_contact['uid'])) {
|
||||||
$profileFields = $this->profileField->select(['uid' => $self_contact['uid'], 'psid' => PermissionSet::PUBLIC]);
|
$profileFields = $this->profileFieldRepo->select(['uid' => $self_contact['uid'], 'psid' => PermissionSet::PUBLIC]);
|
||||||
$fields = $this->mstdnField->createFromProfileFields($profileFields);
|
$fields = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
|
||||||
} else {
|
} else {
|
||||||
$fields = new Fields();
|
$fields = new Fields();
|
||||||
}
|
}
|
||||||
|
@ -87,18 +89,17 @@ class Account extends BaseFactory
|
||||||
/**
|
/**
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @return \Friendica\Object\Api\Mastodon\Account
|
* @return \Friendica\Object\Api\Mastodon\Account
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws ImagickException|HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromUserId(int $userId)
|
public function createFromUserId(int $userId): \Friendica\Object\Api\Mastodon\Account
|
||||||
{
|
{
|
||||||
$publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
|
$publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
|
||||||
|
|
||||||
$profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
|
$profileFields = $this->profileFieldRepo->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
|
||||||
$fields = $this->mstdnField->createFromProfileFields($profileFields);
|
$fields = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
|
||||||
|
|
||||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
$apContact = APContact::getByURL($publicContact['url'], false);
|
||||||
|
|
||||||
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apcontact);
|
return new \Friendica\Object\Api\Mastodon\Account($this->baseUrl, $publicContact, $fields, $apContact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,28 +22,41 @@
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Application extends BaseFactory
|
class Application extends BaseFactory
|
||||||
{
|
{
|
||||||
|
/** @var Database */
|
||||||
|
private $dba;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger, Database $dba)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
$this->dba = $dba;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id Application ID
|
* @param int $id Application ID
|
||||||
|
*
|
||||||
|
* @return \Friendica\Object\Api\Mastodon\Application
|
||||||
|
*
|
||||||
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function createFromApplicationId(int $id)
|
public function createFromApplicationId(int $id): \Friendica\Object\Api\Mastodon\Application
|
||||||
{
|
{
|
||||||
$application = DBA::selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]);
|
$application = $this->dba->selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]);
|
||||||
if (!DBA::isResult($application)) {
|
if (!$this->dba->isResult($application)) {
|
||||||
return [];
|
throw new InternalServerErrorException(sprintf("ID '%s' not found", $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \Friendica\Object\Api\Mastodon\Application(
|
return new \Friendica\Object\Api\Mastodon\Application(
|
||||||
$application['name'],
|
$application['name'],
|
||||||
$application['client_id'],
|
$application['client_id'],
|
||||||
$application['client_secret'],
|
$application['client_secret'],
|
||||||
$application['id'],
|
$application['id'],
|
||||||
$application['redirect_uri'],
|
$application['redirect_uri'],
|
||||||
$application['website']);
|
$application['website']);
|
||||||
|
|
||||||
return $object->toArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,9 @@ namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Repository\ProfileField;
|
|
||||||
use Friendica\Util\Images;
|
use Friendica\Util\Images;
|
||||||
use Friendica\Util\Proxy;
|
use Friendica\Util\Proxy;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -35,32 +33,24 @@ use Psr\Log\LoggerInterface;
|
||||||
class Attachment extends BaseFactory
|
class Attachment extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
protected $baseUrl;
|
private $baseUrl;
|
||||||
/** @var ProfileField */
|
|
||||||
protected $profileField;
|
|
||||||
/** @var Field */
|
|
||||||
protected $mstdnField;
|
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
|
||||||
$this->baseUrl = $baseURL;
|
$this->baseUrl = $baseURL;
|
||||||
$this->profileField = $profileField;
|
|
||||||
$this->mstdnField = $mstdnField;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uriId Uri-ID of the attachments
|
* @param int $uriId Uri-ID of the attachments
|
||||||
* @return array
|
* @return array
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId)
|
public function createFromUriId(int $uriId): array
|
||||||
{
|
{
|
||||||
$attachments = [];
|
$attachments = [];
|
||||||
foreach (Post\Media::getByURIId($uriId, [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]) as $attachment) {
|
foreach (Post\Media::getByURIId($uriId, [Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]) as $attachment) {
|
||||||
|
|
||||||
$filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';
|
$filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';
|
||||||
|
|
||||||
if (($filetype == 'audio') || ($attachment['type'] == Post\Media::AUDIO)) {
|
if (($filetype == 'audio') || ($attachment['type'] == Post\Media::AUDIO)) {
|
||||||
|
@ -78,19 +68,19 @@ class Attachment extends BaseFactory
|
||||||
$remote = $attachment['url'];
|
$remote = $attachment['url'];
|
||||||
if ($type == 'image') {
|
if ($type == 'image') {
|
||||||
if (Proxy::isLocalImage($attachment['url'])) {
|
if (Proxy::isLocalImage($attachment['url'])) {
|
||||||
$url = $attachment['url'];
|
$url = $attachment['url'];
|
||||||
$preview = $attachment['preview'] ?? $url;
|
$preview = $attachment['preview'] ?? $url;
|
||||||
$remote = '';
|
$remote = '';
|
||||||
} else {
|
} else {
|
||||||
$url = Proxy::proxifyUrl($attachment['url']);
|
$url = Proxy::proxifyUrl($attachment['url']);
|
||||||
$preview = Proxy::proxifyUrl($attachment['url'], false, Proxy::SIZE_SMALL);
|
$preview = Proxy::proxifyUrl($attachment['url'], false, Proxy::SIZE_SMALL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$url = Proxy::proxifyUrl($attachment['url']);
|
$url = Proxy::proxifyUrl($attachment['url ']);
|
||||||
$preview = Proxy::proxifyUrl($attachment['preview'] ?? '');
|
$preview = Proxy::proxifyUrl($attachment['preview'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
|
$object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, $type, $url, $preview, $remote);
|
||||||
$attachments[] = $object->toArray();
|
$attachments[] = $object->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,27 +89,27 @@ class Attachment extends BaseFactory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id id of the photo
|
* @param int $id id of the photo
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromPhoto(int $id)
|
public function createFromPhoto(int $id): array
|
||||||
{
|
{
|
||||||
$photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]);
|
$photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]);
|
||||||
if (empty($photo)) {
|
if (empty($photo)) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachment = ['id' => $photo['id'], 'description' => $photo['title']];
|
$attachment = ['id' => $photo['id'], 'description' => $photo['title']];
|
||||||
|
|
||||||
$phototypes = Images::supportedTypes();
|
$photoTypes = Images::supportedTypes();
|
||||||
$ext = $phototypes[$photo['type']];
|
$ext = $photoTypes[$photo['type']];
|
||||||
|
|
||||||
$url = DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-0.' . $ext;
|
$url = $this->baseUrl . '/photo/' . $photo['resource-id'] . '-0.' . $ext;
|
||||||
|
|
||||||
$preview = Photo::selectFirst(['scale'], ["`resource-id` = ? AND `uid` = ? AND `scale` > ?", $photo['resource-id'], $photo['uid'], 0], ['order' => ['scale']]);
|
$preview = Photo::selectFirst(['scale'], ["`resource-id` = ? AND `uid` = ? AND `scale` > ?", $photo['resource-id'], $photo['uid'], 0], ['order' => ['scale']]);
|
||||||
if (empty($scale)) {
|
if (empty($scale)) {
|
||||||
$preview_url = DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $preview['scale'] . '.' . $ext;
|
$preview_url = $this->baseUrl . '/photo/' . $photo['resource-id'] . '-' . $preview['scale'] . '.' . $ext;
|
||||||
} else {
|
} else {
|
||||||
$preview_url = '';
|
$preview_url = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,12 @@ class Card extends BaseFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param int $uriId Uri-ID of the item
|
* @param int $uriId Uri-ID of the item
|
||||||
|
*
|
||||||
* @return \Friendica\Object\Api\Mastodon\Card
|
* @return \Friendica\Object\Api\Mastodon\Card
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException*@throws \Exception
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId)
|
public function createFromUriId(int $uriId): \Friendica\Object\Api\Mastodon\Card
|
||||||
{
|
{
|
||||||
$item = Post::selectFirst(['body'], ['uri-id' => $uriId]);
|
$item = Post::selectFirst(['body'], ['uri-id' => $uriId]);
|
||||||
if (!empty($item['body'])) {
|
if (!empty($item['body'])) {
|
||||||
|
|
|
@ -22,13 +22,33 @@
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\Database;
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
use ImagickException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Conversation extends BaseFactory
|
class Conversation extends BaseFactory
|
||||||
{
|
{
|
||||||
public function CreateFromConvId(int $id)
|
/** @var Database */
|
||||||
|
private $dba;
|
||||||
|
/** @var Status */
|
||||||
|
private $mstdnStatusFactory;
|
||||||
|
/** @var Account */
|
||||||
|
private $mstdnAccountFactory;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger, Database $dba, Status $mstdnStatusFactory, Account $mstdnAccountFactoryFactory)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
$this->dba = $dba;
|
||||||
|
$this->mstdnStatusFactory = $mstdnStatusFactory;
|
||||||
|
$this->mstdnAccountFactory = $mstdnAccountFactoryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ImagickException|HTTPException\InternalServerErrorException|HTTPException\NotFoundException
|
||||||
|
*/
|
||||||
|
public function CreateFromConvId(int $id): \Friendica\Object\Api\Mastodon\Conversation
|
||||||
{
|
{
|
||||||
$accounts = [];
|
$accounts = [];
|
||||||
$unread = false;
|
$unread = false;
|
||||||
|
@ -36,8 +56,8 @@ class Conversation extends BaseFactory
|
||||||
|
|
||||||
$ids = [];
|
$ids = [];
|
||||||
|
|
||||||
$mails = DBA::select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
|
$mails = $this->dba->select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
|
||||||
while ($mail = DBA::fetch($mails)) {
|
while ($mail = $this->dba->fetch($mails)) {
|
||||||
if (!$mail['seen']) {
|
if (!$mail['seen']) {
|
||||||
$unread = true;
|
$unread = true;
|
||||||
}
|
}
|
||||||
|
@ -50,10 +70,10 @@ class Conversation extends BaseFactory
|
||||||
$ids[] = $id;
|
$ids[] = $id;
|
||||||
|
|
||||||
if (empty($last_status)) {
|
if (empty($last_status)) {
|
||||||
$last_status = DI::mstdnStatus()->createFromMailId($mail['id']);
|
$last_status = $this->mstdnStatusFactory->createFromMailId($mail['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$accounts[] = DI::mstdnAccount()->createFromContactId($id, 0);
|
$accounts[] = $this->mstdnAccountFactory->createFromContactId($id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \Friendica\Object\Api\Mastodon\Conversation($id, $accounts, $unread, $last_status);
|
return new \Friendica\Object\Api\Mastodon\Conversation($id, $accounts, $unread, $last_status);
|
||||||
|
|
|
@ -26,7 +26,7 @@ use Friendica\Collection\Api\Mastodon\Emojis;
|
||||||
|
|
||||||
class Emoji extends BaseFactory
|
class Emoji extends BaseFactory
|
||||||
{
|
{
|
||||||
public function create(string $shortcode, string $url)
|
public function create(string $shortcode, string $url): \Friendica\Object\Api\Mastodon\Emoji
|
||||||
{
|
{
|
||||||
return new \Friendica\Object\Api\Mastodon\Emoji($shortcode, $url);
|
return new \Friendica\Object\Api\Mastodon\Emoji($shortcode, $url);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Emoji extends BaseFactory
|
||||||
* @param array $smilies
|
* @param array $smilies
|
||||||
* @return Emojis
|
* @return Emojis
|
||||||
*/
|
*/
|
||||||
public function createCollectionFromSmilies(array $smilies)
|
public function createCollectionFromSmilies(array $smilies): Emojis
|
||||||
{
|
{
|
||||||
$prototype = null;
|
$prototype = null;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Emoji extends BaseFactory
|
||||||
|
|
||||||
if ($prototype === null) {
|
if ($prototype === null) {
|
||||||
$prototype = $this->create($shortcode, $url);
|
$prototype = $this->create($shortcode, $url);
|
||||||
$emojis[] = $prototype;
|
$emojis[] = $prototype;
|
||||||
} else {
|
} else {
|
||||||
$emojis[] = \Friendica\Object\Api\Mastodon\Emoji::createFromPrototype($prototype, $shortcode, $url);
|
$emojis[] = \Friendica\Object\Api\Mastodon\Emoji::createFromPrototype($prototype, $shortcode, $url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,65 +21,82 @@
|
||||||
|
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
|
use Friendica\App\Arguments;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\DI;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
/** @todo A Factory shouldn't return something to the frontpage, it's for creating content, not showing it */
|
||||||
class Error extends BaseFactory
|
class Error extends BaseFactory
|
||||||
{
|
{
|
||||||
|
/** @var Arguments */
|
||||||
|
private $args;
|
||||||
|
/** @var string[] The $_SERVER array */
|
||||||
|
private $server;
|
||||||
|
/** @var L10n */
|
||||||
|
private $l10n;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger, Arguments $args, L10n $l10n, array $server)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
$this->args = $args;
|
||||||
|
$this->server = $server;
|
||||||
|
$this->l10n = $l10n;
|
||||||
|
}
|
||||||
|
|
||||||
private function logError(int $errorno, string $error)
|
private function logError(int $errorno, string $error)
|
||||||
{
|
{
|
||||||
Logger::info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $_SERVER['REQUEST_METHOD'] ?? '', 'command' => DI::args()->getQueryString(), 'user-agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
|
$this->logger->info('API Error', ['no' => $errorno, 'error' => $error, 'method' => $this->server['REQUEST_METHOD'] ?? '', 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function RecordNotFound()
|
public function RecordNotFound()
|
||||||
{
|
{
|
||||||
$error = DI::l10n()->t('Record not found');
|
$error = $this->l10n->t('Record not found');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(404, $error);
|
$this->logError(404, $error);
|
||||||
System::jsonError(404, $errorobj->toArray());
|
System::jsonError(404, $errorObj->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function UnprocessableEntity(string $error = '')
|
public function UnprocessableEntity(string $error = '')
|
||||||
{
|
{
|
||||||
$error = $error ?: DI::l10n()->t('Unprocessable Entity');
|
$error = $error ?: $this->l10n->t('Unprocessable Entity');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(422, $error);
|
$this->logError(422, $error);
|
||||||
System::jsonError(422, $errorobj->toArray());
|
System::jsonError(422, $errorObj->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Unauthorized(string $error = '')
|
public function Unauthorized(string $error = '')
|
||||||
{
|
{
|
||||||
$error = $error ?: DI::l10n()->t('Unauthorized');
|
$error = $error ?: $this->l10n->t('Unauthorized');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(401, $error);
|
$this->logError(401, $error);
|
||||||
System::jsonError(401, $errorobj->toArray());
|
System::jsonError(401, $errorObj->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Forbidden(string $error = '')
|
public function Forbidden(string $error = '')
|
||||||
{
|
{
|
||||||
$error = $error ?: DI::l10n()->t('Token is not authorized with a valid user or is missing a required scope');
|
$error = $error ?: $this->l10n->t('Token is not authorized with a valid user or is missing a required scope');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(403, $error);
|
$this->logError(403, $error);
|
||||||
System::jsonError(403, $errorobj->toArray());
|
System::jsonError(403, $errorObj->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function InternalError(string $error = '')
|
public function InternalError(string $error = '')
|
||||||
{
|
{
|
||||||
$error = $error ?: DI::l10n()->t('Internal Server Error');
|
$error = $error ?: $this->l10n->t('Internal Server Error');
|
||||||
$error_description = '';
|
$error_description = '';
|
||||||
$errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
$errorObj = new \Friendica\Object\Api\Mastodon\Error($error, $error_description);
|
||||||
|
|
||||||
$this->logError(500, $error);
|
$this->logError(500, $error);
|
||||||
System::jsonError(500, $errorobj->toArray());
|
System::jsonError(500, $errorObj->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,10 @@ class Field extends BaseFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param ProfileField $profileField
|
* @param ProfileField $profileField
|
||||||
* @return \Friendica\Api\Entity\Mastodon\Field
|
* @return \Friendica\Object\Api\Mastodon\Field
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function createFromProfileField(ProfileField $profileField)
|
public function createFromProfileField(ProfileField $profileField): \Friendica\Object\Api\Mastodon\Field
|
||||||
{
|
{
|
||||||
return new \Friendica\Object\Api\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, BBCode::ACTIVITYPUB));
|
return new \Friendica\Object\Api\Mastodon\Field($profileField->label, BBCode::convert($profileField->value, false, BBCode::ACTIVITYPUB));
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class Field extends BaseFactory
|
||||||
* @return Fields
|
* @return Fields
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function createFromProfileFields(ProfileFields $profileFields)
|
public function createFromProfileFields(ProfileFields $profileFields): Fields
|
||||||
{
|
{
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,13 @@ use Friendica\Model\APContact;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Introduction;
|
use Friendica\Model\Introduction;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
use ImagickException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class FollowRequest extends BaseFactory
|
class FollowRequest extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
protected $baseUrl;
|
private $baseUrl;
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||||
{
|
{
|
||||||
|
@ -44,10 +45,9 @@ class FollowRequest extends BaseFactory
|
||||||
/**
|
/**
|
||||||
* @param Introduction $introduction
|
* @param Introduction $introduction
|
||||||
* @return \Friendica\Object\Api\Mastodon\FollowRequest
|
* @return \Friendica\Object\Api\Mastodon\FollowRequest
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws ImagickException|HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromIntroduction(Introduction $introduction)
|
public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\FollowRequest
|
||||||
{
|
{
|
||||||
$cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
|
$cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
|
||||||
|
|
||||||
|
@ -57,10 +57,10 @@ class FollowRequest extends BaseFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
$publicContact = Contact::getById($cdata['public']);
|
$publicContact = Contact::getById($cdata['public']);
|
||||||
$userContact = Contact::getById($cdata['user']);
|
$userContact = Contact::getById($cdata['user']);
|
||||||
|
|
||||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
$apContact = APContact::getByURL($publicContact['url'], false);
|
||||||
|
|
||||||
return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apcontact, $userContact);
|
return new \Friendica\Object\Api\Mastodon\FollowRequest($this->baseUrl, $introduction->id, $publicContact, $apContact, $userContact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,27 @@
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class ListEntity extends BaseFactory
|
class ListEntity extends BaseFactory
|
||||||
{
|
{
|
||||||
public function createFromGroupId(int $id)
|
/** @var Database */
|
||||||
|
private $dba;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger, Database $dba)
|
||||||
{
|
{
|
||||||
$group = DBA::selectFirst('group', ['name'], ['id' => $id, 'deleted' => false]);
|
parent::__construct($logger);
|
||||||
|
$this->dba = $dba;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws InternalServerErrorException
|
||||||
|
*/
|
||||||
|
public function createFromGroupId(int $id): \Friendica\Object\Api\Mastodon\ListEntity
|
||||||
|
{
|
||||||
|
$group = $this->dba->selectFirst('group', ['name'], ['id' => $id, 'deleted' => false]);
|
||||||
return new \Friendica\Object\Api\Mastodon\ListEntity($id, $group['name'] ?? '', 'list');
|
return new \Friendica\Object\Api\Mastodon\ListEntity($id, $group['name'] ?? '', 'list');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,44 +23,36 @@ namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
|
use Friendica\Collection\Api\Mastodon\Mentions;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Repository\ProfileField;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Mention extends BaseFactory
|
class Mention extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
protected $baseUrl;
|
private $baseUrl;
|
||||||
/** @var ProfileField */
|
|
||||||
protected $profileField;
|
|
||||||
/** @var Field */
|
|
||||||
protected $mstdnField;
|
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
|
||||||
$this->baseUrl = $baseURL;
|
$this->baseUrl = $baseURL;
|
||||||
$this->profileField = $profileField;
|
|
||||||
$this->mstdnField = $mstdnField;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uriId Uri-ID of the item
|
* @param int $uriId Uri-ID of the item
|
||||||
* @return array
|
* @return Mentions
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId)
|
public function createFromUriId(int $uriId): Mentions
|
||||||
{
|
{
|
||||||
$mentions = [];
|
$mentions = new Mentions();
|
||||||
$tags = Tag::getByURIId($uriId, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]);
|
$tags = Tag::getByURIId($uriId, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]);
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$contact = Contact::getByURL($tag['url'], false);
|
$contact = Contact::getByURL($tag['url'], false);
|
||||||
$mention = new \Friendica\Object\Api\Mastodon\Mention($this->baseUrl, $tag, $contact);
|
$mentions[] = new \Friendica\Object\Api\Mastodon\Mention($this->baseUrl, $tag, $contact);
|
||||||
$mentions[] = $mention->toArray();
|
|
||||||
}
|
}
|
||||||
return $mentions;
|
return $mentions;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,34 @@
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\Database;
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Verb;
|
use Friendica\Model\Verb;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Notification extends BaseFactory
|
class Notification extends BaseFactory
|
||||||
{
|
{
|
||||||
|
/** @var Database */
|
||||||
|
private $dba;
|
||||||
|
/** @var Account */
|
||||||
|
private $mstdnAccountFactory;
|
||||||
|
/** @var Status */
|
||||||
|
private $mstdnStatusFactory;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger, Database $dba, Account $mstdnAccountFactory, Status $mstdnStatusFactoryFactory)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
$this->dba = $dba;
|
||||||
|
$this->mstdnAccountFactory = $mstdnAccountFactory;
|
||||||
|
$this->mstdnStatusFactory = $mstdnStatusFactoryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public function createFromNotificationId(int $id)
|
public function createFromNotificationId(int $id)
|
||||||
{
|
{
|
||||||
$notification = DBA::selectFirst('notification', [], ['id' => $id]);
|
$notification = $this->dba->selectFirst('notification', [], ['id' => $id]);
|
||||||
if (!DBA::isResult($notification)) {
|
if (!$this->dba->isResult($notification)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -49,7 +64,7 @@ class Notification extends BaseFactory
|
||||||
|
|
||||||
if (($notification['vid'] == Verb::getID(Activity::FOLLOW)) && ($notification['type'] == Post\UserNotification::NOTIF_NONE)) {
|
if (($notification['vid'] == Verb::getID(Activity::FOLLOW)) && ($notification['type'] == Post\UserNotification::NOTIF_NONE)) {
|
||||||
$contact = Contact::getById($notification['actor-id'], ['pending']);
|
$contact = Contact::getById($notification['actor-id'], ['pending']);
|
||||||
$type = $contact['pending'] ? $type = 'follow_request' : 'follow';
|
$type = $contact['pending'] ? $type = 'follow_request' : 'follow';
|
||||||
} elseif (($notification['vid'] == Verb::getID(Activity::ANNOUNCE)) &&
|
} elseif (($notification['vid'] == Verb::getID(Activity::ANNOUNCE)) &&
|
||||||
in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
|
in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
|
||||||
$type = 'reblog';
|
$type = 'reblog';
|
||||||
|
@ -66,11 +81,11 @@ class Notification extends BaseFactory
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = DI::mstdnAccount()->createFromContactId($notification['actor-id'], $notification['uid']);
|
$account = $this->mstdnAccountFactory->createFromContactId($notification['actor-id'], $notification['uid']);
|
||||||
|
|
||||||
if (!empty($notification['target-uri-id'])) {
|
if (!empty($notification['target-uri-id'])) {
|
||||||
try {
|
try {
|
||||||
$status = DI::mstdnStatus()->createFromUriId($notification['target-uri-id'], $notification['uid']);
|
$status = $this->mstdnStatusFactory->createFromUriId($notification['target-uri-id'], $notification['uid']);
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
$status = null;
|
$status = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
|
use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
@ -31,9 +32,9 @@ class Relationship extends BaseFactory
|
||||||
* @param int $contactId Contact ID (public or user contact)
|
* @param int $contactId Contact ID (public or user contact)
|
||||||
* @param int $uid User ID
|
* @param int $uid User ID
|
||||||
* @return RelationshipEntity
|
* @return RelationshipEntity
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function createFromContactId(int $contactId, int $uid)
|
public function createFromContactId(int $contactId, int $uid): RelationshipEntity
|
||||||
{
|
{
|
||||||
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
||||||
if (!empty($cdata)) {
|
if (!empty($cdata)) {
|
||||||
|
|
|
@ -21,46 +21,59 @@
|
||||||
|
|
||||||
namespace Friendica\Factory\Api\Mastodon;
|
namespace Friendica\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\App\BaseURL;
|
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Content\ContactSelector;
|
use Friendica\Content\ContactSelector;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\Database;
|
||||||
use Friendica\DI;
|
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Verb;
|
use Friendica\Model\Verb;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Repository\ProfileField;
|
use ImagickException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Status extends BaseFactory
|
class Status extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var Database */
|
||||||
protected $baseUrl;
|
private $dba;
|
||||||
/** @var ProfileField */
|
/** @var Account */
|
||||||
protected $profileField;
|
private $mstdnAccountFactory;
|
||||||
/** @var Field */
|
/** @var Mention */
|
||||||
protected $mstdnField;
|
private $mstdnMentionFactory;
|
||||||
|
/** @var Tag */
|
||||||
|
private $mstdnTagFactory;
|
||||||
|
/** @var Card */
|
||||||
|
private $mstdnCardFactory;
|
||||||
|
/** @var Attachment */
|
||||||
|
private $mstdnAttachementFactory;
|
||||||
|
/** @var Error */
|
||||||
|
private $mstdnErrorFactory;
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
public function __construct(LoggerInterface $logger, Database $dba,
|
||||||
|
Account $mstdnAccountFactory, Mention $mstdnMentionFactory,
|
||||||
|
Tag $mstdnTagFactory, Card $mstdnCardFactory,
|
||||||
|
Attachment $mstdnAttachementFactory, Error $mstdnErrorFactory)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
$this->dba = $dba;
|
||||||
$this->baseUrl = $baseURL;
|
$this->mstdnAccountFactory = $mstdnAccountFactory;
|
||||||
$this->profileField = $profileField;
|
$this->mstdnMentionFactory = $mstdnMentionFactory;
|
||||||
$this->mstdnField = $mstdnField;
|
$this->mstdnTagFactory = $mstdnTagFactory;
|
||||||
|
$this->mstdnCardFactory = $mstdnCardFactory;
|
||||||
|
$this->mstdnAttachementFactory = $mstdnAttachementFactory;
|
||||||
|
$this->mstdnErrorFactory = $mstdnErrorFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uriId Uri-ID of the item
|
* @param int $uriId Uri-ID of the item
|
||||||
* @param int $uid Item user
|
* @param int $uid Item user
|
||||||
|
*
|
||||||
* @return \Friendica\Object\Api\Mastodon\Status
|
* @return \Friendica\Object\Api\Mastodon\Status
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws ImagickException|HTTPException\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId, $uid = 0)
|
public function createFromUriId(int $uriId, $uid = 0): \Friendica\Object\Api\Mastodon\Status
|
||||||
{
|
{
|
||||||
$fields = ['uri-id', 'uid', 'author-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
|
$fields = ['uri-id', 'uid', 'author-id', 'author-link', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
|
||||||
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
||||||
|
@ -69,29 +82,53 @@ class Status extends BaseFactory
|
||||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
|
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = DI::mstdnAccount()->createFromContactId($item['author-id']);
|
$account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);
|
||||||
|
|
||||||
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
|
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts(
|
||||||
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], []),
|
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_COMMENT, 'deleted' => false], []),
|
||||||
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false], []),
|
Post::countPosts([
|
||||||
Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false], [])
|
'thr-parent-id' => $uriId,
|
||||||
|
'gravity' => GRAVITY_ACTIVITY,
|
||||||
|
'vid' => Verb::getID(Activity::ANNOUNCE),
|
||||||
|
'deleted' => false
|
||||||
|
], []),
|
||||||
|
Post::countPosts([
|
||||||
|
'thr-parent-id' => $uriId,
|
||||||
|
'gravity' => GRAVITY_ACTIVITY,
|
||||||
|
'vid' => Verb::getID(Activity::LIKE),
|
||||||
|
'deleted' => false
|
||||||
|
], [])
|
||||||
);
|
);
|
||||||
|
|
||||||
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
|
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
|
||||||
Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false]),
|
Post::exists([
|
||||||
Post::exists(['thr-parent-id' => $uriId, 'uid' => $uid, 'origin' => true, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE), 'deleted' => false]),
|
'thr-parent-id' => $uriId,
|
||||||
|
'uid' => $uid,
|
||||||
|
'origin' => true,
|
||||||
|
'gravity' => GRAVITY_ACTIVITY,
|
||||||
|
'vid' => Verb::getID(Activity::LIKE)
|
||||||
|
, 'deleted' => false
|
||||||
|
]),
|
||||||
|
Post::exists([
|
||||||
|
'thr-parent-id' => $uriId,
|
||||||
|
'uid' => $uid,
|
||||||
|
'origin' => true,
|
||||||
|
'gravity' => GRAVITY_ACTIVITY,
|
||||||
|
'vid' => Verb::getID(Activity::ANNOUNCE),
|
||||||
|
'deleted' => false
|
||||||
|
]),
|
||||||
Post\ThreadUser::getIgnored($uriId, $uid),
|
Post\ThreadUser::getIgnored($uriId, $uid),
|
||||||
(bool)($item['starred'] && ($item['gravity'] == GRAVITY_PARENT)),
|
(bool)($item['starred'] && ($item['gravity'] == GRAVITY_PARENT)),
|
||||||
Post\ThreadUser::getPinned($uriId, $uid)
|
Post\ThreadUser::getPinned($uriId, $uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
$sensitive = DBA::exists('tag-view', ['uri-id' => $uriId, 'name' => 'nsfw']);
|
$sensitive = $this->dba->exists('tag-view', ['uri-id' => $uriId, 'name' => 'nsfw']);
|
||||||
$application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: ContactSelector::networkToName($item['network'], $item['author-link']));
|
$application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: ContactSelector::networkToName($item['network'], $item['author-link']));
|
||||||
|
|
||||||
$mentions = DI::mstdnMention()->createFromUriId($uriId);
|
$mentions = $this->mstdnMentionFactory->createFromUriId($uriId)->getArrayCopy();
|
||||||
$tags = DI::mstdnTag()->createFromUriId($uriId);
|
$tags = $this->mstdnTagFactory->createFromUriId($uriId);
|
||||||
$card = DI::mstdnCard()->createFromUriId($uriId);
|
$card = $this->mstdnCardFactory->createFromUriId($uriId);
|
||||||
$attachments = DI::mstdnAttachment()->createFromUriId($uriId);
|
$attachments = $this->mstdnAttachementFactory->createFromUriId($uriId);
|
||||||
|
|
||||||
$shared = BBCode::fetchShareAttributes($item['body']);
|
$shared = BBCode::fetchShareAttributes($item['body']);
|
||||||
if (!empty($shared['guid'])) {
|
if (!empty($shared['guid'])) {
|
||||||
|
@ -99,21 +136,21 @@ class Status extends BaseFactory
|
||||||
|
|
||||||
$shared_uri_id = $shared_item['uri-id'] ?? 0;
|
$shared_uri_id = $shared_item['uri-id'] ?? 0;
|
||||||
|
|
||||||
$mentions = array_merge($mentions, DI::mstdnMention()->createFromUriId($shared_uri_id));
|
$mentions = array_merge($mentions, $this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy());
|
||||||
$tags = array_merge($tags, DI::mstdnTag()->createFromUriId($shared_uri_id));
|
$tags = array_merge($tags, $this->mstdnTagFactory->createFromUriId($shared_uri_id));
|
||||||
$attachments = array_merge($attachments, DI::mstdnAttachment()->createFromUriId($shared_uri_id));
|
$attachments = array_merge($attachments, $this->mstdnAttachementFactory->createFromUriId($shared_uri_id));
|
||||||
|
|
||||||
if (empty($card->toArray())) {
|
if (empty($card->toArray())) {
|
||||||
$card = DI::mstdnCard()->createFromUriId($shared_uri_id);
|
$card = $this->mstdnCardFactory->createFromUriId($shared_uri_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
|
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
|
||||||
$reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
|
$reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
|
||||||
$reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $uid]]);
|
$reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
|
||||||
$item['title'] = $reshared_item['title'] ?? $item['title'];
|
$item['title'] = $reshared_item['title'] ?? $item['title'];
|
||||||
$item['body'] = $reshared_item['body'] ?? $item['body'];
|
$item['body'] = $reshared_item['body'] ?? $item['body'];
|
||||||
} else {
|
} else {
|
||||||
$reshare = [];
|
$reshare = [];
|
||||||
}
|
}
|
||||||
|
@ -123,20 +160,21 @@ class Status extends BaseFactory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uriId id of the mail
|
* @param int $uriId id of the mail
|
||||||
|
*
|
||||||
* @return \Friendica\Object\Api\Mastodon\Status
|
* @return \Friendica\Object\Api\Mastodon\Status
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws ImagickException|HTTPException\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function createFromMailId(int $id)
|
public function createFromMailId(int $id): \Friendica\Object\Api\Mastodon\Status
|
||||||
{
|
{
|
||||||
$item = ActivityPub\Transmitter::ItemArrayFromMail($id, true);
|
$item = ActivityPub\Transmitter::ItemArrayFromMail($id, true);
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
DI::mstdnError()->RecordNotFound();
|
$this->mstdnErrorFactory->RecordNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = DI::mstdnAccount()->createFromContactId($item['author-id']);
|
$account = $this->mstdnAccountFactory->createFromContactId($item['author-id']);
|
||||||
|
|
||||||
$replies = DBA::count('mail', ['thr-parent-id' => $item['uri-id'], 'reply' => true]);
|
$replies = $this->dba->count('mail', ['thr-parent-id' => $item['uri-id'], 'reply' => true]);
|
||||||
|
|
||||||
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts($replies, 0, 0);
|
$counts = new \Friendica\Object\Api\Mastodon\Status\Counts($replies, 0, 0);
|
||||||
|
|
||||||
|
|
|
@ -25,39 +25,31 @@ use Friendica\App\BaseURL;
|
||||||
use Friendica\BaseFactory;
|
use Friendica\BaseFactory;
|
||||||
use Friendica\Model\Tag as TagModel;
|
use Friendica\Model\Tag as TagModel;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Repository\ProfileField;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Tag extends BaseFactory
|
class Tag extends BaseFactory
|
||||||
{
|
{
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
protected $baseUrl;
|
private $baseUrl;
|
||||||
/** @var ProfileField */
|
|
||||||
protected $profileField;
|
|
||||||
/** @var Field */
|
|
||||||
protected $mstdnField;
|
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
|
public function __construct(LoggerInterface $logger, BaseURL $baseURL)
|
||||||
{
|
{
|
||||||
parent::__construct($logger);
|
parent::__construct($logger);
|
||||||
|
|
||||||
$this->baseUrl = $baseURL;
|
$this->baseUrl = $baseURL;
|
||||||
$this->profileField = $profileField;
|
|
||||||
$this->mstdnField = $mstdnField;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uriId Uri-ID of the item
|
* @param int $uriId Uri-ID of the item
|
||||||
* @return array
|
* @return array
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
|
||||||
*/
|
*/
|
||||||
public function createFromUriId(int $uriId)
|
public function createFromUriId(int $uriId): array
|
||||||
{
|
{
|
||||||
$hashtags = [];
|
$hashtags = [];
|
||||||
$tags = TagModel::getByURIId($uriId, [TagModel::HASHTAG]);
|
$tags = TagModel::getByURIId($uriId, [TagModel::HASHTAG]);
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, $tag);
|
$hashtag = new \Friendica\Object\Api\Mastodon\Tag($this->baseUrl, $tag);
|
||||||
$hashtags[] = $hashtag->toArray();
|
$hashtags[] = $hashtag->toArray();
|
||||||
}
|
}
|
||||||
return $hashtags;
|
return $hashtags;
|
||||||
|
|
|
@ -80,6 +80,6 @@ class Apps extends BaseApi
|
||||||
DI::mstdnError()->InternalError();
|
DI::mstdnError()->InternalError();
|
||||||
}
|
}
|
||||||
|
|
||||||
System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId()));
|
System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ class Error extends BaseDataTransferObject
|
||||||
*
|
*
|
||||||
* @param string $error
|
* @param string $error
|
||||||
* @param string error_description
|
* @param string error_description
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
||||||
*/
|
*/
|
||||||
public function __construct(string $error, string $error_description)
|
public function __construct(string $error, string $error_description)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,9 @@
|
||||||
|
|
||||||
namespace Friendica\Object\Api\Mastodon;
|
namespace Friendica\Object\Api\Mastodon;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Friendica\BaseDataTransferObject;
|
use Friendica\BaseDataTransferObject;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,8 +47,7 @@ class Notification extends BaseDataTransferObject
|
||||||
/**
|
/**
|
||||||
* Creates a notification record
|
* Creates a notification record
|
||||||
*
|
*
|
||||||
* @param array $item
|
* @throws HttpException\InternalServerErrorException|Exception
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
||||||
*/
|
*/
|
||||||
public function __construct(int $id, string $type, string $created_at, Account $account = null, Status $status = null)
|
public function __construct(int $id, string $type, string $created_at, Account $account = null, Status $status = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,5 +221,10 @@ return [
|
||||||
],
|
],
|
||||||
Network\IHTTPRequest::class => [
|
Network\IHTTPRequest::class => [
|
||||||
'instanceOf' => Network\HTTPRequest::class,
|
'instanceOf' => Network\HTTPRequest::class,
|
||||||
]
|
],
|
||||||
|
Factory\Api\Mastodon\Error::class => [
|
||||||
|
'constructParams' => [
|
||||||
|
$_SERVER
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue