]> git.mxchange.org Git - friendica.git/commitdiff
Improved detection for a local contact
authorMichael <heluecht@pirati.ca>
Mon, 19 Jul 2021 04:15:57 +0000 (04:15 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 19 Jul 2021 04:15:57 +0000 (04:15 +0000)
src/Model/APContact.php
src/Model/Contact.php
src/Network/Probe.php

index a4c97f6232f672c9030449bff3c83136fe4ee20a..7bdde60c65ca31be4446c4009378bb1a9446d3f5 100644 (file)
@@ -54,6 +54,20 @@ class APContact
                        return [];
                }
 
+               if (Contact::isLocal($addr) && ($local_uid = User::getIdForURL($addr)) && ($local_owner = User::getOwnerDataById($local_uid))) {
+                       $data = [
+                               'addr'      => $local_owner['addr'],
+                               'baseurl'   => $local_owner['baseurl'],
+                               'url'       => $local_owner['url'],
+                               'subscribe' => $local_owner['baseurl'] . '/follow?url={uri}'];
+
+                       if (!empty($local_owner['alias']) && ($local_owner['url'] != $local_owner['alias'])) {
+                               $data['alias'] = $local_owner['alias'];
+                       }
+
+                       return $data;
+               }
+
                $data = ['addr' => $addr];
                $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
                $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), 'application/jrd+json');
@@ -284,7 +298,7 @@ class APContact
                                $following = ActivityPub::fetchContent($apcontact['following']);
                        }
                        if (!empty($following['totalItems'])) {
-                               // Mastodon seriously allows for this condition? 
+                               // Mastodon seriously allows for this condition?
                                // Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
                                if ($following['totalItems'] < 0) {
                                        $following['totalItems'] = 0;
@@ -300,7 +314,7 @@ class APContact
                                $followers = ActivityPub::fetchContent($apcontact['followers']);
                        }
                        if (!empty($followers['totalItems'])) {
-                               // Mastodon seriously allows for this condition? 
+                               // Mastodon seriously allows for this condition?
                                // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
                                if ($followers['totalItems'] < 0) {
                                        $followers['totalItems'] = 0;
index fe6fe55f3288a3252887a320626a094f7a6693a4..c68039643fe745f22e950273aa13bcc6410f0ad4 100644 (file)
@@ -453,6 +453,13 @@ class Contact
         */
        public static function isLocal($url)
        {
+               if (!parse_url($url, PHP_URL_SCHEME)) {
+                       $addr_parts = explode('@', $url);
+                       if (count($addr_parts) == 2) {
+                               return $addr_parts[1] == DI::baseUrl()->getHostname();
+                       }
+               }
+
                return Strings::compareLink(self::getBasepath($url, true), DI::baseUrl());
        }
 
index e44a8d326ecf92bd16d1da9bdfb5fd2b0d756029..12a5b269255b37ecc121c9a53f764f899ffcd1f0 100644 (file)
@@ -333,7 +333,7 @@ class Probe
        public static function uri($uri, $network = '', $uid = -1)
        {
                // Local profiles aren't probed via network
-               if (empty($network) && strpos($uri, DI::baseUrl()->getHostname())) {
+               if (empty($network) && Contact::isLocal($uri)) {
                        $data = self::localProbe($uri);
                        if (!empty($data)) {
                                return $data;