Unified avatar paths

This commit is contained in:
Michael
2021-06-29 20:26:58 +00:00
parent 9edc75e29d
commit 19aef93560
7 changed files with 24 additions and 18 deletions
+4 -4
View File
@@ -1501,10 +1501,10 @@ class Contact
{
if (!empty($contact)) {
$contact = self::checkAvatarCacheByArray($contact, $no_update);
if (!empty($contact[$field])) {
return $contact[$field];
} elseif (!empty($contact['id'])) {
if (!empty($contact['id'])) {
return self::getAvatarUrlForId($contact['id'], $size, $contact['updated'] ?? '');
} elseif (!empty($contact[$field])) {
return $contact[$field];
} elseif (!empty($contact['avatar'])) {
$avatar = $contact['avatar'];
}
@@ -1713,7 +1713,7 @@ class Contact
$condition = ["`nurl` = ? AND ((`uid` = ? AND `network` IN (?, ?)) OR `uid` = ?)",
Strings::normaliseLink($url), $uid, Protocol::FEED, Protocol::MAIL, 0];
$contact = self::selectFirst(['id', 'updated'], $condition);
return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated']);
return self::getAvatarUrlForId($contact['id'] ?? 0, $size, $contact['updated'] ?? '');
}
/**
+2 -3
View File
@@ -26,6 +26,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\User;
@@ -80,10 +81,8 @@ class NoScrape extends BaseModule
$keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $keywords);
$keywords = explode(',', $keywords);
$contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $profile['uid']]);
$json_info['fn'] = $profile['name'];
$json_info['photo'] = $contactPhoto["photo"];
$json_info['photo'] = Contact::getAvatarUrlForUrl($profile['url'], $profile['uid']);
$json_info['tags'] = $keywords;
$json_info['language'] = $profile['language'];
+8
View File
@@ -191,6 +191,14 @@ class Photo extends BaseModule
$contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']);
}
if (!empty($contact['photo'])) {
// Fetch photo directly
$resourceid = MPhoto::ridFromURI($contact['photo']);
if (!empty($resourceid)) {
$photo = MPhoto::selectFirst([], ['resource-id' => $resourceid], ['order' => ['scale']]);
if (!empty($photo)) {
return $photo;
}
}
$url = $contact['photo'];
} elseif (!empty($contact['avatar'])) {
$url = $contact['avatar'];
+2 -1
View File
@@ -39,6 +39,7 @@ use Friendica\Model\User;
use Friendica\Protocol\Activity;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
@@ -459,7 +460,7 @@ class Post
'profile_url' => $profile_link,
'name' => $profile_name,
'item_photo_menu_html' => item_photo_menu($item),
'thumb' => DI::baseUrl()->remove($item['author-avatar']),
'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
'osparkle' => $osparkle,
'sparkle' => $sparkle,
'title' => $title,
+3 -3
View File
@@ -331,7 +331,7 @@ class Transmitter
return [];
}
$fields = ['name', 'url', 'location', 'about', 'avatar', 'photo'];
$fields = ['id', 'name', 'url', 'location', 'about', 'avatar', 'photo', 'updated'];
$contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($contact)) {
return [];
@@ -379,7 +379,7 @@ class Transmitter
'owner' => $contact['url'],
'publicKeyPem' => $user['pubkey']];
$data['endpoints'] = ['sharedInbox' => DI::baseUrl() . '/inbox'];
$data['icon'] = ['type' => 'Image', 'url' => $contact['photo']];
$data['icon'] = ['type' => 'Image', 'url' => Contact::getAvatarUrlForId($contact['id'], '', $contact['updated'])];
$resourceid = Photo::ridFromURI($contact['photo']);
if (!empty($resourceid)) {
@@ -390,7 +390,7 @@ class Transmitter
}
if (!empty($contact['header'])) {
$data['image'] = ['type' => 'Image', 'url' => $contact['header']];
$data['image'] = ['type' => 'Image', 'url' => Contact::getHeaderUrlForId($contact['id'], '', $contact['updated'])];
$resourceid = Photo::ridFromURI($contact['header']);
if (!empty($resourceid)) {