From 3a8929be1f9db32f39c4e6010c4608a30aaeb257 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Mon, 20 Feb 2023 15:31:15 -0500 Subject: [PATCH] Add dislike counts to Mastodon API Statuses in FriendicaExtension --- src/Factory/Api/Mastodon/Status.php | 12 ++++++++++-- src/Object/Api/Mastodon/Status.php | 2 +- src/Object/Api/Mastodon/Status/Counts.php | 13 +++++++++---- .../Api/Mastodon/Status/FriendicaExtension.php | 8 ++++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index 9f6d3bcde9..4d93d08927 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -144,10 +144,18 @@ class Status extends BaseFactory 'deleted' => false ]); + $count_dislike = Post::countPosts([ + 'thr-parent-id' => $uriId, + 'gravity' => Item::GRAVITY_ACTIVITY, + 'vid' => Verb::getID(Activity::DISLIKE), + 'deleted' => false + ]); + $counts = new \Friendica\Object\Api\Mastodon\Status\Counts( Post::countPosts(['thr-parent-id' => $uriId, 'gravity' => Item::GRAVITY_COMMENT, 'deleted' => false], []), $count_announce, - $count_like + $count_like, + $count_dislike ); $origin_like = ($count_like == 0) ? false : Post::exists([ @@ -323,7 +331,7 @@ class Status extends BaseFactory $replies = $this->dba->count('mail', ['thr-parent-id' => $item['uri-id'], 'reply' => true]); - $counts = new \Friendica\Object\Api\Mastodon\Status\Counts($replies, 0, 0); + $counts = new \Friendica\Object\Api\Mastodon\Status\Counts($replies, 0, 0, 0); $userAttributes = new \Friendica\Object\Api\Mastodon\Status\UserAttributes(false, false, false, false, false); diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index 51f0b1c396..30f554bdf5 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -151,7 +151,7 @@ class Status extends BaseDataTransferObject $this->emojis = []; $this->card = $card->toArray() ?: null; $this->poll = $poll; - $this->friendica = new FriendicaExtension($item['title']); + $this->friendica = new FriendicaExtension($item['title'], $counts->dislikes); } /** diff --git a/src/Object/Api/Mastodon/Status/Counts.php b/src/Object/Api/Mastodon/Status/Counts.php index 26eb361cf8..207f78a43d 100644 --- a/src/Object/Api/Mastodon/Status/Counts.php +++ b/src/Object/Api/Mastodon/Status/Counts.php @@ -35,6 +35,9 @@ class Counts /** @var int */ protected $favourites; + /** @var int */ + protected $dislikes; + /** * Creates a status count object * @@ -43,14 +46,16 @@ class Counts * @param int $favourites * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(int $replies, int $reblogs, int $favourites) + public function __construct(int $replies, int $reblogs, int $favourites, int $dislikes) { - $this->replies = $replies; - $this->reblogs = $reblogs; + $this->replies = $replies; + $this->reblogs = $reblogs; $this->favourites = $favourites; + $this->dislikes = $dislikes; } - public function __get($name) { + public function __get($name) + { return $this->$name; } } diff --git a/src/Object/Api/Mastodon/Status/FriendicaExtension.php b/src/Object/Api/Mastodon/Status/FriendicaExtension.php index 050c5a0268..1db70f7312 100644 --- a/src/Object/Api/Mastodon/Status/FriendicaExtension.php +++ b/src/Object/Api/Mastodon/Status/FriendicaExtension.php @@ -35,14 +35,18 @@ class FriendicaExtension extends BaseDataTransferObject /** @var string */ protected $title; + /** @var int */ + protected $dislikes_count; + /** * Creates a status count object * * @param string $title * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(string $title) + public function __construct(string $title, int $dislikes_count) { - $this->title = $title; + $this->title = $title; + $this->dislikes_count = $dislikes_count; } } -- 2.39.5