From: Michael Date: Mon, 28 Aug 2023 04:09:49 +0000 (+0000) Subject: Improve the fetching of the contact's baseurl X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38d09084a321457b5b4fc2c1256f1913977e057f;p=friendica.git Improve the fetching of the contact's baseurl --- diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d91abe9bcd..a18d6b9d0f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -222,6 +222,11 @@ class Contact Contact\User::insertForContactArray($contact); + if ((empty($contact['baseurl']) || empty($contact['gsid'])) && Probe::isProbable($contact['network'])) { + Logger::debug('Update missing baseurl', ['id' => $contact['id'], 'url' => $contact['url'], 'callstack' => System::callstack(4, 0, true)]); + UpdateContact::add(['priority' => Worker::PRIORITY_MEDIUM, 'dont_fork' => true], $contact['id']); + } + return $contact['id']; } @@ -1372,6 +1377,7 @@ class Contact $fields = [ 'uid' => $uid, 'url' => $data['url'], + 'baseurl' => $data['baseurl'] ?? '', 'nurl' => Strings::normaliseLink($data['url']), 'network' => $data['network'], 'created' => DateTimeFormat::utcNow(), @@ -3181,7 +3187,7 @@ class Contact return false; } - $fields = ['id', 'url', 'name', 'nick', 'avatar', 'photo', 'network', 'blocked']; + $fields = ['id', 'url', 'name', 'nick', 'avatar', 'photo', 'network', 'blocked', 'baseurl']; $pub_contact = DBA::selectFirst('contact', $fields, ['id' => $datarray['author-id']]); if (!DBA::isResult($pub_contact)) { // Should never happen @@ -3252,6 +3258,7 @@ class Contact 'created' => DateTimeFormat::utcNow(), 'url' => $url, 'nurl' => Strings::normaliseLink($url), + 'baseurl' => $pub_contact['baseurl'] ?? '', 'name' => $name, 'nick' => $nick, 'network' => $network, diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 2b5cc3cff7..a0887d5cba 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -415,14 +415,19 @@ class Probe } } - if (!empty($data['baseurl']) && empty($data['gsid'])) { - $data['gsid'] = GServer::getID($data['baseurl']); - } - if (empty($data['network'])) { $data['network'] = Protocol::PHANTOM; } + $baseurl = parse_url($data['url'], PHP_URL_SCHEME) . '://' . parse_url($data['url'], PHP_URL_HOST); + if (empty($data['baseurl']) && ($data['network'] == Protocol::ACTIVITYPUB) && (rtrim($data['url'], '/') == $baseurl)) { + $data['baseurl'] = $baseurl; + } + + if (!empty($data['baseurl']) && empty($data['gsid'])) { + $data['gsid'] = GServer::getID($data['baseurl']); + } + // Ensure that local connections always are DFRN if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) { $data['network'] = Protocol::DFRN; diff --git a/src/Worker/UpdateContact.php b/src/Worker/UpdateContact.php index c2e4432820..23eb5ff4ba 100644 --- a/src/Worker/UpdateContact.php +++ b/src/Worker/UpdateContact.php @@ -25,7 +25,6 @@ use Friendica\Core\Logger; use Friendica\Core\Worker; use Friendica\Model\Contact; use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Util\Network; class UpdateContact {