From ed4a18f079ff8b92e111df477cd26a49ed22e18e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 25 Jun 2021 17:03:35 +0000 Subject: [PATCH] Function to return the avatar and header path for a given contact id --- src/Model/Contact.php | 22 ++++++++++++++++++++++ src/Object/Api/Mastodon/Account.php | 5 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 30fa41307d..fad1db3473 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1662,6 +1662,28 @@ class Contact return DI::baseUrl() . $default; } + /** + * Get avatar link for given contact id + * + * @param integer $cid contact id + * @return string avatar link + */ + public static function getAvatarForContact(int $cid):string + { + return DI::baseUrl() . '/photo/contact/'. $cid; + } + + /** + * Get header link for given contact id + * + * @param integer $cid contact id + * @return string header link + */ + public static function getHeaderForContact(int $cid):string + { + return DI::baseUrl() . '/photo/header/'. $cid; + } + /** * Updates the avatar links in a contact only if needed * diff --git a/src/Object/Api/Mastodon/Account.php b/src/Object/Api/Mastodon/Account.php index 5104fde1f1..b34af79512 100644 --- a/src/Object/Api/Mastodon/Account.php +++ b/src/Object/Api/Mastodon/Account.php @@ -26,7 +26,6 @@ use Friendica\BaseDataTransferObject; use Friendica\Collection\Api\Mastodon\Fields; use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; -use Friendica\DI; use Friendica\Model\Contact; use Friendica\Util\DateTimeFormat; @@ -113,9 +112,9 @@ class Account extends BaseDataTransferObject $this->note = BBCode::convert($publicContact['about'], false); $this->url = $publicContact['url']; - $this->avatar = (($userContact['photo'] ?? '') ?: $publicContact['photo']) ?: DI::baseUrl() . '/photo/contact/'. (($userContact['id'] ?? 0) ?: $publicContact['id']); + $this->avatar = (($userContact['photo'] ?? '') ?: $publicContact['photo']) ?: Contact::getAvatarForContact(($userContact['id'] ?? 0) ?: $publicContact['id']); $this->avatar_static = $this->avatar; - $this->header = DI::baseUrl() . '/photo/header/'. (($userContact['id'] ?? 0) ?: $publicContact['id']); + $this->header = Contact::getHeaderForContact(($userContact['id'] ?? 0) ?: $publicContact['id']); $this->header_static = $this->header; $this->followers_count = $apcontact['followers_count'] ?? 0; $this->following_count = $apcontact['following_count'] ?? 0;