API: moved classes / unified user array creation

This commit is contained in:
Michael 2021-11-16 23:21:40 +00:00
parent 877b90f7f0
commit 6ea426178a
7 changed files with 61 additions and 189 deletions

View file

@ -24,6 +24,9 @@ namespace Friendica\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Model\Contact;
use Friendica\Util\Proxy;
/**
* @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
@ -79,6 +82,14 @@ class User extends BaseDataTransferObject
/** @var string */
protected $withheld_scope;
/**
* Missing fields:
*
* - profile_sidebar_fill_color
* - profile_link_color
* - profile_background_color
*/
/**
* @param array $publicContact Full contact table record with uid = 0
* @param array $apcontact Optional full apcontact table record
@ -89,9 +100,11 @@ class User extends BaseDataTransferObject
*/
public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
{
$uid = $userContact['uid'] ?? 0;
$this->id = (int)$publicContact['id'];
$this->id_str = (string) $publicContact['id'];
$this->name = $publicContact['name'];
$this->name = $publicContact['name'] ?: $publicContact['nick'];
$this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
$this->location = $publicContact['location'] ?:
ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
@ -106,14 +119,14 @@ class User extends BaseDataTransferObject
unset($this->entities);
}
$this->description = BBCode::toPlaintext($publicContact['about']);
$this->profile_image_url_https = $userContact['avatar'] ?? $publicContact['avatar'];
$this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
$this->protected = false;
$this->followers_count = $apcontact['followers_count'] ?? 0;
$this->friends_count = $apcontact['following_count'] ?? 0;
$this->listed_count = 0;
$this->created_at = api_date($publicContact['created']);
$this->favourites_count = 0;
$this->verified = false;
$this->verified = $uid != 0;
$this->statuses_count = $apcontact['statuses_count'] ?? 0;
$this->profile_banner_url = '';
$this->default_profile = false;
@ -127,9 +140,9 @@ class User extends BaseDataTransferObject
unset($this->withheld_scope);
// Deprecated
$this->profile_image_url = $userContact['avatar'] ?? $publicContact['avatar'];
$this->profile_image_url_profile_size = $publicContact['thumb'];
$this->profile_image_url_large = $publicContact['photo'];
$this->profile_image_url = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
$this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
$this->profile_image_url_large = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
$this->utc_offset = 0;
$this->time_zone = 'UTC';
$this->geo_enabled = false;
@ -137,17 +150,17 @@ class User extends BaseDataTransferObject
$this->contributors_enabled = false;
$this->is_translator = false;
$this->is_translation_enabled = false;
$this->following = false;
$this->following = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
$this->follow_request_sent = false;
$this->statusnet_blocking = false;
$this->notifications = false;
// Friendica-specific
$this->uid = (int)$userContact['uid'] ?? 0;
$this->cid = (int)$userContact['id'] ?? 0;
$this->uid = (int)$uid;
$this->cid = (int)($userContact['id'] ?? 0);
$this->pid = (int)$publicContact['id'];
$this->self = (boolean)$userContact['self'] ?? false;
$this->network = $publicContact['network'];
$this->self = (boolean)($userContact['self'] ?? false);
$this->network = $publicContact['network'] ?: Protocol::DFRN;
$this->statusnet_profile_url = $publicContact['url'];
}
}