]> git.mxchange.org Git - friendica.git/commitdiff
Ensure that cached avatar fields are set
authorMichael <heluecht@pirati.ca>
Mon, 27 Jul 2020 10:11:12 +0000 (10:11 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 27 Jul 2020 10:11:12 +0000 (10:11 +0000)
src/Model/Contact.php
src/Module/Contact.php

index 1cf8c742374bbca4e3b85f02f3bdea99e6176833..4f8cb84db7cf692de7528b93114a6a9b25871e2c 100644 (file)
@@ -1787,6 +1787,54 @@ class Contact
                self::updateAvatar($cid, $contact['avatar'], true);
        }
 
+       /**
+        * Check the given contact array for avatar cache fields
+        *
+        * @param array $contact
+        * @return array contact array with avatar cache fields
+        */
+       public static function checkAvatarCacheArray(array $contact)
+       {
+               $update = false;
+               $contact_fields = [];
+               $fields = ['photo', 'thumb', 'micro'];
+               foreach ($fields as $field) {
+                       if (isset($contact[$field])) {
+                               $contact_fields[] = $field;
+                       }
+                       if (isset($contact[$field]) && empty($contact[$field])) {
+                               $update = true;
+                       }
+               }
+
+               if (!$update) {
+                       return $contact;
+               }
+
+               if (!empty($contact['id']) && !empty($contact['avatar'])) {
+                       self::updateAvatar($contact['id'], $contact['avatar'], true);
+
+                       $new_contact = self::getById($contact['id'], $contact_fields);
+                       if (DBA::isResult($new_contact)) {
+                               // We only update the cache fields
+                               $contact = array_merge($contact, $new_contact);
+                       }
+               }
+
+               /// add the default avatars if the fields aren't filled
+               if (isset($contact['photo']) && empty($contact['photo'])) {
+                       $contact['photo'] = DI::baseUrl() . '/images/person-300.jpg';
+               }
+               if (isset($contact['thumb']) && empty($contact['thumb'])) {
+                       $contact['thumb'] = DI::baseUrl() . '/images/person-80.jpg';
+               }
+               if (isset($contact['micro']) && empty($contact['micro'])) {
+                       $contact['micro'] = DI::baseUrl() . '/images/person-48.jpg';
+               }
+
+               return $contact;
+       }
+
        /**
         * Updates the avatar links in a contact only if needed
         *
index 096f69330217233fbd706ba558bb7f18a068ed04..e9f00a1b653d6086e0a46b471324ac72a4f795b8 100644 (file)
@@ -36,6 +36,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\Contact as ModelContact;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -278,6 +279,8 @@ class Contact extends BaseModule
                        if ($contact['network'] == Protocol::PHANTOM) {
                                $contact = false;
                        }
+
+                       $contact = ModelContact::checkAvatarCacheArray($contact);
                }
 
                if (DBA::isResult($contact)) {