]> git.mxchange.org Git - friendica.git/commitdiff
Fix local avatar, improve speed for fetching cached photos
authorMichael <heluecht@pirati.ca>
Tue, 10 May 2022 18:18:24 +0000 (18:18 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 10 May 2022 18:18:24 +0000 (18:18 +0000)
src/Content/Conversation.php
src/Content/Item.php
src/Model/Contact.php
src/Module/Photo.php
src/Object/Post.php

index 89d9ca4c1b712e59de059595a3e8ce6b662bd30e..04cdab4785e50b0e5efefbdddb322fe8b015e963 100644 (file)
@@ -660,27 +660,6 @@ class Conversation
                                                $pinned = '';
                                        }
 
-                                       if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
-                                               $owner_avatar  = $author_avatar  = $item['contact-id'];
-                                               $owner_updated = $author_updated = '';
-                                               $owner_thumb   = $author_thumb   = $item['contact-avatar'];
-                                       } else {
-                                               $owner_avatar   = $item['owner-id'];
-                                               $owner_updated  = $item['owner-updated'];
-                                               $owner_thumb    = $item['owner-avatar'];
-                                               $author_avatar  = $item['author-id'];
-                                               $author_updated = $item['author-updated'];
-                                               $author_thumb   = $item['author-avatar'];
-                                       }
-
-                                       if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
-                                               $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
-                                       }
-                       
-                                       if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
-                                               $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
-                                       }
-
                                        $tmp_item = [
                                                'template'             => $tpl,
                                                'id'                   => ($preview ? 'P0' : $item['id']),
@@ -698,7 +677,7 @@ class Conversation
                                                'name'                 => $profile_name,
                                                'sparkle'              => $sparkle,
                                                'lock'                 => false,
-                                               'thumb'                => $this->baseURL->remove($author_thumb),
+                                               'thumb'                => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
                                                'title'                => $title,
                                                'body_html'            => $body_html,
                                                'tags'                 => $tags['tags'],
@@ -719,7 +698,7 @@ class Conversation
                                                'indent'               => '',
                                                'owner_name'           => '',
                                                'owner_url'            => '',
-                                               'owner_photo'          => $this->baseURL->remove($owner_thumb),
+                                               'owner_photo'          => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
                                                'plink'                => ItemModel::getPlink($item),
                                                'edpost'               => false,
                                                'pinned'               => $pinned,
index d36112865127e737a952c001c1eb9dac82db6f91..240de4c741cba9f63a7a5dddbda42e4077a2c474 100644 (file)
@@ -26,15 +26,16 @@ use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item as ModelItem;
+use Friendica\Model\Photo;
 use Friendica\Model\Tag;
 use Friendica\Model\Post;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Profiler;
+use Friendica\Util\Proxy;
 use Friendica\Util\XML;
 
 /**
@@ -564,4 +565,43 @@ class Item
                }
                return $item;
        }
+
+       public function getAuthorAvatar(array $item): string
+       {
+               if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
+                       $author_avatar  = $item['contact-id'];
+                       $author_updated = '';
+                       $author_thumb   = $item['contact-avatar'];
+               } else {
+                       $author_avatar  = $item['author-id'];
+                       $author_updated = $item['author-updated'];
+                       $author_thumb   = $item['author-avatar'];
+               }
+
+
+               if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
+                       $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
+               }
+
+               return $author_thumb;
+       }
+
+       public function getOwnerAvatar(array $item): string
+       {
+               if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
+                       $owner_avatar  = $item['contact-id'];
+                       $owner_updated = '';
+                       $owner_thumb   = $item['contact-avatar'];
+               } else {
+                       $owner_avatar   = $item['owner-id'];
+                       $owner_updated  = $item['owner-updated'];
+                       $owner_thumb    = $item['owner-avatar'];
+               }
+
+               if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
+                       $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
+               }
+
+               return $owner_thumb;
+       }
 }
index 6a982869944de165d48124dc962040f7131e0291..b0ccfd40bfa6a2cf7cec8cfe9f00ec05320924c7 100644 (file)
@@ -1700,6 +1700,10 @@ class Contact
                        }
                }
 
+               if (Network::isLocalLink($contact['url']) && !empty($contact['avatar'])) {
+                       return $contact;
+               }
+
                /// add the default avatars if the fields aren't filled
                if (isset($contact['photo']) && empty($contact['photo'])) {
                        $contact['photo'] = self::getDefaultAvatar($contact, Proxy::SIZE_SMALL);
index 73bd154c5659a773030af0735e19390c6cb6d8f3..f721b1cea927712b561777e8a21c53b337f3764c 100644 (file)
@@ -304,10 +304,12 @@ class Photo extends BaseModule
                                                $photo = MPhoto::selectFirst([], ['resource-id' => $resourceid], ['order' => ['scale']]);
                                                if (!empty($photo)) {
                                                        return $photo;
+                                               } else {
+                                                       $url = $contact['avatar'];
                                                }
+                                       } else {
+                                               $url = $contact['photo'];
                                        }
-                                       // We continue with the avatar link when the photo link is invalid
-                                       $url = $contact['avatar'];
                                } elseif (!empty($contact['avatar'])) {
                                        $url = $contact['avatar'];
                                }
@@ -340,6 +342,7 @@ class Photo extends BaseModule
                                        }
                                }
                                if (empty($mimetext)) {
+                                       Logger::info('Blubb');
                                        if ($customsize <= Proxy::PIXEL_MICRO) {
                                                $url = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO);
                                        } elseif ($customsize <= Proxy::PIXEL_THUMB) {
index 3c01028292d0cd2c2ecabf95c2290bf6634dd39a..3f4b2760b59527a23cef9c76f508932fee0f82b3 100644 (file)
@@ -451,27 +451,6 @@ class Post
                        $browsershare = null;
                }
 
-               if (in_array($item['network'], [Protocol::FEED, Protocol::MAIL])) {
-                       $owner_avatar  = $author_avatar  = $item['contact-id'];
-                       $owner_updated = $author_updated = '';
-                       $owner_thumb   = $author_thumb   = $item['contact-avatar'];
-               } else {
-                       $owner_avatar   = $item['owner-id'];
-                       $owner_updated  = $item['owner-updated'];
-                       $owner_thumb    = $item['owner-avatar'];
-                       $author_avatar  = $item['author-id'];
-                       $author_updated = $item['author-updated'];
-                       $author_thumb   = $item['author-avatar'];
-               }
-
-               if (empty($owner_thumb) || Photo::isPhotoURI($owner_thumb)) {
-                       $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
-               }
-
-               if (empty($author_thumb) || Photo::isPhotoURI($author_thumb)) {
-                       $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
-               }
-
                $tmp_item = [
                        'template'        => $this->getTemplate(),
                        'type'            => implode("", array_slice(explode("/", $item['verb']), -1)),
@@ -503,7 +482,7 @@ class Post
                        'profile_url'     => $profile_link,
                        'name'            => $profile_name,
                        'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken),
-                       'thumb'           => DI::baseUrl()->remove($author_thumb),
+                       'thumb'           => DI::baseUrl()->remove(DI::contentItem()->getAuthorAvatar($item)),
                        'osparkle'        => $osparkle,
                        'sparkle'         => $sparkle,
                        'title'           => $title,
@@ -520,7 +499,7 @@ class Post
                        'shiny'           => $shiny,
                        'owner_self'      => $item['author-link'] == Session::get('my_url'),
                        'owner_url'       => $this->getOwnerUrl(),
-                       'owner_photo'     => DI::baseUrl()->remove($owner_thumb),
+                       'owner_photo'     => DI::baseUrl()->remove(DI::contentItem()->getOwnerAvatar($item)),
                        'owner_name'      => $this->getOwnerName(),
                        'plink'           => Item::getPlink($item),
                        'browsershare'    => $browsershare,