diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index 190f1e0e2..62941978e 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -28,6 +28,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Logger; use Friendica\Database\Database; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\Tag as TagModel; @@ -35,6 +36,7 @@ use Friendica\Model\Verb; use Friendica\Network\HTTPException; use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData; use Friendica\Object\Api\Mastodon\Status\FriendicaExtension; +use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityPub; use ImagickException; @@ -100,7 +102,7 @@ class Status extends BaseFactory { $fields = ['uri-id', 'uid', 'author-id', 'causer-id', 'author-uri-id', 'author-link', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id', 'created', 'edited', 'commented', 'received', 'changed', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media', 'quote-uri-id', - 'delivery_queue_count', 'delivery_queue_done','delivery_queue_failed']; + 'delivery_queue_count', 'delivery_queue_done','delivery_queue_failed', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid']; $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]); if (!$item) { $mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]); @@ -290,8 +292,10 @@ class Status extends BaseFactory $in_reply = []; } - $delivery_data = new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']); - $friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $delivery_data); + $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'])); + $friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $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); } @@ -357,7 +361,7 @@ class Status extends BaseFactory $attachments = []; $in_reply = []; $reshare = []; - $friendica = new FriendicaExtension('', null, null, null, 0, new FriendicaDeliveryData(0, 0, 0)); + $friendica = new FriendicaExtension('', null, null, null, 0, null, null); return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica); } diff --git a/src/Object/Api/Mastodon/Status/FriendicaExtension.php b/src/Object/Api/Mastodon/Status/FriendicaExtension.php index 5702c0678..be49fe3c5 100644 --- a/src/Object/Api/Mastodon/Status/FriendicaExtension.php +++ b/src/Object/Api/Mastodon/Status/FriendicaExtension.php @@ -45,14 +45,18 @@ class FriendicaExtension extends BaseDataTransferObject /** @var string|null (Datetime) */ protected $received_at; - /** @var FriendicaDeliveryData */ + /** @var FriendicaDeliveryData|null */ protected $delivery_data; /** @var int */ protected $dislikes_count; + /** + * @var FriendicaVisibility|null + */ + protected $visibility; /** - * Creates a status count object + * Creates a FriendicaExtension object * * @param string $title * @param string|null $changed_at @@ -60,7 +64,8 @@ class FriendicaExtension extends BaseDataTransferObject * @param string|null $edited_at * @param string|null $received_at * @param int $dislikes_count - * @param FriendicaDeliveryData $delivery_data + * @param FriendicaDeliveryData|null $delivery_data + * @param FriendicaVisibility|null $visibility */ public function __construct( string $title, @@ -68,7 +73,8 @@ class FriendicaExtension extends BaseDataTransferObject ?string $commented_at, ?string $received_at, int $dislikes_count, - FriendicaDeliveryData $delivery_data + ?FriendicaDeliveryData $delivery_data, + ?FriendicaVisibility $visibility ) { $this->title = $title; $this->changed_at = $changed_at ? DateTimeFormat::utc($changed_at, DateTimeFormat::JSON) : null; @@ -76,6 +82,7 @@ class FriendicaExtension extends BaseDataTransferObject $this->received_at = $received_at ? DateTimeFormat::utc($received_at, DateTimeFormat::JSON) : null; $this->delivery_data = $delivery_data; $this->dislikes_count = $dislikes_count; + $this->visibility = $visibility; } /** diff --git a/src/Object/Api/Mastodon/Status/FriendicaVisibility.php b/src/Object/Api/Mastodon/Status/FriendicaVisibility.php new file mode 100644 index 000000000..6ded2bfc3 --- /dev/null +++ b/src/Object/Api/Mastodon/Status/FriendicaVisibility.php @@ -0,0 +1,51 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\Status; + +use Friendica\BaseDataTransferObject; + +/** + * Class FriendicaVisibility + * + * Fields for the user's visibility settings on a post if they own that post + * + * @see https://docs.joinmastodon.org/entities/status + */ +class FriendicaVisibility extends BaseDataTransferObject +{ + /** @var array */ + protected $allow_cid; + /** @var array */ + protected $deny_cid; + /** @var array */ + protected $allow_gid; + /** @var array */ + protected $deny_gid; + + public function __construct(array $allow_cid, array $deny_cid, array $allow_gid, array $deny_gid) + { + $this->allow_cid = $allow_cid; + $this->deny_cid = $deny_cid; + $this->allow_gid = $allow_gid; + $this->deny_gid = $deny_gid; + } +}