use Friendica\Protocol\Activity;
use Friendica\Repository\ProfileField;
use Psr\Log\LoggerInterface;
-use stdClass;
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);
}
use Friendica\BaseEntity;
use Friendica\Content\Text\BBCode;
+use Friendica\Object\Api\Mastodon\Status\StatusCounts;
use Friendica\Util\DateTimeFormat;
-use stdClass;
/**
* Class Status
* @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);
$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;
--- /dev/null
+<?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;
+ }
+}