X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=f35808f050c9843986cabf3be7f3f25d6bf0c1b7;hb=4f332e3b5202f39809a14aaf5df2bbca2417af11;hp=e928df7f6323570bd399d273c466acefab4316a5;hpb=e0e2e45b91f793c58b8fb06240cca0e6c7f85ea4;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index e928df7f63..f35808f050 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1,6 +1,6 @@ truncateFieldsForTable('contact', $fields); - $ret = DBA::update('contact', $fields, $condition, $old_fields); - // Apply changes to the "user-contact" table on dedicated fields Contact\User::updateByContactUpdate($fields, $condition); - return $ret; + $fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields); + return DBA::update('contact', $fields, $condition, $old_fields); } /** @@ -362,7 +362,11 @@ class Contact // Update the contact in the background if needed if ($background_update && !self::isLocal($url) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + try { + UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['contact' => $contact]); + } } // Remove the internal fields @@ -566,7 +570,7 @@ class Contact { if (!parse_url($url, PHP_URL_SCHEME)) { $addr_parts = explode('@', $url); - return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHostname()); + return (count($addr_parts) == 2) && ($addr_parts[1] == DI::baseUrl()->getHost()); } return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl()); @@ -624,7 +628,7 @@ class Contact public static function getPublicAndUserContactID(int $cid, int $uid): array { // We have to use the legacy function as long as the post update hasn't finished - if (DI::config()->get('system', 'post_update_version') < 1427) { + if (DI::keyValue()->get('post_update_version') < 1427) { return self::legacyGetPublicAndUserContactID($cid, $uid); } @@ -1276,7 +1280,11 @@ class Contact $background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true; if ($background_update && !self::isLocal($url) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + try { + UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['contact' => $contact]); + } } if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { @@ -1600,7 +1608,7 @@ class Contact } } - $o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId()); + $o .= DI::conversation()->create($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_commented', DI::userSession()->getLocalUserId()); } else { $fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']); $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params)); @@ -1615,7 +1623,7 @@ class Contact } } - $o .= DI::conversation()->create($items, 'contact-posts', $update); + $o .= DI::conversation()->create($items, ConversationContent::MODE_CONTACT_POSTS, $update); } if (!$update) { @@ -2196,20 +2204,38 @@ class Contact return; } + if (!Network::isValidHttpUrl($avatar)) { + Logger::warning('Invalid avatar', ['cid' => $cid, 'avatar' => $avatar]); + $avatar = ''; + } + $uid = $contact['uid']; // Only update the cached photo links of public contacts when they already are cached if (($uid == 0) && !$force && empty($contact['thumb']) && empty($contact['micro']) && !$create_cache) { if (($contact['avatar'] != $avatar) || empty($contact['blurhash'])) { $update_fields = ['avatar' => $avatar]; - $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); - - $img_str = $fetchResult->getBody(); - if (!empty($img_str)) { - $image = new Image($img_str, Images::getMimeTypeByData($img_str)); - if ($image->isValid()) { - $update_fields['blurhash'] = $image->getBlurHash(); + if (!Network::isLocalLink($avatar)) { + try { + $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); + + $img_str = $fetchResult->getBody(); + if (!empty($img_str)) { + $image = new Image($img_str, Images::getMimeTypeByData($img_str)); + if ($image->isValid()) { + $update_fields['blurhash'] = $image->getBlurHash(); + } else { + return; + } + } + } catch (\Exception $exception) { + Logger::notice('Error fetching avatar', ['avatar' => $avatar, 'exception' => $exception]); + return; } + } elseif (!empty($contact['blurhash'])) { + $update_fields['blurhash'] = null; + } else { + return; } self::update($update_fields, ['id' => $cid]); @@ -2242,7 +2268,9 @@ class Contact } if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) || $cache_avatar) { - Avatar::deleteCache($contact); + if (Avatar::deleteCache($contact)) { + $force = true; + } if ($default_avatar && Proxy::isLocalImage($avatar)) { $fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(), @@ -2953,12 +2981,12 @@ class Contact } if (($network != '') && ($ret['network'] != $network)) { - Logger::notice('Expected network ' . $network . ' does not match actual network ' . $ret['network']); + $result['message'] = DI::l10n()->t('Expected network %s does not match actual network %s', $network, $ret['network']); return $result; } // check if we already have a contact - $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url'])]; + $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'deleted' => false]; $contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition); $protocol = self::getProtocol($ret['url'], $ret['network']); @@ -3078,7 +3106,11 @@ class Contact if ($probed) { self::updateFromProbeArray($contact_id, $ret); } else { - Worker::add(Worker::PRIORITY_HIGH, 'UpdateContact', $contact_id); + try { + UpdateContact::add(Worker::PRIORITY_HIGH, $contact['id']); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['contact' => $contact]); + } } $result['success'] = Protocol::follow($uid, $contact, $protocol); @@ -3277,7 +3309,7 @@ class Contact if ($contact['rel'] == self::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) { self::remove($contact['id']); } else { - self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]); + self::update(['rel' => self::FOLLOWER, 'pending' => false], ['id' => $contact['id']]); } Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $contact['uid']); @@ -3549,8 +3581,12 @@ class Contact Worker::add(Worker::PRIORITY_LOW, 'AddContact', 0, $url); ++$added; } elseif (!empty($contact['network']) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); - ++$updated; + try { + UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']); + ++$updated; + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['contact' => $contact]); + } } else { ++$unchanged; }