]> git.mxchange.org Git - friendica.git/commitdiff
Improve the fetching of the contact's baseurl
authorMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 04:09:49 +0000 (04:09 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 28 Aug 2023 04:09:49 +0000 (04:09 +0000)
src/Model/Contact.php
src/Network/Probe.php
src/Worker/UpdateContact.php

index d91abe9bcdb0b3070fa579b0171be4da3b4ef6e1..a18d6b9d0fee929d8d5e45007b4a02dee1a5b48b 100644 (file)
@@ -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,
index 2b5cc3cff7d02a7cdcaa0209d14813ca37524cde..a0887d5cba877cb5187acccdf6c09017c261b1a6 100644 (file)
@@ -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;
index c2e443282056381cae6594c1c88d7a618e1d7e1f..23eb5ff4bac37f32f5041ba56ee133a5985857f0 100644 (file)
@@ -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
 {