3 namespace Friendica\Object\Api\Mastodon;
5 use Friendica\App\BaseURL;
6 use Friendica\BaseEntity;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Database\DBA;
9 use Friendica\Model\Contact;
10 use Friendica\Util\DateTimeFormat;
15 * @see https://docs.joinmastodon.org/entities/account
17 class Account extends BaseEntity
26 protected $display_name;
29 /** @var string (Datetime) */
30 protected $created_at;
32 protected $followers_count;
34 protected $following_count;
36 protected $statuses_count;
39 /** @var string (URL)*/
41 /** @var string (URL) */
43 /** @var string (URL) */
44 protected $avatar_static;
45 /** @var string (URL) */
47 /** @var string (URL) */
48 protected $header_static;
51 /** @var Account|null */
52 protected $moved = null;
53 /** @var Field[]|null */
54 protected $fields = null;
56 protected $bot = null;
60 protected $discoverable;
61 /** @var string|null (Datetime) */
62 protected $last_status_at = null;
65 * Creates an account record from a public contact record. Expects all contact table fields to be set.
67 * @param BaseURL $baseUrl
68 * @param array $publicContact Full contact table record with uid = 0
69 * @param array $apcontact Optional full apcontact table record
70 * @param array $userContact Optional full contact table record with uid != 0
71 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
73 public function __construct(BaseURL $baseUrl, array $publicContact, array $apcontact = [], array $userContact = [])
75 $this->id = $publicContact['id'];
76 $this->username = $publicContact['nick'];
78 strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ?
79 $publicContact['nick'] :
80 $publicContact['addr'];
81 $this->display_name = $publicContact['name'];
82 $this->locked = !empty($apcontact['manually-approve']);
83 $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM);
84 $this->followers_count = $apcontact['followers_count'] ?? 0;
85 $this->following_count = $apcontact['following_count'] ?? 0;
86 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
87 $this->note = BBCode::convert($publicContact['about'], false);
88 $this->url = $publicContact['url'];
89 $this->avatar = $userContact['avatar'] ?? $publicContact['avatar'];
90 $this->avatar_static = $userContact['avatar'] ?? $publicContact['avatar'];
91 // No header picture in Friendica
93 $this->header_static = '';
94 // No custom emojis per account in Friendica
96 // No metadata fields in Friendica
98 $this->bot = ($publicContact['contact-type'] == Contact::TYPE_NEWS);
99 $this->group = ($publicContact['contact-type'] == Contact::TYPE_COMMUNITY);
100 $this->discoverable = !$publicContact['unsearchable'];
102 $publicContactLastItem = $publicContact['last-item'] ?: DBA::NULL_DATETIME;
103 $userContactLastItem = $userContact['last-item'] ?? DBA::NULL_DATETIME;
105 $lastItem = $userContactLastItem > $publicContactLastItem ? $userContactLastItem : $publicContactLastItem;
106 $this->last_status_at = $lastItem != DBA::NULL_DATETIME ? DateTimeFormat::utc($lastItem, DateTimeFormat::ATOM) : null;