mirror of
https://github.com/friendica/friendica
synced 2024-12-23 03:20:15 +00:00
API: Provide platform data
This commit is contained in:
parent
7d2900c2e0
commit
efe2f5273d
2 changed files with 43 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue