From efe2f5273da577b0155dc48ce430d8b258adda8c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 Jul 2024 03:32:08 +0000 Subject: [PATCH] API: Provide platform data --- src/Factory/Api/Mastodon/Status.php | 31 +++++++++++++++---- .../Mastodon/Status/FriendicaExtension.php | 18 +++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index d25c22d4e5..e5880647a1 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -27,6 +27,7 @@ use Friendica\Content\Item as ContentItem; use Friendica\Content\Smilies; use Friendica\Content\Text\BBCode; use Friendica\Core\Logger; +use Friendica\Core\Protocol; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; @@ -105,7 +106,7 @@ class Status extends BaseFactory */ public function createFromUriId(int $uriId, int $uid = 0, bool $display_quote = false, bool $reblog = true, bool $in_reply_status = true): \Friendica\Object\Api\Mastodon\Status { - $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', + $fields = ['uri-id', 'uid', 'author-id', 'causer-id', 'author-uri-id', 'author-link', 'author-gsid', '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', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid', 'sensitive']; $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]); @@ -212,9 +213,27 @@ class Status extends BaseFactory $item['featured'] ); - $sensitive = (bool)$item['sensitive']; - $network = ContactSelector::networkToName($item['network'], $item['author-link']); - $application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: $network); + $sensitive = (bool)$item['sensitive']; + + $network = ContactSelector::networkToName($item['network']); + $sitename = ''; + $platform = ''; + $version = ''; + + if (in_array($item['network'], Protocol::FEDERATED)) { + $gserver = $this->dba->selectFirst('gserver', ['site_name', 'platform', 'version'], ['id' => $item['author-gsid']]); + if (!empty($gserver)) { + $platform = ucfirst($gserver['platform']); + $version = $gserver['version']; + $sitename = $gserver['site_name']; + } + } + + if ($platform == '') { + $platform = ContactSelector::networkToName($item['network'], $item['author-link'], $item['network'], $item['author-gsid']); + } + + $application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: $platform); $mentions = $this->mstdnMentionFactory->createFromUriId($uriId)->getArrayCopy(); $tags = $this->mstdnTagFactory->createFromUriId($uriId); @@ -323,7 +342,7 @@ class Status extends BaseFactory $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($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, $network, $delivery_data, $visibility_data); + $friendica = new FriendicaExtension($item['title'] ?? '', $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $origin_dislike, $network, $platform, $version, $sitename, $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, $emojis); } @@ -394,7 +413,7 @@ class Status extends BaseFactory $attachments = []; $in_reply = []; $reshare = []; - $friendica = new FriendicaExtension('', null, null, null, 0, false, null, null, null); + $friendica = new FriendicaExtension('', null, null, null, 0, false, null, null, null, null, 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 640cfecacb..152acaae17 100644 --- a/src/Object/Api/Mastodon/Status/FriendicaExtension.php +++ b/src/Object/Api/Mastodon/Status/FriendicaExtension.php @@ -57,6 +57,15 @@ class FriendicaExtension extends BaseDataTransferObject /** @var string|null */ protected $network; + /** @var string|null */ + protected $platform; + + /** @var string|null */ + protected $version; + + /** @var string|null */ + protected $sitename; + /** * @var FriendicaVisibility|null */ @@ -72,6 +81,9 @@ class FriendicaExtension extends BaseDataTransferObject * @param int $dislikes_count * @param bool $disliked * @param ?string $network + * @param ?string $platform + * @param ?string $version + * @param ?string $sitename * @param ?FriendicaDeliveryData $delivery_data * @param ?FriendicaVisibility $visibility * @throws \Exception @@ -84,6 +96,9 @@ class FriendicaExtension extends BaseDataTransferObject int $dislikes_count, bool $disliked, ?string $network, + ?string $platform, + ?string $version, + ?string $sitename, ?FriendicaDeliveryData $delivery_data, ?FriendicaVisibility $visibility ) { @@ -95,6 +110,9 @@ class FriendicaExtension extends BaseDataTransferObject $this->dislikes_count = $dislikes_count; $this->disliked = $disliked; $this->network = $network; + $this->platform = $platform; + $this->version = $version; + $this->sitename = $sitename; $this->visibility = $visibility; }