mirror of
https://github.com/friendica/friendica
synced 2025-04-23 18:30:11 +00:00
Reworked friendship API endpoints
This commit is contained in:
parent
87084a3e85
commit
a4ef4589e6
7 changed files with 250 additions and 191 deletions
|
@ -22,8 +22,9 @@
|
|||
namespace Friendica\Module\Api\Twitter\Friends;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Module\Api\Twitter\ContactEndpoint;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-list
|
||||
|
@ -32,33 +33,64 @@ class Lists extends ContactEndpoint
|
|||
{
|
||||
public function rawContent()
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// Expected value for user_id parameter: public/user contact id
|
||||
$contact_id = filter_input(INPUT_GET, 'user_id' , FILTER_VALIDATE_INT);
|
||||
$screen_name = filter_input(INPUT_GET, 'screen_name');
|
||||
$cursor = filter_input(INPUT_GET, 'cursor' , FILTER_VALIDATE_INT);
|
||||
$count = filter_input(INPUT_GET, 'count' , FILTER_VALIDATE_INT, ['options' => [
|
||||
$contact_id = filter_input(INPUT_GET, 'user_id' , FILTER_VALIDATE_INT);
|
||||
$screen_name = filter_input(INPUT_GET, 'screen_name');
|
||||
$cursor = filter_input(INPUT_GET, 'cursor' , FILTER_VALIDATE_INT, ['options' => ['default' => -1]]);
|
||||
$skip_status = filter_input(INPUT_GET, 'skip_status' , FILTER_VALIDATE_BOOLEAN, ['options' => ['default' => false]]);
|
||||
$include_user_entities = filter_input(INPUT_GET, 'include_user_entities', FILTER_VALIDATE_BOOLEAN, ['options' => ['default' => false]]);
|
||||
$count = filter_input(INPUT_GET, 'count' , FILTER_VALIDATE_INT, ['options' => [
|
||||
'default' => self::DEFAULT_COUNT,
|
||||
'min_range' => 1,
|
||||
'max_range' => self::MAX_COUNT,
|
||||
]]);
|
||||
$skip_status = filter_input(INPUT_GET, 'skip_status' , FILTER_VALIDATE_BOOLEAN);
|
||||
$include_user_entities = filter_input(INPUT_GET, 'include_user_entities', FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
// Friendica-specific
|
||||
$since_id = filter_input(INPUT_GET, 'since_id' , FILTER_VALIDATE_INT);
|
||||
$max_id = filter_input(INPUT_GET, 'max_id' , FILTER_VALIDATE_INT, ['options' => [
|
||||
'default' => 1,
|
||||
]]);
|
||||
$since_id = filter_input(INPUT_GET, 'since_id', FILTER_VALIDATE_INT);
|
||||
$max_id = filter_input(INPUT_GET, 'max_id' , FILTER_VALIDATE_INT);
|
||||
$min_id = filter_input(INPUT_GET, 'min_id' , FILTER_VALIDATE_INT);
|
||||
|
||||
// @todo Use Model\Contact\Relation::listFollows($cid, $condition, $count);
|
||||
$cid = BaseApi::getContactIDForSearchterm($screen_name, $contact_id, $uid);
|
||||
|
||||
System::jsonExit(self::list(
|
||||
[Contact::SHARING, Contact::FRIEND],
|
||||
self::getUid($contact_id, $screen_name),
|
||||
$cursor ?? $since_id ?? - $max_id,
|
||||
$count,
|
||||
$skip_status,
|
||||
$include_user_entities
|
||||
));
|
||||
$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);
|
||||
|
||||
if (!empty($min_id)) {
|
||||
array_reverse($ids);
|
||||
}
|
||||
|
||||
$return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities);
|
||||
|
||||
self::setLinkHeader();
|
||||
|
||||
System::jsonExit($return);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue