From ff5da9bc7138752483bb346b62b550c0496dda1d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Dec 2022 22:26:30 +0000 Subject: [PATCH 1/5] API: Use "contact" for own relations --- src/Module/Api/Twitter/Followers/Ids.php | 76 ++++++++++++++------- src/Module/Api/Twitter/Followers/Lists.php | 77 +++++++++++++++------- src/Module/Api/Twitter/Friends/Ids.php | 76 ++++++++++++++------- src/Module/Api/Twitter/Friends/Lists.php | 77 +++++++++++++++------- 4 files changed, 208 insertions(+), 98 deletions(-) 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,35 +48,62 @@ 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]; + if ($cid == Contact::getPublicIdByUserId($uid)) { + $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['cid' => $cid, 'follows' => true]; + $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]; - $total_count = (int)DBA::count('contact-relation', $condition); + $condition = ['cid' => $cid, 'follows' => true]; - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]); + $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); } - 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); - 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,35 +48,62 @@ 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]; + if ($cid == Contact::getPublicIdByUserId($uid)) { + $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['cid' => $cid, 'follows' => true]; + $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]; - $total_count = (int)DBA::count('contact-relation', $condition); + $condition = ['cid' => $cid, 'follows' => true]; - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`relation-cid` < ?", $max_id]); + $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); } - 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); - 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,35 +48,62 @@ 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]; + if ($cid == Contact::getPublicIdByUserId($uid)) { + $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['relation-cid' => $cid, 'follows' => true]; + $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]; - $total_count = (int)DBA::count('contact-relation', $condition); + $condition = ['relation-cid' => $cid, 'follows' => true]; - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]); + $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); } - 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); - 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,35 +48,62 @@ 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]; + if ($cid == Contact::getPublicIdByUserId($uid)) { + $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['relation-cid' => $cid, 'follows' => true]; + $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); + $total_count = (int)DBA::count('contact-relation', $condition); - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]); + 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); } - 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); - if (!empty($min_id)) { $ids = array_reverse($ids); } From 89efa73195b1ccfeb174fc2c2d60c3ba0dae753a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Dec 2022 22:56:56 +0000 Subject: [PATCH 2/5] Fix tests --- src/Module/Api/Twitter/Followers/Ids.php | 2 ++ src/Module/Api/Twitter/Followers/Lists.php | 2 ++ src/Module/Api/Twitter/Friends/Ids.php | 2 ++ src/Module/Api/Twitter/Friends/Lists.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/Module/Api/Twitter/Followers/Ids.php b/src/Module/Api/Twitter/Followers/Ids.php index 3753a790a5..6f89b9ac1f 100644 --- a/src/Module/Api/Twitter/Followers/Ids.php +++ b/src/Module/Api/Twitter/Followers/Ids.php @@ -53,6 +53,8 @@ class Ids extends ContactEndpoint $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; + $total_count = (int)DBA::count('contact', $condition); + if (!empty($max_id)) { $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]); } diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 9983cb4e53..68bc77b987 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -53,6 +53,8 @@ class Lists extends ContactEndpoint $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; + $total_count = (int)DBA::count('contact', $condition); + if (!empty($max_id)) { $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]); } diff --git a/src/Module/Api/Twitter/Friends/Ids.php b/src/Module/Api/Twitter/Friends/Ids.php index 736c78fae2..1d15695d9d 100644 --- a/src/Module/Api/Twitter/Friends/Ids.php +++ b/src/Module/Api/Twitter/Friends/Ids.php @@ -53,6 +53,8 @@ class Ids extends ContactEndpoint $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $total_count = (int)DBA::count('contact', $condition); + if (!empty($max_id)) { $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]); } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 5d8b5bfaca..6a13dbef99 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -53,6 +53,8 @@ class Lists extends ContactEndpoint $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $total_count = (int)DBA::count('contact', $condition); + if (!empty($max_id)) { $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]); } From cfd09663e7a9e263650d991c1ff2773f752e4f72 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Dec 2022 02:33:57 +0000 Subject: [PATCH 3/5] Don't display pending requests --- src/Module/Api/Twitter/Followers/Ids.php | 2 +- src/Module/Api/Twitter/Followers/Lists.php | 2 +- src/Module/Api/Twitter/Friends/Ids.php | 2 +- src/Module/Api/Twitter/Friends/Lists.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Module/Api/Twitter/Followers/Ids.php b/src/Module/Api/Twitter/Followers/Ids.php index 6f89b9ac1f..2a810849be 100644 --- a/src/Module/Api/Twitter/Followers/Ids.php +++ b/src/Module/Api/Twitter/Followers/Ids.php @@ -51,7 +51,7 @@ class Ids extends ContactEndpoint if ($cid == Contact::getPublicIdByUserId($uid)) { $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; + $condition = ['uid' => $uid, 'self' => false, 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; $total_count = (int)DBA::count('contact', $condition); diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 68bc77b987..e969004cb7 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -51,7 +51,7 @@ class Lists extends ContactEndpoint if ($cid == Contact::getPublicIdByUserId($uid)) { $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; + $condition = ['uid' => $uid, 'self' => false, 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; $total_count = (int)DBA::count('contact', $condition); diff --git a/src/Module/Api/Twitter/Friends/Ids.php b/src/Module/Api/Twitter/Friends/Ids.php index 1d15695d9d..d12e082cfa 100644 --- a/src/Module/Api/Twitter/Friends/Ids.php +++ b/src/Module/Api/Twitter/Friends/Ids.php @@ -51,7 +51,7 @@ class Ids extends ContactEndpoint if ($cid == Contact::getPublicIdByUserId($uid)) { $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $condition = ['uid' => $uid, 'self' => false, 'pending' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; $total_count = (int)DBA::count('contact', $condition); diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 6a13dbef99..11c9c4fc39 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -51,7 +51,7 @@ class Lists extends ContactEndpoint if ($cid == Contact::getPublicIdByUserId($uid)) { $params = ['order' => ['pid' => true], 'limit' => $count]; - $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $condition = ['uid' => $uid, 'self' => false, 'pending' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]]; $total_count = (int)DBA::count('contact', $condition); From a2f386cd2f39552cea17210b388b94261ac1f0ea Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Dec 2022 02:43:32 +0000 Subject: [PATCH 4/5] Transmit header before creating user list --- src/Module/Api/Twitter/Followers/Lists.php | 4 ++-- src/Module/Api/Twitter/Friends/Lists.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index e969004cb7..930114c47b 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -110,10 +110,10 @@ class Lists extends ContactEndpoint $ids = array_reverse($ids); } - $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); - self::setLinkHeader(); + $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 11c9c4fc39..45c46f64d7 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -110,10 +110,10 @@ class Lists extends ContactEndpoint $ids = array_reverse($ids); } - $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); - self::setLinkHeader(); + $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); + $this->response->exit('lists', ['lists' => $return]); } } From 5312b23f0389f9992a78366460478d41872f4719 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 12 Dec 2022 03:13:24 +0000 Subject: [PATCH 5/5] Don't send the header --- src/Module/Api/Twitter/Followers/Lists.php | 4 ++-- src/Module/Api/Twitter/Friends/Lists.php | 6 ++--- .../Api/Twitter/Friendships/Incoming.php | 3 +-- src/Module/BaseApi.php | 22 ++++++++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Module/Api/Twitter/Followers/Lists.php b/src/Module/Api/Twitter/Followers/Lists.php index 930114c47b..04bddf83cd 100644 --- a/src/Module/Api/Twitter/Followers/Lists.php +++ b/src/Module/Api/Twitter/Followers/Lists.php @@ -110,10 +110,10 @@ class Lists extends ContactEndpoint $ids = array_reverse($ids); } - self::setLinkHeader(); - $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); + $this->response->setHeader(self::getLinkHeader()); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friends/Lists.php b/src/Module/Api/Twitter/Friends/Lists.php index 45c46f64d7..1abce53646 100644 --- a/src/Module/Api/Twitter/Friends/Lists.php +++ b/src/Module/Api/Twitter/Friends/Lists.php @@ -77,7 +77,7 @@ class Lists extends ContactEndpoint } } else { $params = ['order' => ['cid' => true], 'limit' => $count]; - + $condition = ['relation-cid' => $cid, 'follows' => true]; $total_count = (int)DBA::count('contact-relation', $condition); @@ -110,10 +110,10 @@ class Lists extends ContactEndpoint $ids = array_reverse($ids); } - self::setLinkHeader(); - $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities); + $this->response->setHeader(self::getLinkHeader()); + $this->response->exit('lists', ['lists' => $return]); } } diff --git a/src/Module/Api/Twitter/Friendships/Incoming.php b/src/Module/Api/Twitter/Friendships/Incoming.php index d34d79fae0..89a7b4bcec 100644 --- a/src/Module/Api/Twitter/Friendships/Incoming.php +++ b/src/Module/Api/Twitter/Friendships/Incoming.php @@ -21,7 +21,6 @@ namespace Friendica\Module\Api\Twitter\Friendships; -use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Module\Api\Twitter\ContactEndpoint; use Friendica\Module\BaseApi; @@ -81,7 +80,7 @@ class Incoming extends ContactEndpoint $return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids); - self::setLinkHeader(); + $this->response->setHeader(self::getLinkHeader()); $this->response->exit('incoming', ['incoming' => $return]); } diff --git a/src/Module/BaseApi.php b/src/Module/BaseApi.php index 47557928a9..1d5249ac85 100644 --- a/src/Module/BaseApi.php +++ b/src/Module/BaseApi.php @@ -139,13 +139,13 @@ class BaseApi extends BaseModule } /** - * Set the "link" header with "next" and "prev" links - * @return void + * Get the "link" header with "next" and "prev" links + * @return string */ - protected static function setLinkHeader() + protected static function getLinkHeader(): string { if (empty(self::$boundaries)) { - return; + return ''; } $request = self::$request; @@ -164,7 +164,19 @@ class BaseApi extends BaseModule $prev = $command . '?' . http_build_query($prev_request); $next = $command . '?' . http_build_query($next_request); - header('Link: <' . $next . '>; rel="next", <' . $prev . '>; rel="prev"'); + return 'Link: <' . $next . '>; rel="next", <' . $prev . '>; rel="prev"'; + } + + /** + * Set the "link" header with "next" and "prev" links + * @return void + */ + protected static function setLinkHeader() + { + $header = self::getLinkHeader(); + if (!empty($header)) { + header($header); + } } /**