X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FApi%2FMastodon%2FAccount.php;h=5a66209777c37c3469da55f13ea60b8de3402512;hb=32bb0976046ef9fa2296d0aeb39a01b0b916dc1e;hp=a5f401a0f3ed57ef86842a26a57985f335280942;hpb=608e634858944601a6041ac7e88a4e7abb0f49e0;p=friendica.git diff --git a/src/Object/Api/Mastodon/Account.php b/src/Object/Api/Mastodon/Account.php index a5f401a0f3..5a66209777 100644 --- a/src/Object/Api/Mastodon/Account.php +++ b/src/Object/Api/Mastodon/Account.php @@ -1,21 +1,41 @@ . + * + */ namespace Friendica\Object\Api\Mastodon; use Friendica\App\BaseURL; -use Friendica\BaseEntity; +use Friendica\BaseDataTransferObject; use Friendica\Collection\Api\Mastodon\Fields; use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Proxy; /** * Class Account * * @see https://docs.joinmastodon.org/entities/account */ -class Account extends BaseEntity +class Account extends BaseDataTransferObject { /** @var string */ protected $id; @@ -27,14 +47,14 @@ class Account extends BaseEntity protected $display_name; /** @var bool */ protected $locked; - /** @var string (Datetime) */ + /** @var bool|null */ + protected $bot = null; + /** @var bool */ + protected $discoverable; + /** @var bool */ + protected $group; + /** @var string|null (Datetime) */ protected $created_at; - /** @var int */ - protected $followers_count; - /** @var int */ - protected $following_count; - /** @var int */ - protected $statuses_count; /** @var string */ protected $note; /** @var string (URL)*/ @@ -47,63 +67,76 @@ class Account extends BaseEntity protected $header; /** @var string (URL) */ protected $header_static; + /** @var int */ + protected $followers_count; + /** @var int */ + protected $following_count; + /** @var int */ + protected $statuses_count; + /** @var string|null (Datetime) */ + protected $last_status_at = null; /** @var Emoji[] */ protected $emojis; /** @var Account|null */ protected $moved = null; /** @var Field[]|null */ protected $fields = null; - /** @var bool|null */ - protected $bot = null; - /** @var bool */ - protected $group; - /** @var bool */ - protected $discoverable; - /** @var string|null (Datetime) */ - protected $last_status_at = null; /** * Creates an account record from a public contact record. Expects all contact table fields to be set. * * @param BaseURL $baseUrl - * @param array $publicContact Full contact table record with uid = 0 - * @param array $apcontact Optional full apcontact table record - * @param array $userContact Optional full contact table record with uid != 0 + * @param array $account entry of "account-user-view" + * @param Fields $fields Profile fields * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(BaseURL $baseUrl, array $publicContact, Fields $fields, array $apcontact = [], array $userContact = []) + public function __construct(BaseURL $baseUrl, array $account, Fields $fields) { - $this->id = $publicContact['id']; - $this->username = $publicContact['nick']; + $this->id = (string)$account['pid']; + $this->username = $account['nick']; $this->acct = - strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ? - $publicContact['nick'] : - $publicContact['addr']; - $this->display_name = $publicContact['name']; - $this->locked = !empty($apcontact['manually-approve']); - $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM); - $this->followers_count = $apcontact['followers_count'] ?? 0; - $this->following_count = $apcontact['following_count'] ?? 0; - $this->statuses_count = $apcontact['statuses_count'] ?? 0; - $this->note = BBCode::convert($publicContact['about'], false); - $this->url = $publicContact['url']; - $this->avatar = $userContact['avatar'] ?? $publicContact['avatar']; - $this->avatar_static = $userContact['avatar'] ?? $publicContact['avatar']; - // No header picture in Friendica - $this->header = ''; - $this->header_static = ''; + strpos($account['url'], $baseUrl . '/') === 0 ? + $account['nick'] : + $account['addr']; + $this->display_name = $account['name']; + $this->locked = (bool)$account['manually-approve']; + $this->bot = ($account['contact-type'] == Contact::TYPE_NEWS); + $this->discoverable = !$account['unsearchable']; + $this->group = ($account['contact-type'] == Contact::TYPE_COMMUNITY); + + $this->created_at = DateTimeFormat::utc($account['created'] ?: DBA::NULL_DATETIME, DateTimeFormat::JSON); + + $this->note = BBCode::convertForUriId($account['uri-id'], $account['about'], BBCode::EXTERNAL); + $this->url = $account['url']; + $this->avatar = Contact::getAvatarUrlForId($account['id'] ?? 0 ?: $account['pid'], Proxy::SIZE_SMALL, $account['updated'], $account['guid'] ?? ''); + $this->avatar_static = Contact::getAvatarUrlForId($account['id'] ?? 0 ?: $account['pid'], Proxy::SIZE_SMALL, $account['updated'], $account['guid'] ?? '', true); + $this->header = Contact::getHeaderUrlForId($account['id'] ?? 0 ?: $account['pid'], '', $account['updated'], $account['guid'] ?? ''); + $this->header_static = Contact::getHeaderUrlForId($account['id'] ?? 0 ?: $account['pid'], '', $account['updated'], $account['guid'] ?? '', true); + $this->followers_count = $account['ap-followers_count'] ?? $account['diaspora-interacted_count'] ?? 0; + $this->following_count = $account['ap-following_count'] ?? $account['diaspora-interacting_count'] ?? 0; + $this->statuses_count = $account['ap-statuses_count'] ?? $account['diaspora-post_count'] ?? 0; + + $lastItem = $account['last-item'] ?: DBA::NULL_DATETIME; + $this->last_status_at = $lastItem != DBA::NULL_DATETIME ? DateTimeFormat::utc($lastItem, 'Y-m-d') : null; + // No custom emojis per account in Friendica $this->emojis = []; - // No metadata fields in Friendica $this->fields = $fields->getArrayCopy(); - $this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS); - $this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY); - $this->discoverable = !$publicContact['unsearchable']; + } + + /** + * Returns the current entity as an array + * + * @return array + */ + public function toArray(): array + { + $account = parent::toArray(); - $publicContactLastItem = $publicContact['last-item'] ?: DBA::NULL_DATETIME; - $userContactLastItem = $userContact['last-item'] ?? DBA::NULL_DATETIME; + if (empty($account['moved'])) { + unset($account['moved']); + } - $lastItem = $userContactLastItem > $publicContactLastItem ? $userContactLastItem : $publicContactLastItem; - $this->last_status_at = $lastItem != DBA::NULL_DATETIME ? DateTimeFormat::utc($lastItem, DateTimeFormat::ATOM) : null; + return $account; } }