]> git.mxchange.org Git - friendica.git/commitdiff
Use "StatusCounts" class
authorMichael <heluecht@pirati.ca>
Mon, 7 Sep 2020 18:24:11 +0000 (18:24 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 7 Sep 2020 18:24:11 +0000 (18:24 +0000)
src/Factory/Api/Mastodon/Status.php
src/Object/Api/Mastodon/Status.php
src/Object/Api/Mastodon/Status/StatusCounts.php [new file with mode: 0644]

index ccb131aa8f62af2a7baec7f01d8b24cd6e3e3925..db7c7203dc5e8671e9de301e90d89474fae903cf 100644 (file)
@@ -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);
        }
index a983785884651a99ed8494841289d55e7912b5c3..a82d100c98f06e8a516623d02e6a82c97c575daf 100644 (file)
@@ -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 (file)
index 0000000..eb62326
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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;
+    }
+}