]> git.mxchange.org Git - friendica.git/commitdiff
Cleanup Mastodon Factories
authorPhilipp <admin@philipp.info>
Sat, 5 Jun 2021 20:36:45 +0000 (22:36 +0200)
committerPhilipp <admin@philipp.info>
Sun, 20 Jun 2021 11:25:45 +0000 (13:25 +0200)
16 files changed:
src/Collection/Api/Mastodon/Mentions.php [new file with mode: 0644]
src/DI.php
src/Factory/Api/Mastodon/Account.php
src/Factory/Api/Mastodon/Application.php
src/Factory/Api/Mastodon/Attachment.php
src/Factory/Api/Mastodon/Conversation.php
src/Factory/Api/Mastodon/Error.php
src/Factory/Api/Mastodon/Field.php
src/Factory/Api/Mastodon/FollowRequest.php
src/Factory/Api/Mastodon/ListEntity.php
src/Factory/Api/Mastodon/Mention.php
src/Factory/Api/Mastodon/Notification.php
src/Factory/Api/Mastodon/Status.php
src/Factory/Api/Mastodon/Tag.php
src/Module/Api/Mastodon/Apps.php
static/dependencies.config.php

diff --git a/src/Collection/Api/Mastodon/Mentions.php b/src/Collection/Api/Mastodon/Mentions.php
new file mode 100644 (file)
index 0000000..4a43316
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+
+namespace Friendica\Collection\Api\Mastodon;
+
+use Friendica\BaseCollection;
+use Friendica\Object\Api\Mastodon\Mention;
+
+class Mentions extends BaseCollection
+{
+       /**
+        * @return Mention
+        */
+       public function current()
+       {
+               return parent::current();
+       }
+}
index 944fad805d18d8413d6e9a9e12837c646dbc456a..d8e51b439822fcd9ca242ba59085e6f8318c02f8 100644 (file)
@@ -287,14 +287,6 @@ abstract class DI
                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
         */
@@ -327,14 +319,6 @@ abstract class DI
                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
         */
@@ -343,14 +327,6 @@ abstract class DI
                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
         */
index 28335a0e8e270bd3b4922ffcb3dbde5f0e4643bc..f8474eb5e2afd36c7ac8222a0f65622a64d5c37b 100644 (file)
@@ -34,19 +34,19 @@ use Psr\Log\LoggerInterface;
 class Account extends BaseFactory
 {
        /** @var BaseURL */
-       protected $baseUrl;
+       private $baseUrl;
        /** @var ProfileField */
-       protected $profileField;
+       private $profileFieldRepo;
        /** @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);
 
-               $this->baseUrl      = $baseURL;
-               $this->profileField = $profileField;
-               $this->mstdnField   = $mstdnField;
+               $this->baseUrl           = $baseURL;
+               $this->profileFieldRepo  = $profileFieldRepo;
+               $this->mstdnFieldFactory = $mstdnFieldFactory;
        }
 
        /**
@@ -75,8 +75,8 @@ class Account extends BaseFactory
 
                $self_contact = Contact::selectFirst(['uid'], ['nurl' => $publicContact['nurl'], 'self' => true]);
                if (!empty($self_contact['uid'])) {
-                       $profileFields = $this->profileField->select(['uid' => $self_contact['uid'], 'psid' => PermissionSet::PUBLIC]);
-                       $fields        = $this->mstdnField->createFromProfileFields($profileFields);
+                       $profileFields = $this->profileFieldRepo->select(['uid' => $self_contact['uid'], 'psid' => PermissionSet::PUBLIC]);
+                       $fields        = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
                } else {
                        $fields = new Fields();
                }
@@ -94,8 +94,8 @@ class Account extends BaseFactory
        {
                $publicContact = Contact::selectFirst([], ['uid' => $userId, 'self' => true]);
 
-               $profileFields = $this->profileField->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
-               $fields        = $this->mstdnField->createFromProfileFields($profileFields);
+               $profileFields = $this->profileFieldRepo->select(['uid' => $userId, 'psid' => PermissionSet::PUBLIC]);
+               $fields        = $this->mstdnFieldFactory->createFromProfileFields($profileFields);
 
                $apcontact     = APContact::getByURL($publicContact['url'], false);
 
index 3a184d8a5efe137c86a106e3b732c755df47e1ca..b387a199c52f8d58ab5591362086d07389ddeefd 100644 (file)
 namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\BaseFactory;
-use Friendica\Database\DBA;
+use Friendica\Database\Database;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Psr\Log\LoggerInterface;
 
 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
+        *
+        * @return \Friendica\Object\Api\Mastodon\Application
+        *
+        * @throws InternalServerErrorException
         */
        public function createFromApplicationId(int $id)
        {
-               $application = DBA::selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]);
-               if (!DBA::isResult($application)) {
+               $application = $this->dba->selectFirst('application', ['client_id', 'client_secret', 'id', 'name', 'redirect_uri', 'website'], ['id' => $id]);
+               if (!$this->dba->isResult($application)) {
                        return [];
                }
 
-               $object = new \Friendica\Object\Api\Mastodon\Application(
+               return new \Friendica\Object\Api\Mastodon\Application(
                        $application['name'],
                        $application['client_id'],
                        $application['client_secret'],
                        $application['id'],
                        $application['redirect_uri'],
                        $application['website']);
-
-               return $object->toArray();
        }
 }
index f039c1a2332440d7497b0d144c731ce777899db3..12381dbb6ae4633c53f17ac2865321a92f46bf4c 100644 (file)
@@ -23,11 +23,9 @@ namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
-use Friendica\DI;
 use Friendica\Model\Photo;
 use Friendica\Network\HTTPException;
 use Friendica\Model\Post;
-use Friendica\Repository\ProfileField;
 use Friendica\Util\Images;
 use Friendica\Util\Proxy;
 use Psr\Log\LoggerInterface;
@@ -35,19 +33,13 @@ use Psr\Log\LoggerInterface;
 class Attachment extends BaseFactory
 {
        /** @var BaseURL */
-       protected $baseUrl;
-       /** @var ProfileField */
-       protected $profileField;
-       /** @var Field */
-       protected $mstdnField;
+       private $baseUrl;
 
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
        {
                parent::__construct($logger);
 
                $this->baseUrl = $baseURL;
-               $this->profileField = $profileField;
-               $this->mstdnField = $mstdnField;
        }
 
        /**
@@ -115,11 +107,11 @@ class Attachment extends BaseFactory
                $phototypes = Images::supportedTypes();
                $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']]);
                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 {
                        $preview_url = '';
                }
index d867dd0b2ae8864506e7d280e03b4f8be4aa0a91..ad873ba9a436dfff7116f9ae0c7e497bb379931a 100644 (file)
 namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\BaseFactory;
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\Database\Database;
 use Friendica\Model\Contact;
+use Psr\Log\LoggerInterface;
 
 class Conversation extends BaseFactory
 {
+       /** @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;
+       }
+
        public function CreateFromConvId(int $id)
        {
                $accounts    = [];
@@ -36,8 +51,8 @@ class Conversation extends BaseFactory
 
                $ids = [];
 
-               $mails = DBA::select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
-               while ($mail = DBA::fetch($mails)) {
+               $mails = $this->dba->select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
+               while ($mail = $this->dba->fetch($mails)) {
                        if (!$mail['seen']) {
                                $unread = true;
                        }
@@ -50,10 +65,10 @@ class Conversation extends BaseFactory
                        $ids[] = $id;
 
                        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);
index 31f719307e78d1c41cebdd98aef9d7c6bfe20c94..a4dd66ccc5ddc57f8e3818a44856fa8297114b92 100644 (file)
 
 namespace Friendica\Factory\Api\Mastodon;
 
+use Friendica\App\Arguments;
 use Friendica\BaseFactory;
-use Friendica\Core\Logger;
+use Friendica\Core\L10n;
 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
 {
+       /** @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)
        {
-               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()
        {
-               $error = DI::l10n()->t('Record not found');
+               $error = $this->l10n->t('Record not found');
                $error_description = '';
                $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
 
@@ -45,7 +62,7 @@ class Error extends BaseFactory
 
        public function UnprocessableEntity(string $error = '')
        {
-               $error = $error ?: DI::l10n()->t('Unprocessable Entity');
+               $error = $error ?: $this->l10n->t('Unprocessable Entity');
                $error_description = '';
                $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
 
@@ -55,7 +72,7 @@ class Error extends BaseFactory
 
        public function Unauthorized(string $error = '')
        {
-               $error = $error ?: DI::l10n()->t('Unauthorized');
+               $error = $error ?: $this->l10n->t('Unauthorized');
                $error_description = '';
                $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
 
@@ -65,7 +82,7 @@ class Error extends BaseFactory
 
        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 = '';
                $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
 
@@ -75,7 +92,7 @@ class Error extends BaseFactory
 
        public function InternalError(string $error = '')
        {
-               $error = $error ?: DI::l10n()->t('Internal Server Error');
+               $error = $error ?: $this->l10n->t('Internal Server Error');
                $error_description = '';
                $errorobj = New \Friendica\Object\Api\Mastodon\Error($error, $error_description);
 
index fb51f594cf696a1c418b16477177663d76e1e2f1..86c20e1f0671edb099ff926c2a195f2c8240f299 100644 (file)
@@ -32,7 +32,7 @@ class Field extends BaseFactory
 {
        /**
         * @param ProfileField $profileField
-        * @return \Friendica\Api\Entity\Mastodon\Field
+        * @return \Friendica\Object\Api\Mastodon\Field
         * @throws HTTPException\InternalServerErrorException
         */
        public function createFromProfileField(ProfileField $profileField)
index 1ee6507ae4b54cc7d48947d613602298aed793d3..84c5ec71328a1a3e1123de6a42bf9d0ef8378bc9 100644 (file)
@@ -32,7 +32,7 @@ use Psr\Log\LoggerInterface;
 class FollowRequest extends BaseFactory
 {
        /** @var BaseURL */
-       protected $baseUrl;
+       private $baseUrl;
 
        public function __construct(LoggerInterface $logger, BaseURL $baseURL)
        {
index a149b25af2bdd0f4a77cd30d770bc13b3e4ef9b2..a766d053f6ab7f05761f8257ef2993bcd9cfa648 100644 (file)
 namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\BaseFactory;
-use Friendica\Database\DBA;
+use Friendica\Database\Database;
+use Psr\Log\LoggerInterface;
 
 class ListEntity extends BaseFactory
 {
+       /** @var Database */
+       private $dba;
+
+       public function __construct(LoggerInterface $logger, Database $dba)
+       {
+               parent::__construct($logger);
+               $this->dba = $dba;
+       }
+
        public function createFromGroupId(int $id)
        {
-               $group = DBA::selectFirst('group', ['name'], ['id' => $id, 'deleted' => false]);
+               $group = $this->dba->selectFirst('group', ['name'], ['id' => $id, 'deleted' => false]);
                return new \Friendica\Object\Api\Mastodon\ListEntity($id, $group['name'] ?? '', 'list');
        }
 }
index 692ba56a8daccbafa9339d6c43f63e1e93e81ea0..cf863472c6f3f5080bab1c4c759fed1a2d712f28 100644 (file)
@@ -23,44 +23,37 @@ namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
+use Friendica\Collection\Api\Mastodon\Mentions;
 use Friendica\Model\Contact;
 use Friendica\Model\Tag;
 use Friendica\Network\HTTPException;
-use Friendica\Repository\ProfileField;
 use Psr\Log\LoggerInterface;
 
 class Mention extends BaseFactory
 {
        /** @var BaseURL */
-       protected $baseUrl;
-       /** @var ProfileField */
-       protected $profileField;
-       /** @var Field */
-       protected $mstdnField;
+       private $baseUrl;
 
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
        {
                parent::__construct($logger);
 
                $this->baseUrl = $baseURL;
-               $this->profileField = $profileField;
-               $this->mstdnField = $mstdnField;
        }
 
        /**
         * @param int $uriId Uri-ID of the item
-        * @return array
+        * @return Mentions
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
        public function createFromUriId(int $uriId)
        {
-               $mentions = [];
+               $mentions = new Mentions();
                $tags = Tag::getByURIId($uriId, [Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION]);
                foreach ($tags as $tag) {
                        $contact = Contact::getByURL($tag['url'], false);
-                       $mention = new \Friendica\Object\Api\Mastodon\Mention($this->baseUrl, $tag, $contact);
-                       $mentions[] = $mention->toArray();
+                       $mentions->append(new \Friendica\Object\Api\Mastodon\Mention($this->baseUrl, $tag, $contact));
                }
                return $mentions;
        }
index e1fc80e2982c1a26f8ec960f915826f692a03564..ef3d2b6674047f190223d11f9d5fdc246192576d 100644 (file)
 namespace Friendica\Factory\Api\Mastodon;
 
 use Friendica\BaseFactory;
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\Database\Database;
 use Friendica\Model\Contact;
 use Friendica\Model\Post;
 use Friendica\Model\Verb;
 use Friendica\Protocol\Activity;
+use Psr\Log\LoggerInterface;
 
 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)
        {
-               $notification = DBA::selectFirst('notification', [], ['id' => $id]);
-               if (!DBA::isResult($notification)) {
+               $notification = $this->dba->selectFirst('notification', [], ['id' => $id]);
+               if (!$this->dba->isResult($notification)) {
                        return null;
                }
                /*
@@ -66,11 +81,11 @@ class Notification extends BaseFactory
                        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'])) {
                        try {
-                               $status = DI::mstdnStatus()->createFromUriId($notification['target-uri-id'], $notification['uid']);
+                               $status = $this->mstdnStatusFactory->createFromUriId($notification['target-uri-id'], $notification['uid']);
                        } catch (\Throwable $th) {
                                $status = null;
                        }
index c5e18219d1626c8dc20bc423745444a150624121..3e8e3c4a3f30bb1e34f33ae8fd8bdda89fd9ceed 100644 (file)
 
 namespace Friendica\Factory\Api\Mastodon;
 
-use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Text\BBCode;
-use Friendica\Database\DBA;
-use Friendica\DI;
+use Friendica\Database\Database;
 use Friendica\Model\Post;
 use Friendica\Model\Verb;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
-use Friendica\Repository\ProfileField;
+use ImagickException;
 use Psr\Log\LoggerInterface;
 
 class Status extends BaseFactory
 {
-       /** @var BaseURL */
-       protected $baseUrl;
-       /** @var ProfileField */
-       protected $profileField;
-       /** @var Field */
-       protected $mstdnField;
-
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
+       /** @var Database */
+       private $dba;
+       /** @var Account */
+       private $mstdnAccountFactory;
+       /** @var Mention */
+       private $mstdnMentionFactory;
+       /** @var Tag */
+       private $mstdnTagFactory;
+       /** @var Card */
+       private $mstdnCardFactory;
+       /** @var Attachment */
+       private $mstdnAttachementFactory;
+       /** @var Error */
+       private $mstdnErrorFactory;
+
+       public function __construct(LoggerInterface $logger, Database $dba,
+               Account $mstdnAccountFactory, Mention $mstdnMentionFactory,
+               Tag $mstdnTagFactory, Card $mstdnCardFactory,
+               Attachment $mstdnAttachementFactory, Error $mstdnErrorFactory)
        {
                parent::__construct($logger);
-
-               $this->baseUrl = $baseURL;
-               $this->profileField = $profileField;
-               $this->mstdnField = $mstdnField;
+               $this->dba                     = $dba;
+               $this->mstdnAccountFactory     = $mstdnAccountFactory;
+               $this->mstdnMentionFactory     = $mstdnMentionFactory;
+               $this->mstdnTagFactory         = $mstdnTagFactory;
+               $this->mstdnCardFactory        = $mstdnCardFactory;
+               $this->mstdnAttachementFactory = $mstdnAttachementFactory;
+               $this->mstdnErrorFactory       = $mstdnErrorFactory;
        }
 
        /**
         * @param int $uriId Uri-ID of the item
         * @param int $uid   Item user
+        *
         * @return \Friendica\Object\Api\Mastodon\Status
         * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
+        * @throws ImagickException|HTTPException\NotFoundException
         */
        public function createFromUriId(int $uriId, $uid = 0)
        {
@@ -69,29 +82,53 @@ class Status extends BaseFactory
                        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(
                        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(['thr-parent-id' => $uriId, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE), 'deleted' => false], [])
+                       Post::countPosts([
+                               '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(
-                       Post::exists(['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::exists([
+                               '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),
                        (bool)($item['starred'] && ($item['gravity'] == GRAVITY_PARENT)),
                        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']));
 
-               $mentions    = DI::mstdnMention()->createFromUriId($uriId);
-               $tags        = DI::mstdnTag()->createFromUriId($uriId);
-               $card        = DI::mstdnCard()->createFromUriId($uriId);
-               $attachments = DI::mstdnAttachment()->createFromUriId($uriId);
+               $mentions    = $this->mstdnMentionFactory->createFromUriId($uriId)->getArrayCopy();
+               $tags        = $this->mstdnTagFactory->createFromUriId($uriId);
+               $card        = $this->mstdnCardFactory->createFromUriId($uriId);
+               $attachments = $this->mstdnAttachementFactory->createFromUriId($uriId);
 
                $shared = BBCode::fetchShareAttributes($item['body']);
                if (!empty($shared['guid'])) {
@@ -99,21 +136,21 @@ class Status extends BaseFactory
 
                        $shared_uri_id = $shared_item['uri-id'] ?? 0;
 
-                       $mentions    = array_merge($mentions, DI::mstdnMention()->createFromUriId($shared_uri_id));
-                       $tags        = array_merge($tags, DI::mstdnTag()->createFromUriId($shared_uri_id));
-                       $attachments = array_merge($attachments, DI::mstdnAttachment()->createFromUriId($shared_uri_id));
+                       $mentions    = array_merge($mentions, $this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy());
+                       $tags        = array_merge($tags, $this->mstdnTagFactory->createFromUriId($shared_uri_id));
+                       $attachments = array_merge($attachments, $this->mstdnAttachementFactory->createFromUriId($shared_uri_id));
 
                        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)) {
-                       $reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
-                       $reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $uid]]);
+                       $reshare       = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
+                       $reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
                        $item['title'] = $reshared_item['title'] ?? $item['title'];
-                       $item['body'] = $reshared_item['body'] ?? $item['body'];
+                       $item['body']  = $reshared_item['body'] ?? $item['body'];
                } else {
                        $reshare = [];
                }
@@ -123,20 +160,21 @@ class Status extends BaseFactory
 
        /**
         * @param int $uriId id of the mail
+        *
         * @return \Friendica\Object\Api\Mastodon\Status
         * @throws HTTPException\InternalServerErrorException
-        * @throws \ImagickException
+        * @throws ImagickException
         */
        public function createFromMailId(int $id)
        {
                $item = ActivityPub\Transmitter::ItemArrayFromMail($id, true);
                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);
 
index d7f8369b91c6e74ccdf7d36398c266eeb0b7a323..566b4c2696bb43fd9d3425f5e2b0d50399e19aeb 100644 (file)
@@ -25,25 +25,18 @@ use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
 use Friendica\Model\Tag as TagModel;
 use Friendica\Network\HTTPException;
-use Friendica\Repository\ProfileField;
 use Psr\Log\LoggerInterface;
 
 class Tag extends BaseFactory
 {
        /** @var BaseURL */
-       protected $baseUrl;
-       /** @var ProfileField */
-       protected $profileField;
-       /** @var Field */
-       protected $mstdnField;
+       private $baseUrl;
 
-       public function __construct(LoggerInterface $logger, BaseURL $baseURL, ProfileField $profileField, Field $mstdnField)
+       public function __construct(LoggerInterface $logger, BaseURL $baseURL)
        {
                parent::__construct($logger);
 
                $this->baseUrl = $baseURL;
-               $this->profileField = $profileField;
-               $this->mstdnField = $mstdnField;
        }
 
        /**
index f16ceea859f3db646d2c0b99e8d9ac17aede8048..040607137c9c83ced95c5b458756ea31ba74a69d 100644 (file)
@@ -80,6 +80,6 @@ class Apps extends BaseApi
                        DI::mstdnError()->InternalError();
                }
 
-               System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId()));
+               System::jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
        }
 }
index 744c6df09dcbea8280acbb084b254b1e1d6d3531..90fa13684ca98a31e28cf4a303b872da198bbbc0 100644 (file)
@@ -221,5 +221,10 @@ return [
        ],
        Network\IHTTPRequest::class => [
                'instanceOf' => Network\HTTPRequest::class,
-       ]
+       ],
+       Factory\Api\Mastodon\Error::class => [
+               'constructParams' => [
+                       $_SERVER
+               ],
+       ],
 ];