]> git.mxchange.org Git - friendica.git/commitdiff
Only output ActivityPub contacts in /followers and /following
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 6 May 2020 02:33:26 +0000 (22:33 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 6 May 2020 19:29:35 +0000 (15:29 -0400)
- Join contact table with apcontact to weed out non-AP contacts

src/Protocol/ActivityPub/Transmitter.php

index b393abd9e1798d331120b84bc72d07cd0185fa4b..84a6d61be607385552cb7d346b2d8f0df005b42b 100644 (file)
@@ -74,16 +74,30 @@ class Transmitter
         */
        public static function getContacts($owner, $rel, $module, $page = null)
        {
-               $condition = ['rel' => $rel, 'network' => Protocol::FEDERATED, 'uid' => $owner['uid'],
-                       'self' => false, 'deleted' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
-               $count = DBA::count('contact', $condition);
+               $parameters = [
+                       'rel' => $rel,
+                       'uid' => $owner['uid'],
+                       'self' => false,
+                       'deleted' => false,
+                       'hidden' => false,
+                       'archive' => false,
+                       'pending' => false
+               ];
+               $condition = DBA::buildCondition($parameters);
+
+               $sql = "SELECT COUNT(*) as `count`
+               FROM `contact`
+               JOIN `apcontact` ON `apcontact`.`url` = `contact`.`url`
+               " . $condition;
+
+               $contacts = DBA::fetchFirst($sql, ...$parameters);
 
                $modulePath = '/' . $module . '/';
 
                $data = ['@context' => ActivityPub::CONTEXT];
                $data['id'] = DI::baseUrl() . $modulePath . $owner['nickname'];
                $data['type'] = 'OrderedCollection';
-               $data['totalItems'] = $count;
+               $data['totalItems'] = $contacts['count'];
 
                // When we hide our friends we will only show the pure number but don't allow more.
                $profile = Profile::getByUID($owner['uid']);
@@ -97,7 +111,16 @@ class Transmitter
                        $data['type'] = 'OrderedCollectionPage';
                        $list = [];
 
-                       $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
+                       $sql = "SELECT `contact`.`url`
+                       FROM `contact`
+                       JOIN `apcontact` ON `apcontact`.`url` = `contact`.`url`
+                       " . $condition . "
+                       LIMIT ?, ?";
+
+                       $parameters[] = ($page - 1) * 100;
+                       $parameters[] = 100;
+
+                       $contacts = DBA::p($sql, ...$parameters);
                        while ($contact = DBA::fetch($contacts)) {
                                $list[] = $contact['url'];
                        }