Merge pull request #10432 from annando/avatar-path

Function to return the avatar and header path for a given contact id
This commit is contained in:
Hypolite Petovan 2021-06-25 14:37:24 -04:00 committed by GitHub
commit 2399353d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -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 getAvatarUrlForId(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 getHeaderUrlForId(int $cid):string
{
return DI::baseUrl() . '/photo/header/' . $cid;
}
/**
* Updates the avatar links in a contact only if needed
*

View file

@ -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::getAvatarUrlForId($userContact['id'] ?? 0 ?: $publicContact['id']);
$this->avatar_static = $this->avatar;
$this->header = DI::baseUrl() . '/photo/header/'. (($userContact['id'] ?? 0) ?: $publicContact['id']);
$this->header = Contact::getHeaderUrlForId($userContact['id'] ?? 0 ?: $publicContact['id']);
$this->header_static = $this->header;
$this->followers_count = $apcontact['followers_count'] ?? 0;
$this->following_count = $apcontact['following_count'] ?? 0;