Use "StatusCounts" class

This commit is contained in:
Michael 2020-09-07 18:24:11 +00:00
parent 1bca280eae
commit 59374eb6c6
3 changed files with 65 additions and 10 deletions

View 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);
}

View 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;

View File

@ -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;
}
}