Merge pull request #11200 from annando/issue-11034

Issue 11034: Use the profile photo for local users
This commit is contained in:
Hypolite Petovan 2022-02-02 05:13:03 -05:00 committed by GitHub
commit 4ad528a15c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 23 deletions

View file

@ -1913,7 +1913,14 @@ class Contact
$avatar = self::getDefaultAvatar($contact, Proxy::SIZE_SMALL); $avatar = self::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
} }
if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || DI::config()->get('system', 'cache_contact_avatar')) { $cache_avatar = DI::config()->get('system', 'cache_contact_avatar');
// Local contact avatars don't need to be cached
if ($cache_avatar && Network::isLocalLink($contact['url'])) {
$cache_avatar = !DBA::exists('contact', ['nurl' => $contact['nurl'], 'self' => true]);
}
if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || $cache_avatar) {
if ($default_avatar && Proxy::isLocalImage($avatar)) { if ($default_avatar && Proxy::isLocalImage($avatar)) {
$fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(), $fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(),
'photo' => $avatar, 'photo' => $avatar,

View file

@ -265,10 +265,29 @@ class Photo extends BaseModule
return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype']); return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype']);
case "contact": case "contact":
$contact = Contact::getById($id, ['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr']); $contact = Contact::getById($id, ['uid', 'url', 'nurl', 'avatar', 'photo', 'xmpp', 'addr']);
if (empty($contact)) { if (empty($contact)) {
return false; return false;
} }
// For local users directly use the photo record that is marked as the profile
if (Network::isLocalLink($contact['url'])) {
$contact = Contact::selectFirst(['uid', 'url', 'avatar', 'photo', 'xmpp', 'addr'], ['nurl' => $contact['nurl'], 'self' => true]);
if (!empty($contact)) {
if ($customsize <= Proxy::PIXEL_MICRO) {
$scale = 6;
} elseif ($customsize <= Proxy::PIXEL_THUMB) {
$scale = 5;
} else {
$scale = 4;
}
$photo = MPhoto::selectFirst([], ["scale" => $scale, "uid" => $contact['uid'], "profile" => 1]);
if (!empty($photo)) {
return $photo;
}
}
}
If (($contact['uid'] != 0) && empty($contact['photo']) && empty($contact['avatar'])) { If (($contact['uid'] != 0) && empty($contact['photo']) && empty($contact['avatar'])) {
$contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']); $contact = Contact::getByURL($contact['url'], false, ['avatar', 'photo', 'xmpp', 'addr']);
} }

View file

@ -5,11 +5,8 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $profile.picdate}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div>
{{else}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}" alt="{{$profile.name}}"></a></div> <div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}" alt="{{$profile.name}}"></a></div>
{{/if}}
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}
{{if $profile.network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$profile.network_link nofilter}}</dd></dl>{{/if}} {{if $profile.network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$profile.network_link nofilter}}</dd></dl>{{/if}}
{{if $location}} {{if $location}}

View file

@ -5,7 +5,7 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
<div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></div> <div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}" alt="{{$profile.name}}"></div>
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}

View file

@ -1,12 +1,7 @@
<div class="vcard h-card widget"> <div class="vcard h-card widget">
<div id="profile-photo-wrapper"> <div id="profile-photo-wrapper">
{{if $profile.picdate}}
<a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}" /></a>
{{else}}
<a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}" alt="{{$profile.name}}" /></a> <a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}" alt="{{$profile.name}}" /></a>
{{/if}}
<div class="tool visible-lg visible-md"> <div class="tool visible-lg visible-md">
{{if $profile.edit}} {{if $profile.edit}}
<div class="action"> <div class="action">
@ -21,11 +16,7 @@
<div id="vcard-short-info-wrapper" style="display: none;"> <div id="vcard-short-info-wrapper" style="display: none;">
<div id="vcard-short-info" class="media" style="display: none"> <div id="vcard-short-info" class="media" style="display: none">
<div id="vcard-short-photo-wrapper" class="pull-left"> <div id="vcard-short-photo-wrapper" class="pull-left">
{{if $profile.picdate}}
<img class="media-object" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a>
{{else}}
<img class="media-object" src="{{$profile.photo}}" alt="{{$profile.name}}"></a> <img class="media-object" src="{{$profile.photo}}" alt="{{$profile.name}}"></a>
{{/if}}
</div> </div>
<div id="vcard-short-desc" class="media-body"> <div id="vcard-short-desc" class="media-body">

View file

@ -17,7 +17,7 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
<div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}" /></div> <div id="profile-photo-wrapper"><img class="photo u-photo" width="175" height="175" src="{{$profile.photo}}" alt="{{$profile.name}}" /></div>
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}

View file

@ -11,11 +11,7 @@
{{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}} {{if $profile.addr}}<div class="p-addr">{{$profile.addr}}</div>{{/if}}
{{if $profile.picdate}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}?rev={{$profile.picdate}}" alt="{{$profile.name}}"></a></div>
{{else}}
<div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}" alt="{{$profile.name}}"></a></div> <div id="profile-photo-wrapper"><a href="{{$profile.url}}"><img class="photo u-photo" src="{{$profile.photo}}" alt="{{$profile.name}}"></a></div>
{{/if}}
{{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}} {{if $account_type}}<div class="account-type">{{$account_type}}</div>{{/if}}
{{if $profile.network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$profile.network_link nofilter}}</dd></dl>{{/if}} {{if $profile.network_link}}<dl class="network"><dt class="network-label">{{$network}}</dt><dd class="x-network">{{$profile.network_link nofilter}}</dd></dl>{{/if}}