From 59374eb6c6e9c81c9079cd140e72d3c48a1532f4 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 7 Sep 2020 18:24:11 +0000 Subject: [PATCH] Use "StatusCounts" class --- src/Factory/Api/Mastodon/Status.php | 9 ++- src/Object/Api/Mastodon/Status.php | 10 ++-- .../Api/Mastodon/Status/StatusCounts.php | 56 +++++++++++++++++++ 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/Object/Api/Mastodon/Status/StatusCounts.php diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index ccb131aa8..db7c7203d 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -31,7 +31,6 @@ use Friendica\Network\HTTPException; use Friendica\Protocol\Activity; use Friendica\Repository\ProfileField; use Psr\Log\LoggerInterface; -use stdClass; class Status extends BaseFactory { @@ -63,10 +62,10 @@ class Status extends BaseFactory $item = Item::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]); $account = DI::mstdnAccount()->createFromContactId($item['author-id']); - $count = new stdClass; - $count->replies = DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]); - $count->reblogs = DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]); - $count->favourites = DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)]); + $count = new \Friendica\Object\Api\Mastodon\Status\StatusCounts( + DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]), + DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::ANNOUNCE)]), + DBA::count('item', ['thr-parent-id' => $uriId, 'uid' => $uid, 'gravity' => GRAVITY_ACTIVITY, 'vid' => Verb::getID(Activity::LIKE)])); return new \Friendica\Object\Api\Mastodon\Status($item, $account, $count); } diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index a98378588..a82d100c9 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -23,8 +23,8 @@ namespace Friendica\Object\Api\Mastodon; use Friendica\BaseEntity; use Friendica\Content\Text\BBCode; +use Friendica\Object\Api\Mastodon\Status\StatusCounts; use Friendica\Util\DateTimeFormat; -use stdClass; /** * Class Status @@ -96,7 +96,7 @@ class Status extends BaseEntity * @param array $item * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(array $item, Account $account, stdClass $count) + public function __construct(array $item, Account $account, StatusCounts $count) { $this->id = (string)$item['uri-id']; $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM); @@ -115,9 +115,9 @@ class Status extends BaseEntity $this->language = null; $this->uri = $item['uri']; $this->url = $item['plink'] ?? null; - $this->replies_count = $count->replies; - $this->reblogs_count = $count->reblogs; - $this->favourites_count = $count->favourites; + $this->replies_count = $count->__get('replies'); + $this->reblogs_count = $count->__get('reblogs'); + $this->favourites_count = $count->__get('favourites'); $this->favourited = false; $this->reblogged = false; $this->muted = false; diff --git a/src/Object/Api/Mastodon/Status/StatusCounts.php b/src/Object/Api/Mastodon/Status/StatusCounts.php new file mode 100644 index 000000000..eb62326de --- /dev/null +++ b/src/Object/Api/Mastodon/Status/StatusCounts.php @@ -0,0 +1,56 @@ +. + * + */ + +namespace Friendica\Object\Api\Mastodon\Status; + +/** + * Class StatusCounts + * + * @see https://docs.joinmastodon.org/entities/status + */ +class StatusCounts +{ + /** @var int */ + protected $replies; + /** @var int */ + protected $reblogs; + /** @var int */ + protected $favourites; + + /** + * Creates a status count object + * + * @param int $replies + * @param int $reblogs + * @param int $favourites + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function __construct(int $replies, int $reblogs, int $favourites) + { + $this->replies = $replies; + $this->reblogs = $reblogs; + $this->favourites = $favourites; + } + + public function __get($name) { + return $this->$name; + } +}