Reformat Factory\Api\Mastodon\Status

- Simplify boolean operations
- Add ACLFormatter dependency to constructor
- Fix white space alignment
This commit is contained in:
Hypolite Petovan 2023-04-02 23:19:40 -04:00
parent f721565046
commit 09f9559769
2 changed files with 25 additions and 21 deletions

View file

@ -39,6 +39,7 @@ use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility;
use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\ACLFormatter;
use ImagickException;
use Psr\Log\LoggerInterface;
@ -62,6 +63,8 @@ class Status extends BaseFactory
private $mstdnPollFactory;
/** @var ContentItem */
private $contentItem;
/** @var ACLFormatter */
private $aclFormatter;
public function __construct(
LoggerInterface $logger,
@ -73,7 +76,8 @@ class Status extends BaseFactory
Attachment $mstdnAttachmentFactory,
Error $mstdnErrorFactory,
Poll $mstdnPollFactory,
ContentItem $contentItem
ContentItem $contentItem,
ACLFormatter $aclFormatter
) {
parent::__construct($logger);
$this->dba = $dba;
@ -85,6 +89,7 @@ class Status extends BaseFactory
$this->mstdnErrorFactory = $mstdnErrorFactory;
$this->mstdnPollFactory = $mstdnPollFactory;
$this->contentItem = $contentItem;
$this->aclFormatter = $aclFormatter;
}
/**
@ -169,7 +174,7 @@ class Status extends BaseFactory
$count_dislike
);
$origin_like = ($count_like == 0) ? false : Post::exists([
$origin_like = $count_like > 0 && Post::exists([
'thr-parent-id' => $uriId,
'uid' => $uid,
'origin' => true,
@ -177,7 +182,7 @@ class Status extends BaseFactory
'vid' => Verb::getID(Activity::LIKE),
'deleted' => false
]);
$origin_dislike = ($count_dislike == 0) ? false : Post::exists([
$origin_dislike = $count_dislike > 0 && Post::exists([
'thr-parent-id' => $uriId,
'uid' => $uid,
'origin' => true,
@ -185,7 +190,7 @@ class Status extends BaseFactory
'vid' => Verb::getID(Activity::DISLIKE),
'deleted' => false
]);
$origin_announce = ($count_announce == 0) ? false : Post::exists([
$origin_announce = $count_announce > 0 && (Post::exists([
'thr-parent-id' => $uriId,
'uid' => $uid,
'origin' => true,
@ -194,16 +199,16 @@ class Status extends BaseFactory
'deleted' => false
]) || Post::exists([
'quote-uri-id' => $uriId,
'uid' => $uid,
'origin' => true,
'body' => '',
'deleted' => false
]);
'uid' => $uid,
'origin' => true,
'body' => '',
'deleted' => false
]));
$userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(
$origin_like,
$origin_announce,
Post\ThreadUser::getIgnored($uriId, $uid),
(bool)($item['starred'] && ($item['gravity'] == Item::GRAVITY_PARENT)),
$item['starred'] && $item['gravity'] == Item::GRAVITY_PARENT,
$item['featured']
);
@ -300,9 +305,8 @@ class Status extends BaseFactory
$in_reply = [];
}
$aclFormatter = DI::aclFormatter();
$delivery_data = $uid != $item['uid'] ? null : new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']);
$visibility_data = $uid != $item['uid'] ? null : new FriendicaVisibility($aclFormatter->expand($item['allow_cid']), $aclFormatter->expand($item['deny_cid']), $aclFormatter->expand($item['allow_gid']), $aclFormatter->expand($item['deny_gid']));
$visibility_data = $uid != $item['uid'] ? null : new FriendicaVisibility($this->aclFormatter->expand($item['allow_cid']), $this->aclFormatter->expand($item['deny_cid']), $this->aclFormatter->expand($item['allow_gid']), $this->aclFormatter->expand($item['deny_gid']));
$friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $origin_dislike, $delivery_data, $visibility_data);
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica, $quote, $poll);

View file

@ -62,15 +62,15 @@ class FriendicaExtension extends BaseDataTransferObject
/**
* Creates a FriendicaExtension object
*
* @param string $title
* @param string|null $changed_at
* @param string|null $commented_at
* @param string|null $edited_at
* @param string|null $received_at
* @param int $dislikes_count
* @param bool $disliked
* @param FriendicaDeliveryData|null $delivery_data
* @param FriendicaVisibility|null $visibility
* @param string $title
* @param ?string $changed_at
* @param ?string $commented_at
* @param ?string $received_at
* @param int $dislikes_count
* @param bool $disliked
* @param ?FriendicaDeliveryData $delivery_data
* @param ?FriendicaVisibility $visibility
* @throws \Exception
*/
public function __construct(
string $title,