]> git.mxchange.org Git - friendica.git/commitdiff
Add dislike counts to Mastodon API Statuses in FriendicaExtension
authorHank Grabowski <hankgrabowski@gmail.com>
Mon, 20 Feb 2023 20:31:15 +0000 (15:31 -0500)
committerHank Grabowski <hankgrabowski@gmail.com>
Mon, 20 Feb 2023 20:31:15 +0000 (15:31 -0500)
src/Factory/Api/Mastodon/Status.php
src/Object/Api/Mastodon/Status.php
src/Object/Api/Mastodon/Status/Counts.php
src/Object/Api/Mastodon/Status/FriendicaExtension.php

index 9f6d3bcde95877dfa47addf0e6a61d2d007b86c9..4d93d08927694caefaeadbc6da07abc5a275f1fe 100644 (file)
@@ -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);
 
index 51f0b1c396621e82ea412563f9b75e01cc9ab67b..30f554bdf5d61433cba6936a43e0a4d61761a2d4 100644 (file)
@@ -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);
        }
 
        /**
index 26eb361cf880dffeb4e17af9abaf054d5b66545e..207f78a43d5082d9a9f60cfc7e797d13d02df290 100644 (file)
@@ -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;
        }
 }
index 050c5a0268c557ae95372b952736a45778342e14..1db70f7312074c9ae5268ea3280c0ee977511945 100644 (file)
@@ -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;
        }
 }