From: Michael Date: Sun, 11 Dec 2022 22:26:30 +0000 (+0000) Subject: API: Use "contact" for own relations X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ff5da9bc7138752483bb346b62b550c0496dda1d;p=friendica.git API: Use "contact" for own relations --- diff --git a/src/Module/Api/Twitter/Followers/Ids.php b/src/Module/Api/Twitter/Followers/Ids.php index 6acf7c8311..3753a790a5 100644 --- a/src/Module/Api/Twitter/Followers/Ids.php +++ b/src/Module/Api/Twitter/Followers/Ids.php @@ -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); diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index fbae33652f..9983cb4e53 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -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); diff --git a/src/Module/Api/Twitter/Friends/Ids.php b/src/Module/Api/Twitter/Friends/Ids.php index a46be8deb9..736c78fae2 100644 --- a/src/Module/Api/Twitter/Friends/Ids.php +++ b/src/Module/Api/Twitter/Friends/Ids.php @@ -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); diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 304f19db9e..5d8b5bfaca 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -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);