]> git.mxchange.org Git - friendica.git/commitdiff
API: Use "contact" for own relations
authorMichael <heluecht@pirati.ca>
Sun, 11 Dec 2022 22:26:30 +0000 (22:26 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 11 Dec 2022 22:26:30 +0000 (22:26 +0000)
src/Module/Api/Twitter/Followers/Ids.php
src/Module/Api/Twitter/Followers/Lists.php
src/Module/Api/Twitter/Friends/Ids.php
src/Module/Api/Twitter/Friends/Lists.php

index 6acf7c83110607ee7f65955480c51b756e49dc7a..3753a790a5c1e3675fb5806f2dd08017c2858c55 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Twitter\Followers;
 
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Module\Api\Twitter\ContactEndpoint;
 use Friendica\Module\BaseApi;
 
@@ -47,34 +48,61 @@ class Ids extends ContactEndpoint
                $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
                $min_id   = $this->getRequestValue($request, 'min_id', 0, 0);
 
-               $params = ['order' => ['relation-cid' => true], 'limit' => $count];
-
-               $condition = ['cid' => $cid, 'follows' => true];
-
-               $total_count = (int)DBA::count('contact-relation', $condition);
-
-               if (!empty($max_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]);
-               }
-
-               if (!empty($since_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $since_id]);
-               }
-
-               if (!empty($min_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
-
-                       $params['order'] = ['relation-cid'];
-               }
-
-               $ids = [];
-
-               $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params);
-               while ($follower = DBA::fetch($followers)) {
-                       self::setBoundaries($follower['relation-cid']);
-                       $ids[] = $follower['relation-cid'];
+               if ($cid == Contact::getPublicIdByUserId($uid)) {
+                       $params = ['order' => ['pid' => true], 'limit' => $count];
+
+                       $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
+       
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]);
+                       }
+       
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $since_id]);
+                       }
+       
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $min_id]);
+       
+                               $params['order'] = ['pid'];
+                       }
+       
+                       $ids = [];
+       
+                       foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) {
+                               self::setBoundaries($follower['pid']);
+                               $ids[] = $follower['pid'];
+                       }
+               } else {
+                       $params = ['order' => ['relation-cid' => true], 'limit' => $count];
+
+                       $condition = ['cid' => $cid, 'follows' => true];
+
+                       $total_count = (int)DBA::count('contact-relation', $condition);
+
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]);
+                       }
+
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $since_id]);
+                       }
+
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
+
+                               $params['order'] = ['relation-cid'];
+                       }
+
+                       $ids = [];
+
+                       $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params);
+                       while ($follower = DBA::fetch($followers)) {
+                               self::setBoundaries($follower['relation-cid']);
+                               $ids[] = $follower['relation-cid'];
+                       }
+                       DBA::close($followers);
                }
-               DBA::close($followers);
 
                if (!empty($min_id)) {
                        $ids = array_reverse($ids);
index fbae33652f7aaffab5af9076caa10a68c8697b8b..9983cb4e530122747cbf47a5121025ddc480b103 100644 (file)
@@ -21,8 +21,8 @@
 
 namespace Friendica\Module\Api\Twitter\Followers;
 
-use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Module\Api\Twitter\ContactEndpoint;
 use Friendica\Module\BaseApi;
 
@@ -48,34 +48,61 @@ class Lists extends ContactEndpoint
                $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
                $min_id   = $this->getRequestValue($request, 'min_id', 0, 0);
 
-               $params = ['order' => ['relation-cid' => true], 'limit' => $count];
-
-               $condition = ['cid' => $cid, 'follows' => true];
-
-               $total_count = (int)DBA::count('contact-relation', $condition);
-
-               if (!empty($max_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]);
-               }
-
-               if (!empty($since_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $since_id]);
-               }
-
-               if (!empty($min_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
-
-                       $params['order'] = ['relation-cid'];
-               }
-
-               $ids = [];
-
-               $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params);
-               while ($follower = DBA::fetch($followers)) {
-                       self::setBoundaries($follower['relation-cid']);
-                       $ids[] = $follower['relation-cid'];
+               if ($cid == Contact::getPublicIdByUserId($uid)) {
+                       $params = ['order' => ['pid' => true], 'limit' => $count];
+
+                       $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
+       
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]);
+                       }
+       
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $since_id]);
+                       }
+       
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $min_id]);
+       
+                               $params['order'] = ['pid'];
+                       }
+       
+                       $ids = [];
+       
+                       foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) {
+                               self::setBoundaries($follower['pid']);
+                               $ids[] = $follower['pid'];
+                       }
+               } else {
+                       $params = ['order' => ['relation-cid' => true], 'limit' => $count];
+
+                       $condition = ['cid' => $cid, 'follows' => true];
+
+                       $total_count = (int)DBA::count('contact-relation', $condition);
+
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]);
+                       }
+
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $since_id]);
+                       }
+
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`relation-cid` > ?", $min_id]);
+
+                               $params['order'] = ['relation-cid'];
+                       }
+
+                       $ids = [];
+
+                       $followers = DBA::select('contact-relation', ['relation-cid'], $condition, $params);
+                       while ($follower = DBA::fetch($followers)) {
+                               self::setBoundaries($follower['relation-cid']);
+                               $ids[] = $follower['relation-cid'];
+                       }
+                       DBA::close($followers);
                }
-               DBA::close($followers);
 
                if (!empty($min_id)) {
                        $ids = array_reverse($ids);
index a46be8deb9910a759755dd4dcd804cab08ba4f0a..736c78fae26033791b5cefc14503531c6b443937 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Twitter\Friends;
 
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Module\Api\Twitter\ContactEndpoint;
 use Friendica\Module\BaseApi;
 
@@ -47,34 +48,61 @@ class Ids extends ContactEndpoint
                $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
                $min_id   = $this->getRequestValue($request, 'min_id', 0, 0);
 
-               $params = ['order' => ['cid' => true], 'limit' => $count];
-
-               $condition = ['relation-cid' => $cid, 'follows' => true];
-
-               $total_count = (int)DBA::count('contact-relation', $condition);
-
-               if (!empty($max_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
-               }
-
-               if (!empty($since_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
-               }
-
-               if (!empty($min_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
-
-                       $params['order'] = ['cid'];
-               }
-
-               $ids = [];
-
-               $followers = DBA::select('contact-relation', ['cid'], $condition, $params);
-               while ($follower = DBA::fetch($followers)) {
-                       self::setBoundaries($follower['cid']);
-                       $ids[] = $follower['cid'];
+               if ($cid == Contact::getPublicIdByUserId($uid)) {
+                       $params = ['order' => ['pid' => true], 'limit' => $count];
+
+                       $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]];
+       
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]);
+                       }
+       
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $since_id]);
+                       }
+       
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $min_id]);
+       
+                               $params['order'] = ['pid'];
+                       }
+       
+                       $ids = [];
+       
+                       foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) {
+                               self::setBoundaries($follower['pid']);
+                               $ids[] = $follower['pid'];
+                       }
+               } else {
+                       $params = ['order' => ['cid' => true], 'limit' => $count];
+
+                       $condition = ['relation-cid' => $cid, 'follows' => true];
+
+                       $total_count = (int)DBA::count('contact-relation', $condition);
+
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
+                       }
+
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
+                       }
+
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
+
+                               $params['order'] = ['cid'];
+                       }
+
+                       $ids = [];
+
+                       $followers = DBA::select('contact-relation', ['cid'], $condition, $params);
+                       while ($follower = DBA::fetch($followers)) {
+                               self::setBoundaries($follower['cid']);
+                               $ids[] = $follower['cid'];
+                       }
+                       DBA::close($followers);
                }
-               DBA::close($followers);
 
                if (!empty($min_id)) {
                        $ids = array_reverse($ids);
index 304f19db9e4cb1db9185cdbcac076ed672825611..5d8b5bfaca3c49cc8d0ecee8c0b1c43fe0ada557 100644 (file)
@@ -21,8 +21,8 @@
 
 namespace Friendica\Module\Api\Twitter\Friends;
 
-use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Module\Api\Twitter\ContactEndpoint;
 use Friendica\Module\BaseApi;
 
@@ -48,34 +48,61 @@ class Lists extends ContactEndpoint
                $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
                $min_id   = $this->getRequestValue($request, 'min_id', 0, 0);
 
-               $params = ['order' => ['cid' => true], 'limit' => $count];
-
-               $condition = ['relation-cid' => $cid, 'follows' => true];
-
-               $total_count = (int)DBA::count('contact-relation', $condition);
-
-               if (!empty($max_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
-               }
-
-               if (!empty($since_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
-               }
-
-               if (!empty($min_id)) {
-                       $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
-
-                       $params['order'] = ['cid'];
-               }
-
-               $ids = [];
-
-               $followers = DBA::select('contact-relation', ['cid'], $condition, $params);
-               while ($follower = DBA::fetch($followers)) {
-                       self::setBoundaries($follower['cid']);
-                       $ids[] = $follower['cid'];
+               if ($cid == Contact::getPublicIdByUserId($uid)) {
+                       $params = ['order' => ['pid' => true], 'limit' => $count];
+
+                       $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]];
+       
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]);
+                       }
+       
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $since_id]);
+                       }
+       
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`pid` > ?", $min_id]);
+       
+                               $params['order'] = ['pid'];
+                       }
+       
+                       $ids = [];
+       
+                       foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) {
+                               self::setBoundaries($follower['pid']);
+                               $ids[] = $follower['pid'];
+                       }
+               } else {
+                       $params = ['order' => ['cid' => true], 'limit' => $count];
+       
+                       $condition = ['relation-cid' => $cid, 'follows' => true];
+
+                       $total_count = (int)DBA::count('contact-relation', $condition);
+
+                       if (!empty($max_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
+                       }
+
+                       if (!empty($since_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
+                       }
+
+                       if (!empty($min_id)) {
+                               $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
+
+                               $params['order'] = ['cid'];
+                       }
+
+                       $ids = [];
+
+                       $followers = DBA::select('contact-relation', ['cid'], $condition, $params);
+                       while ($follower = DBA::fetch($followers)) {
+                               self::setBoundaries($follower['cid']);
+                               $ids[] = $follower['cid'];
+                       }
+                       DBA::close($followers);
                }
-               DBA::close($followers);
 
                if (!empty($min_id)) {
                        $ids = array_reverse($ids);