Merge pull request #8044 from annando/contact-adding

Don't add contacts when not needed
This commit is contained in:
Philipp 2020-01-01 20:38:34 +01:00 committed by GitHub
commit 75c74e8562
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 19 deletions

View file

@ -216,7 +216,7 @@ class GContact
if (empty($gcontact['server_url'])) {
// We check the server url to be sure that it is a real one
$server_url = Contact::getBasepath($gcontact['url']);
$server_url = self::getBasepath($gcontact['url']);
// We are now sure that it is a correct URL. So we use it in the future
if ($server_url != '') {
@ -1128,6 +1128,38 @@ class GContact
self::update($gcontact);
}
/**
* @brief Get the basepath for a given contact link
*
* @param string $url The gcontact link
* @param boolean $dont_update Don't update the contact
*
* @return string basepath
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function getBasepath($url, $dont_update = false)
{
$gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
if (!empty($gcontact['server_url'])) {
return $gcontact['server_url'];
} elseif ($dont_update) {
return '';
}
self::updateFromProbe($url, true);
// Fetch the result
$gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($url)]);
if (empty($gcontact['server_url'])) {
Logger::info('No baseurl for gcontact', ['url' => $url]);
return '';
}
Logger::info('Found baseurl for gcontact', ['url' => $url, 'baseurl' => $gcontact['server_url']]);
return $gcontact['server_url'];
}
/**
* @brief Fetches users of given GNU Social server
*