3 namespace Friendica\Object\Api\Mastodon;
5 use Friendica\App\BaseURL;
6 use Friendica\BaseEntity;
7 use Friendica\Collection\Api\Mastodon\Fields;
8 use Friendica\Content\Text\BBCode;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Util\DateTimeFormat;
16 * @see https://docs.joinmastodon.org/entities/account
18 class Account extends BaseEntity
27 protected $display_name;
30 /** @var string (Datetime) */
31 protected $created_at;
33 protected $followers_count;
35 protected $following_count;
37 protected $statuses_count;
40 /** @var string (URL)*/
42 /** @var string (URL) */
44 /** @var string (URL) */
45 protected $avatar_static;
46 /** @var string (URL) */
48 /** @var string (URL) */
49 protected $header_static;
52 /** @var Account|null */
53 protected $moved = null;
54 /** @var Field[]|null */
55 protected $fields = null;
57 protected $bot = null;
61 protected $discoverable;
62 /** @var string|null (Datetime) */
63 protected $last_status_at = null;
66 * Creates an account record from a public contact record. Expects all contact table fields to be set.
68 * @param BaseURL $baseUrl
69 * @param array $publicContact Full contact table record with uid = 0
70 * @param array $apcontact Optional full apcontact table record
71 * @param array $userContact Optional full contact table record with uid != 0
72 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
74 public function __construct(BaseURL $baseUrl, array $publicContact, Fields $fields, array $apcontact = [], array $userContact = [])
76 $this->id = $publicContact['id'];
77 $this->username = $publicContact['nick'];
79 strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ?
80 $publicContact['nick'] :
81 $publicContact['addr'];
82 $this->display_name = $publicContact['name'];
83 $this->locked = !empty($apcontact['manually-approve']);
84 $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM);
85 $this->followers_count = $apcontact['followers_count'] ?? 0;
86 $this->following_count = $apcontact['following_count'] ?? 0;
87 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
88 $this->note = BBCode::convert($publicContact['about'], false);
89 $this->url = $publicContact['url'];
90 $this->avatar = $userContact['avatar'] ?? $publicContact['avatar'];
91 $this->avatar_static = $userContact['avatar'] ?? $publicContact['avatar'];
92 // No header picture in Friendica
94 $this->header_static = '';
95 // No custom emojis per account in Friendica
97 // No metadata fields in Friendica
98 $this->fields = $fields->getArrayCopy();
99 $this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
100 $this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
101 $this->discoverable = !$publicContact['unsearchable'];
103 $publicContactLastItem = $publicContact['last-item'] ?: DBA::NULL_DATETIME;
104 $userContactLastItem = $userContact['last-item'] ?? DBA::NULL_DATETIME;
106 $lastItem = $userContactLastItem > $publicContactLastItem ? $userContactLastItem : $publicContactLastItem;
107 $this->last_status_at = $lastItem != DBA::NULL_DATETIME ? DateTimeFormat::utc($lastItem, DateTimeFormat::ATOM) : null;