Merge pull request #13383 from annando/baseurl

Improve the fetching of the contact's baseurl
This commit is contained in:
Hypolite Petovan 2023-08-28 12:31:23 -04:00 committed by GitHub
commit 75c4cc70c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -222,6 +222,11 @@ class Contact
Contact\User::insertForContactArray($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']; return $contact['id'];
} }
@ -1372,6 +1377,7 @@ class Contact
$fields = [ $fields = [
'uid' => $uid, 'uid' => $uid,
'url' => $data['url'], 'url' => $data['url'],
'baseurl' => $data['baseurl'] ?? '',
'nurl' => Strings::normaliseLink($data['url']), 'nurl' => Strings::normaliseLink($data['url']),
'network' => $data['network'], 'network' => $data['network'],
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
@ -3181,7 +3187,7 @@ class Contact
return false; 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']]); $pub_contact = DBA::selectFirst('contact', $fields, ['id' => $datarray['author-id']]);
if (!DBA::isResult($pub_contact)) { if (!DBA::isResult($pub_contact)) {
// Should never happen // Should never happen
@ -3252,6 +3258,7 @@ class Contact
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
'url' => $url, 'url' => $url,
'nurl' => Strings::normaliseLink($url), 'nurl' => Strings::normaliseLink($url),
'baseurl' => $pub_contact['baseurl'] ?? '',
'name' => $name, 'name' => $name,
'nick' => $nick, 'nick' => $nick,
'network' => $network, 'network' => $network,

View File

@ -415,14 +415,19 @@ class Probe
} }
} }
if (!empty($data['baseurl']) && empty($data['gsid'])) {
$data['gsid'] = GServer::getID($data['baseurl']);
}
if (empty($data['network'])) { if (empty($data['network'])) {
$data['network'] = Protocol::PHANTOM; $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 // Ensure that local connections always are DFRN
if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) { if (($network == '') && ($data['network'] != Protocol::PHANTOM) && (self::ownHost($data['baseurl'] ?? '') || self::ownHost($data['url']))) {
$data['network'] = Protocol::DFRN; $data['network'] = Protocol::DFRN;

View File

@ -25,7 +25,6 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Network;
class UpdateContact class UpdateContact
{ {