StdClass instead of arrays

This commit is contained in:
Michael 2020-09-07 14:34:05 +00:00
parent 07ccfb212b
commit 1bca280eae
2 changed files with 10 additions and 7 deletions

View File

@ -31,6 +31,7 @@ use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Repository\ProfileField;
use Psr\Log\LoggerInterface;
use stdClass;
class Status extends BaseFactory
{
@ -62,9 +63,10 @@ class Status extends BaseFactory
$item = Item::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]);
$account = DI::mstdnAccount()->createFromContactId($item['author-id']);
$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 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)]);
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $count);
}

View File

@ -24,6 +24,7 @@ namespace Friendica\Object\Api\Mastodon;
use Friendica\BaseEntity;
use Friendica\Content\Text\BBCode;
use Friendica\Util\DateTimeFormat;
use stdClass;
/**
* Class Status
@ -95,7 +96,7 @@ class Status extends BaseEntity
* @param array $item
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $item, Account $account, array $count)
public function __construct(array $item, Account $account, stdClass $count)
{
$this->id = (string)$item['uri-id'];
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM);
@ -114,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->replies;
$this->reblogs_count = $count->reblogs;
$this->favourites_count = $count->favourites;
$this->favourited = false;
$this->reblogged = false;
$this->muted = false;