]> git.mxchange.org Git - friendica.git/commitdiff
Use new function to check for a local avatar cache file
authorMichael <heluecht@pirati.ca>
Sun, 8 May 2022 10:32:29 +0000 (10:32 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 8 May 2022 10:32:29 +0000 (10:32 +0000)
src/Content/Conversation.php
src/Model/Contact.php
src/Object/Post.php

index 4ad1890a267ecc60e40d6276bb18f4cd32116aa3..fdb1f51d89904cfc72fcb83bd91995b62797be33 100644 (file)
@@ -662,11 +662,22 @@ class Conversation
                                        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 (!Contact::isAvatarFile($owner_thumb)) {
+                                               $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
+                                       }
+
+                                       if (!Contact::isAvatarFile($author_thumb)) {
+                                               $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
                                        }
 
                                        $tmp_item = [
@@ -686,7 +697,7 @@ class Conversation
                                                'name'                 => $profile_name,
                                                'sparkle'              => $sparkle,
                                                'lock'                 => false,
-                                               'thumb'                => $this->baseURL->remove(Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated)),
+                                               'thumb'                => $this->baseURL->remove($author_thumb),
                                                'title'                => $title,
                                                'body_html'            => $body_html,
                                                'tags'                 => $tags['tags'],
@@ -707,7 +718,7 @@ class Conversation
                                                'indent'               => '',
                                                'owner_name'           => '',
                                                'owner_url'            => '',
-                                               'owner_photo'          => $this->baseURL->remove(Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated)),
+                                               'owner_photo'          => $this->baseURL->remove($owner_thumb),
                                                'plink'                => ItemModel::getPlink($item),
                                                'edpost'               => false,
                                                'pinned'               => $pinned,
index c00c6b2e8aa17265c86e707adcfe928570f118bf..f16a2e9c8aa46493a0e293ac1dffa55cc076a93b 100644 (file)
@@ -1587,7 +1587,7 @@ class Contact
                                self::updateAvatar($cid, $contact['avatar'], true);
                                return;
                        }
-               } elseif (!self::getAvatarFile($contact['photo']) || !self::getAvatarFile($contact['thumb']) || !self::getAvatarFile($contact['micro'])) {
+               } elseif (!self::isAvatarFile($contact['photo']) || !self::isAvatarFile($contact['thumb']) || !self::isAvatarFile($contact['micro'])) {
                        Logger::info('Removing/replacing avatar cache', ['id' => $cid, 'contact' => $contact]);
                        self::updateAvatar($cid, $contact['avatar'], true);
                        return;
@@ -1611,17 +1611,17 @@ class Contact
                if (DI::config()->get('system', 'avatar_cache')) {
                        switch ($size) {
                                case Proxy::SIZE_MICRO:
-                                       if (self::getAvatarFile($contact['micro'])) {
+                                       if (self::isAvatarFile($contact['micro'])) {
                                                return $contact['micro'];
                                        }
                                        break;
                                case Proxy::SIZE_THUMB:
-                                       if (self::getAvatarFile($contact['thumb'])) {
+                                       if (self::isAvatarFile($contact['thumb'])) {
                                                return $contact['thumb'];
                                        }
                                        break;
                                case Proxy::SIZE_SMALL:
-                                       if (self::getAvatarFile($contact['photo'])) {
+                                       if (self::isAvatarFile($contact['photo'])) {
                                                return $contact['photo'];
                                        }
                                        break;
@@ -2091,7 +2091,7 @@ class Contact
                        self::deleteAvatarCache($contact['thumb']);
                        self::deleteAvatarCache($contact['micro']);
                        Logger::debug('Avatar file name changed', ['new' => $avatar, 'old' => $contact['avatar']]);
-               } elseif (self::getAvatarFile($contact['photo']) && self::getAvatarFile($contact['thumb']) && self::getAvatarFile($contact['micro'])) {
+               } elseif (self::isAvatarFile($contact['photo']) && self::isAvatarFile($contact['thumb']) && self::isAvatarFile($contact['micro'])) {
                        $fields['photo'] = $contact['photo'];
                        $fields['thumb'] = $contact['thumb'];
                        $fields['micro'] = $contact['micro'];
@@ -2181,6 +2181,17 @@ class Contact
                return $filename;
        }
 
+       /**
+        * Check if the avatar cache file is locally stored
+        *
+        * @param string $avatar
+        * @return boolean
+        */
+       public static function isAvatarFile(string $avatar): bool
+       {
+               return !empty(self::getAvatarFile($avatar));
+       }
+
        /**
         * Delete a locally cached avatar picture
         *
index a949c24aa704ffae28e5eed4ca44ff6fdd286ffc..0a7bea91bdd0457517d93d3d0bbccc4f46d5cc21 100644 (file)
@@ -123,8 +123,8 @@ class Post
        /**
         * Fetch the privacy of the post
         *
-        * @param array $item 
-        * @return string 
+        * @param array $item
+        * @return string
         */
        private function fetchPrivacy(array $item):string
        {
@@ -453,11 +453,22 @@ class Post
                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 (!Contact::isAvatarFile($owner_thumb)) {
+                       $owner_thumb = Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated);
+               }
+
+               if (!Contact::isAvatarFile($author_thumb)) {
+                       $author_thumb = Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated);
                }
 
                $tmp_item = [
@@ -491,7 +502,7 @@ class Post
                        'profile_url'     => $profile_link,
                        'name'            => $profile_name,
                        'item_photo_menu_html' => DI::contentItem()->photoMenu($item, $formSecurityToken),
-                       'thumb'           => DI::baseUrl()->remove(Contact::getAvatarUrlForId($author_avatar, Proxy::SIZE_THUMB, $author_updated)),
+                       'thumb'           => DI::baseUrl()->remove($author_thumb),
                        'osparkle'        => $osparkle,
                        'sparkle'         => $sparkle,
                        'title'           => $title,
@@ -508,7 +519,7 @@ class Post
                        'shiny'           => $shiny,
                        'owner_self'      => $item['author-link'] == Session::get('my_url'),
                        'owner_url'       => $this->getOwnerUrl(),
-                       'owner_photo'     => DI::baseUrl()->remove(Contact::getAvatarUrlForId($owner_avatar, Proxy::SIZE_THUMB, $owner_updated)),
+                       'owner_photo'     => DI::baseUrl()->remove($owner_thumb),
                        'owner_name'      => $this->getOwnerName(),
                        'plink'           => Item::getPlink($item),
                        'browsershare'    => $browsershare,