Always use direct DFRN transport on local contacts
authorMichael <heluecht@pirati.ca>
Sat, 21 Sep 2019 12:39:07 +0000 (12:39 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 21 Sep 2019 12:39:07 +0000 (12:39 +0000)
src/Model/Contact.php
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Notifier.php

index 6f0de5a..1ea6704 100644 (file)
@@ -290,6 +290,19 @@ class Contact extends BaseObject
                return '';
        }
 
+       /**
+        * Check if the given contact url is on the same machine
+        *
+        * @param string $url The contact link
+        *
+        * @return boolean Is it the same machine?
+        */
+       public static function isLocal($url)
+       {
+               return Strings::compareLink(self::getBasepath($url), System::baseUrl());
+
+       }
+
        /**
         * Returns the public contact id of the given user id
         *
@@ -2486,6 +2499,9 @@ class Contact extends BaseObject
                                                ['id' => $contact['id'], 'uid' => $importer['uid']]);
                        }
 
+                       // Ensure to always have the correct network type, independent from the connection request method
+                       self::updateFromProbe($contact['id'], '', true);
+
                        return true;
                } else {
                        // send email notification to owner?
@@ -2511,15 +2527,14 @@ class Contact extends BaseObject
                                'writable' => 1,
                        ]);
 
-                       $contact_record = [
-                               'id' => DBA::lastInsertId(),
-                               'network' => $network,
-                               'name' => $name,
-                               'url' => $url,
-                               'photo' => $photo
-                       ];
+                       $contact_id = DBA::lastInsertId();
+
+                       // Ensure to always have the correct network type, independent from the connection request method
+                       self::updateFromProbe($contact_id, '', true);
+
+                       Contact::updateAvatar($photo, $importer["uid"], $contact_id, true);
 
-                       Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
+                       $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);
 
                        /// @TODO Encapsulate this into a function/method
                        $fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
index e44ae1c..19c0cc2 100644 (file)
@@ -544,6 +544,10 @@ class Transmitter
 
                $contacts = DBA::select('contact', ['url', 'network', 'protocol'], $condition);
                while ($contact = DBA::fetch($contacts)) {
+                       if (Contact::isLocal($contact['url'])) {
+                               continue;
+                       }
+
                        if (!in_array($contact['network'], $networks) && ($contact['protocol'] != Protocol::ACTIVITYPUB)) {
                                continue;
                        }
@@ -611,6 +615,10 @@ class Transmitter
                                if ($receiver == $item_profile['followers']) {
                                        $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
                                } else {
+                                       if (Contact::isLocal($receiver)) {
+                                               continue;
+                                       }
+
                                        $profile = APContact::getByURL($receiver, false);
                                        if (!empty($profile)) {
                                                if (empty($profile['sharedinbox']) || $personal || $blindcopy) {
index 154a638..8755a59 100644 (file)
@@ -568,6 +568,11 @@ class Notifier
         */
        private static function skipDFRN($contact, $item, $cmd)
        {
+               // Use DFRN if we are on the same site
+               if (Contact::isLocal($contact['url'])) {
+                       return false;
+               }
+
                // Don't skip when author or owner don't have AP profiles
                if ((!empty($item['author-link']) && empty(APContact::getByURL($item['author-link'], false))) || (!empty($item['owner-link']) && empty(APContact::getByURL($item['owner-link'], false)))) {
                        return false;