API: Use "contact" for own relations

This commit is contained in:
Michael 2022-12-11 22:26:30 +00:00
parent baf2f7565a
commit ff5da9bc71
4 changed files with 208 additions and 98 deletions

View 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,6 +48,32 @@ class Ids extends ContactEndpoint
$max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$min_id = $this->getRequestValue($request, 'min_id', 0, 0);
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];
@ -75,6 +102,7 @@ class Ids extends ContactEndpoint
$ids[] = $follower['relation-cid'];
}
DBA::close($followers);
}
if (!empty($min_id)) {
$ids = array_reverse($ids);

View 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,6 +48,32 @@ class Lists extends ContactEndpoint
$max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$min_id = $this->getRequestValue($request, 'min_id', 0, 0);
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];
@ -76,6 +102,7 @@ class Lists extends ContactEndpoint
$ids[] = $follower['relation-cid'];
}
DBA::close($followers);
}
if (!empty($min_id)) {
$ids = array_reverse($ids);

View 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,6 +48,32 @@ class Ids extends ContactEndpoint
$max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$min_id = $this->getRequestValue($request, 'min_id', 0, 0);
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];
@ -75,6 +102,7 @@ class Ids extends ContactEndpoint
$ids[] = $follower['cid'];
}
DBA::close($followers);
}
if (!empty($min_id)) {
$ids = array_reverse($ids);

View 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,6 +48,32 @@ class Lists extends ContactEndpoint
$max_id = $this->getRequestValue($request, 'max_id', 0, 0);
$min_id = $this->getRequestValue($request, 'min_id', 0, 0);
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];
@ -76,6 +102,7 @@ class Lists extends ContactEndpoint
$ids[] = $follower['cid'];
}
DBA::close($followers);
}
if (!empty($min_id)) {
$ids = array_reverse($ids);