X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=e847ce034666cf458ce7121363127af7f5d8eac1;hb=21f172c585aff8c606774a05fde1548ddff1667d;hp=7c83e035119faa0eb41f77a6bbc9512ffa5495c4;hpb=df69dc0edb4349f9249f45593a90d4286a7870b3;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 7c83e03511..e847ce0346 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1,6 +1,6 @@ get('system', 'update_active_contacts') ? $contact['local-data'] : true; + // Update the contact in the background if needed - if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + if ($background_update && !self::isLocal($url) && Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { + 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 @@ -606,7 +630,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); } @@ -729,7 +753,6 @@ class Contact 'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'], 'poll' => DI::baseUrl() . '/dfrn_poll/' . $user['nickname'], 'confirm' => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'], - 'poco' => DI::baseUrl() . '/poco/' . $user['nickname'], 'name-date' => DateTimeFormat::utcNow(), 'uri-date' => DateTimeFormat::utcNow(), 'avatar-date' => DateTimeFormat::utcNow(), @@ -811,7 +834,6 @@ class Contact 'notify' => DI::baseUrl() . '/dfrn_notify/' . $user['nickname'], 'poll' => DI::baseUrl() . '/dfrn_poll/'. $user['nickname'], 'confirm' => DI::baseUrl() . '/dfrn_confirm/' . $user['nickname'], - 'poco' => DI::baseUrl() . '/poco/' . $user['nickname'], ]; @@ -1116,40 +1138,26 @@ class Contact * Returns the data array for the photo menu of a given contact * * @param array $contact contact - * @param int $uid optional, default 0 + * @param int $uid Visitor user id * @return array * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function photoMenu(array $contact, int $uid = 0): array + public static function photoMenu(array $contact, int $uid): array { - $pm_url = ''; - $status_link = ''; - $photos_link = ''; - - if ($uid == 0) { - $uid = DI::userSession()->getLocalUserId(); + // Anonymous visitor + if (!$uid) { + return ['profile' => [DI::l10n()->t('View Profile'), self::magicLinkByContact($contact), true]]; } - if (empty($contact['uid']) || ($contact['uid'] != $uid)) { - if ($uid == 0) { - $profile_link = self::magicLinkByContact($contact); - $menu = ['profile' => [DI::l10n()->t('View Profile'), $profile_link, true]]; - - return $menu; - } - - // Look for our own contact if the uid doesn't match and isn't public - $contact_own = DBA::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]); - if (DBA::isResult($contact_own)) { - return self::photoMenu($contact_own, $uid); - } - } + $pm_url = ''; + $status_link = ''; + $photos_link = ''; $sparkle = false; if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) { - $sparkle = true; - $profile_link = DI::baseUrl() . '/redir/' . $contact['id']; + $sparkle = true; + $profile_link = 'contact/redir/' . $contact['id']; } else { $profile_link = $contact['url']; } @@ -1159,25 +1167,24 @@ class Contact } if ($sparkle) { - $status_link = $profile_link . '/status'; - $photos_link = str_replace('/profile/', '/photos/', $profile_link); + $status_link = $profile_link . '/status'; + $photos_link = $profile_link . '/photos'; $profile_link = $profile_link . '/profile'; } if (self::canReceivePrivateMessages($contact) && empty($contact['pending'])) { - $pm_url = DI::baseUrl() . '/message/new/' . $contact['id']; + $pm_url = 'message/new/' . $contact['id']; } - $contact_url = DI::baseUrl() . '/contact/' . $contact['id']; - - $posts_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/conversations'; + $contact_url = 'contact/' . $contact['id']; + $posts_link = 'contact/' . $contact['id'] . '/conversations'; - $follow_link = ''; + $follow_link = ''; $unfollow_link = ''; if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) { if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) { $unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1'; - } elseif(!$contact['pending']) { + } elseif (!$contact['pending']) { $follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1'; } } @@ -1188,27 +1195,27 @@ class Contact */ if (empty($contact['uid'])) { $menu = [ - 'profile' => [DI::l10n()->t('View Profile') , $profile_link , true], - 'network' => [DI::l10n()->t('Network Posts') , $posts_link , false], - 'edit' => [DI::l10n()->t('View Contact') , $contact_url , false], - 'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true], - 'unfollow'=> [DI::l10n()->t('UnFollow') , $unfollow_link, true], + 'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ], + 'network' => [DI::l10n()->t('Network Posts') , $posts_link , false], + 'edit' => [DI::l10n()->t('View Contact') , $contact_url , false], + 'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ], + 'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ], ]; } else { $menu = [ - 'status' => [DI::l10n()->t('View Status') , $status_link , true], - 'profile' => [DI::l10n()->t('View Profile') , $profile_link , true], - 'photos' => [DI::l10n()->t('View Photos') , $photos_link , true], - 'network' => [DI::l10n()->t('Network Posts') , $posts_link , false], - 'edit' => [DI::l10n()->t('View Contact') , $contact_url , false], - 'pm' => [DI::l10n()->t('Send PM') , $pm_url , false], - 'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true], - 'unfollow'=> [DI::l10n()->t('UnFollow') , $unfollow_link , true], + 'status' => [DI::l10n()->t('View Status') , $status_link , true ], + 'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ], + 'photos' => [DI::l10n()->t('View Photos') , $photos_link , true ], + 'network' => [DI::l10n()->t('Network Posts') , $posts_link , false], + 'edit' => [DI::l10n()->t('View Contact') , $contact_url , false], + 'pm' => [DI::l10n()->t('Send PM') , $pm_url , false], + 'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ], + 'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ], ]; if (!empty($contact['pending'])) { try { - $intro = DI::intro()->selectForContact($contact['id']); + $intro = DI::intro()->selectForContact($contact['id']); $menu['follow'] = [DI::l10n()->t('Approve'), 'notifications/intros/' . $intro->id, true]; } catch (IntroductionNotFoundException $exception) { DI::logger()->error('Pending contact doesn\'t have an introduction.', ['exception' => $exception]); @@ -1267,13 +1274,19 @@ class Contact return 0; } - $contact = self::getByURL($url, false, ['id', 'network', 'uri-id', 'next-update'], $uid); + $contact = self::getByURL($url, false, ['id', 'network', 'uri-id', 'next-update', 'local-data'], $uid); if (!empty($contact)) { $contact_id = $contact['id']; - if (Probe::isProbable($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) { - Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateContact', $contact['id']); + $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())) { + 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))) { @@ -1385,7 +1398,21 @@ class Contact } if ($data['network'] == Protocol::DIASPORA) { - FContact::updateFromProbeArray($data); + try { + DI::dsprContact()->updateFromProbeArray($data); + } catch (HTTPException\NotFoundException $e) { + Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data]); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data]); + } + } elseif (!empty($data['networks'][Protocol::DIASPORA])) { + try { + DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]); + } catch (HTTPException\NotFoundException $e) { + Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]); + } } self::updateFromProbeArray($contact_id, $data); @@ -1531,8 +1558,8 @@ class Contact $contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id'); if ($thread_mode) { - $condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql, - $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), DI::userSession()->getLocalUserId()]; + $condition = ["((`$contact_field` = ? AND `gravity` = ?) OR (`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `protocol` != ? AND `thr-parent-id` = `parent-uri-id`)) AND " . $sql, + $cid, Item::GRAVITY_PARENT, $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Conversation::PARCEL_DIASPORA, DI::userSession()->getLocalUserId()]; } else { $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql, $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, DI::userSession()->getLocalUserId()]; @@ -1583,7 +1610,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)); @@ -1598,7 +1625,7 @@ class Contact } } - $o .= DI::conversation()->create($items, 'contact-posts', $update); + $o .= DI::conversation()->create($items, ConversationContent::MODE_CONTACT_POSTS, $update); } if (!$update) { @@ -2047,9 +2074,10 @@ class Contact * @param integer $cid contact id * @param string $size One of the Proxy::SIZE_* constants * @param string $updated Contact update date + * @param bool $static If "true" a parameter is added to convert the avatar to a static one * @return string avatar link */ - public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string + public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = '', bool $static = false): string { // We have to fetch the "updated" variable when it wasn't provided // The parameter can be provided to improve performance @@ -2079,7 +2107,15 @@ class Contact $url .= Proxy::PIXEL_LARGE . '/'; break; } - return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : ''); + $query_params = []; + if ($updated) { + $query_params['ts'] = strtotime($updated); + } + if ($static) { + $query_params['static'] = true; + } + + return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); } /** @@ -2104,9 +2140,10 @@ class Contact * @param integer $cid contact id * @param string $size One of the Proxy::SIZE_* constants * @param string $updated Contact update date + * @param bool $static If "true" a parameter is added to convert the header to a static one * @return string header link */ - public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string + public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = '', bool $static = false): string { // We have to fetch the "updated" variable when it wasn't provided // The parameter can be provided to improve performance @@ -2137,7 +2174,15 @@ class Contact break; } - return $url . ($guid ?: $cid) . ($updated ? '?ts=' . strtotime($updated) : ''); + $query_params = []; + if ($updated) { + $query_params['ts'] = strtotime($updated); + } + if ($static) { + $query_params['static'] = true; + } + + return $url . ($guid ?: $cid) . (!empty($query_params) ? '?' . http_build_query($query_params) : ''); } /** @@ -2155,7 +2200,7 @@ class Contact */ public static function updateAvatar(int $cid, string $avatar, bool $force = false, bool $create_cache = false) { - $contact = DBA::selectFirst('contact', ['uid', 'avatar', 'photo', 'thumb', 'micro', 'xmpp', 'addr', 'nurl', 'url', 'network', 'uri-id'], + $contact = DBA::selectFirst('contact', ['uid', 'avatar', 'photo', 'thumb', 'micro', 'blurhash', 'xmpp', 'addr', 'nurl', 'url', 'network', 'uri-id'], ['id' => $cid, 'self' => false]); if (!DBA::isResult($contact)) { return; @@ -2165,8 +2210,19 @@ class Contact // 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) { - self::update(['avatar' => $avatar], ['id' => $cid]); + 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(); + } + } + + self::update($update_fields, ['id' => $cid]); Logger::info('Only update the avatar', ['id' => $cid, 'avatar' => $avatar, 'contact' => $contact]); } return; @@ -2196,7 +2252,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(), @@ -2237,7 +2295,7 @@ class Contact if ($update) { $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true); if ($photos) { - $fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()]; + $fields = ['avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'blurhash' => $photos[3], 'avatar-date' => DateTimeFormat::utcNow()]; $update = !empty($fields); Logger::debug('Created new cached avatars', ['id' => $cid, 'uid' => $uid, 'owner-uid' => $local_uid]); } else { @@ -2439,6 +2497,44 @@ class Contact return true; } + /** + * Perform a contact update if the contact is outdated + * + * @param integer $id contact id + * @return bool + */ + public static function updateByIdIfNeeded(int $id): bool + { + $contact = self::selectFirst(['url'], ["`id` = ? AND `next-update` < ?", $id, DateTimeFormat::utcNow()]); + if (empty($contact['url'])) { + return false; + } + + if (self::isLocal($contact['url'])) { + return true; + } + + $stamp = (float)microtime(true); + self::updateFromProbe($id); + Logger::debug('Contact data is updated.', ['duration' => round((float)microtime(true) - $stamp, 3), 'id' => $id, 'url' => $contact['url'], 'callstack' => System::callstack(20)]); + return true; + } + + /** + * Perform a contact update if the contact is outdated + * + * @param string $url contact url + * @return bool + */ + public static function updateByUrlIfNeeded(string $url): bool + { + $id = self::getIdForURL($url, 0, false); + if (!empty($id)) { + return self::updateByIdIfNeeded($id); + } + return (bool)self::getIdForURL($url); + } + /** * Updates contact record by provided id and optional network * @@ -2455,13 +2551,27 @@ class Contact return false; } - $ret = Probe::uri($contact['url'], $network, $contact['uid']); + $data = Probe::uri($contact['url'], $network, $contact['uid']); - if ($ret['network'] == Protocol::DIASPORA) { - FContact::updateFromProbeArray($ret); + if ($data['network'] == Protocol::DIASPORA) { + try { + DI::dsprContact()->updateFromProbeArray($data); + } catch (HTTPException\NotFoundException $e) { + Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]); + } + } elseif (!empty($data['networks'][Protocol::DIASPORA])) { + try { + DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]); + } catch (HTTPException\NotFoundException $e) { + Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]); + } catch (\InvalidArgumentException $e) { + Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]); + } } - return self::updateFromProbeArray($id, $ret); + return self::updateFromProbeArray($id, $data); } /** @@ -2643,7 +2753,7 @@ class Contact } $update = false; - $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url'], parse_url($ret['url'], PHP_URL_HOST)); + $guid = ($ret['guid'] ?? '') ?: Item::guidFromUri($ret['url']); // make sure to not overwrite existing values with blank entries except some technical fields $keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl']; @@ -2855,20 +2965,13 @@ 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 - // the poll url is more reliable than the profile url, as we may have - // indirect links or webfinger links - - $condition = ['uid' => $uid, 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false]; - $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); - if (!DBA::isResult($contact)) { - $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'pending' => false]; - $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); - } + $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url'])]; + $contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition); $protocol = self::getProtocol($ret['url'], $ret['network']); @@ -2924,7 +3027,13 @@ class Contact // update contact $new_relation = (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND]) ? self::FRIEND : self::SHARING); - $fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false]; + $fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false, 'network' => $ret['network']]; + + if ($contact['pending'] && !empty($contact['hub-verify'])) { + ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid); + $fields['pending'] = false; + } + self::update($fields, ['id' => $contact['id']]); } else { $new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING); @@ -2981,7 +3090,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); @@ -3156,11 +3269,14 @@ class Contact return; } + Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $contact['uid']); + self::clearFollowerFollowingEndpointCache($contact['uid']); $cdata = self::getPublicAndUserContactID($contact['id'], $contact['uid']); - - DI::notification()->deleteForUserByVerb($contact['uid'], Activity::FOLLOW, ['actor-id' => $cdata['public']]); + if (!empty($cdata['public'])) { + DI::notification()->deleteForUserByVerb($contact['uid'], Activity::FOLLOW, ['actor-id' => $cdata['public']]); + } } /** @@ -3179,6 +3295,8 @@ class Contact } else { self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]); } + + Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $contact['uid']); } /** @@ -3324,7 +3442,7 @@ class Contact return $destination; } - $redirect = 'redir/' . $contact['id']; + $redirect = 'contact/redir/' . $contact['id']; if (($url != '') && !Strings::compareLink($contact['url'], $url)) { $redirect .= '?url=' . $url; @@ -3373,11 +3491,13 @@ class Contact * @param string $search Name or nick * @param string $mode Search mode (e.g. "community") * @param int $uid User ID + * @param int $limit Maximum amount of returned values + * @param int $offset Limit offset * * @return array with search results * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function searchByName(string $search, string $mode = '', int $uid = 0): array + public static function searchByName(string $search, string $mode = '', int $uid = 0, int $limit = 0, int $offset = 0): array { if (empty($search)) { return []; @@ -3397,6 +3517,8 @@ class Contact if ($uid == 0) { $condition['blocked'] = false; + } else { + $condition['rel'] = [Contact::SHARING, Contact::FRIEND]; } // check if we search only communities or every contact @@ -3406,12 +3528,19 @@ class Contact $search .= '%'; + $params = []; + + if (!empty($limit) && !empty($offset)) { + $params['limit'] = [$offset, $limit]; + } elseif (!empty($limit)) { + $params['limit'] = $limit; + } + $condition = DBA::mergeConditions($condition, ["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` WHERE `publish` OR `net-publish`)) AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]); - $contacts = self::selectToArray([], $condition); - return $contacts; + return self::selectToArray([], $condition, $params); } /** @@ -3436,8 +3565,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; } @@ -3466,4 +3599,17 @@ class Contact return []; } + + /** + * Checks, if contacts with the given condition exists + * + * @param array $condition + * + * @return bool + * @throws \Exception + */ + public static function exists(array $condition): bool + { + return DBA::exists('contact', $condition); + } }