Merge pull request #14270 from annando/api-platform

API: Provide platform data
This commit is contained in:
Tobias Diekershoff 2024-07-03 06:31:37 +02:00 committed by GitHub
commit aad210e891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 6 deletions

View file

@ -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);
}

View file

@ -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;
}