]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #8119 from annando/localdfrn
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 16 Jan 2020 12:31:28 +0000 (07:31 -0500)
committerGitHub <noreply@github.com>
Thu, 16 Jan 2020 12:31:28 +0000 (07:31 -0500)
Ensure that local contacts always are DFRN contacts

src/Model/Contact.php
src/Network/Probe.php
src/Protocol/ActivityPub/Processor.php
src/Worker/Cron.php
src/Worker/OnePoll.php

index e6c00b1e3c6e1fa518d6cb86a154d55153f8edef..550f89f31a6343dad11e88fdbe36defccb5cb5cf 100644 (file)
@@ -314,6 +314,29 @@ class Contact
                return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());
        }
 
+       /**
+        * Check if the given contact ID is on the same server
+        *
+        * @param string $url The contact link
+        *
+        * @return boolean Is it the same server?
+        */
+       public static function isLocalById(int $cid)
+       {
+               $contact = DBA::selectFirst('contact', ['url', 'baseurl'], ['id' => $cid]);
+               if (!DBA::isResult($contact)) {
+                       return false;
+               }
+
+               if (empty($contact['baseurl'])) {
+                       $baseurl = self::getBasepath($contact['url'], true);
+               } else {
+                       $baseurl = $contact['baseurl'];
+               }
+
+               return Strings::compareLink($baseurl, DI::baseUrl());
+       }
+
        /**
         * Returns the public contact id of the given user id
         *
@@ -2126,6 +2149,12 @@ class Contact
                        if ($force) {
                                self::updateContact($id, $uid, $ret['url'], ['last-update' => $updated, 'success_update' => $updated]);
                        }
+
+                       // Update the public contact
+                       if ($uid != 0) {
+                               self::updateFromProbeByURL($ret['url']);
+                       }
+
                        return true;
                }
 
index 497fd3c51704bd4f468e708da9ac5f0a1f1153f3..e25e24593143c1f3fa19057f30e5aded2300b2a9 100644 (file)
@@ -401,6 +401,11 @@ class Probe
                        $data['network'] = Protocol::PHANTOM;
                }
 
+               // 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;
+               }
+
                if (!isset($data['hide']) && in_array($data['network'], Protocol::FEDERATED)) {
                        $data['hide'] = self::getHideStatus($data['url']);
                }
index c96a4e704c84505292d78945df5ec0156f406961..ca8d6478d700db4e54e9a329c3404ee8d00e58e7 100644 (file)
@@ -857,13 +857,13 @@ class Processor
         */
        private static function switchContact($cid)
        {
-               $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
-               if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
+               $contact = DBA::selectFirst('contact', ['network', 'url'], ['id' => $cid]);
+               if (!DBA::isResult($contact) || in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN]) || Contact::isLocal($contact['url'])) {
                        return;
                }
 
-               Logger::log('Change existing contact ' . $cid . ' from ' . $contact['network'] . ' to ActivityPub.');
-               Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB);
+               Logger::info('Change existing contact', ['cid' => $cid, 'previous' => $contact['network']]);
+               Contact::updateFromProbe($cid);
        }
 
        /**
index 2d46ce328d12440e7e1f9e41ae9dbb1c155455a3..5df19226a3b6a2bcae18bd968b95e98c0856f974 100644 (file)
@@ -177,12 +177,12 @@ class Cron
                                FROM `user`
                                STRAIGHT_JOIN `contact`
                                ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
-                                       AND `contact`.`network` IN (?, ?, ?, ?)
+                                       AND `contact`.`network` IN (?, ?, ?, ?, ?)
                                        AND NOT `contact`.`self` AND NOT `contact`.`blocked`
                                        AND `contact`.`rel` != ?
                                WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`";
 
-               $parameters = [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
+               $parameters = [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
 
                // Only poll from those with suitable relationships,
                // and which have a polling address and ignore Diaspora since
@@ -209,6 +209,11 @@ class Cron
                                $contact['priority'] = 3;
                        }
 
+                       // ActivityPub is checked once a week
+                       if ($contact['network'] == Protocol::ACTIVITYPUB) {
+                               $contact['priority'] = 4;
+                       }
+
                        // Check archived contacts once a month
                        if ($contact['archive']) {
                                $contact['priority'] = 5;
index 107bd342467d435facdf6c73e31064e020cc8c2a..b557f4ea3d447a3aadac7168f117780c4f4a2712 100644 (file)
@@ -38,9 +38,7 @@ class OnePoll
                        return;
                }
 
-               if ($force) {
-                       Contact::updateFromProbe($contact_id, '', true);
-               }
+               Contact::updateFromProbe($contact_id, '', $force);
 
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
                if (!DBA::isResult($contact)) {
@@ -48,6 +46,12 @@ class OnePoll
                        return;
                }
 
+               // Special treatment for wrongly detected local contacts
+               if (!$force && ($contact['network'] != Protocol::DFRN) && Contact::isLocalById($contact_id)) {
+                       Contact::updateFromProbe($contact_id, Protocol::DFRN, true);
+                       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
+               }
+
                if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) {
                        $protocol = Protocol::ACTIVITYPUB;
                } else {