Merge pull request #7943 from MrPetovan/bug/7920-api-fix-followers-friends-ids
Add relationship filter to api_friends_ids and api_followers_ids
This commit is contained in:
commit
b2ae39db1a
|
@ -3626,6 +3626,7 @@ api_register_func('api/statusnet/version', 'api_statusnet_version', false);
|
|||
*
|
||||
* @param string $type Return type (atom, rss, xml, json)
|
||||
*
|
||||
* @param int $rel A contact relationship constant
|
||||
* @return array|string|void
|
||||
* @throws BadRequestException
|
||||
* @throws ForbiddenException
|
||||
|
@ -3634,7 +3635,7 @@ api_register_func('api/statusnet/version', 'api_statusnet_version', false);
|
|||
* @throws UnauthorizedException
|
||||
* @todo use api_format_data() to return data
|
||||
*/
|
||||
function api_ff_ids($type)
|
||||
function api_ff_ids($type, int $rel)
|
||||
{
|
||||
if (!api_user()) {
|
||||
throw new ForbiddenException();
|
||||
|
@ -3646,26 +3647,29 @@ function api_ff_ids($type)
|
|||
|
||||
$stringify_ids = $_REQUEST['stringify_ids'] ?? false;
|
||||
|
||||
$r = q(
|
||||
"SELECT `pcontact`.`id` FROM `contact`
|
||||
INNER JOIN `contact` AS `pcontact` ON `contact`.`nurl` = `pcontact`.`nurl` AND `pcontact`.`uid` = 0
|
||||
WHERE `contact`.`uid` = %s AND NOT `contact`.`self`",
|
||||
intval(api_user())
|
||||
$contacts = DBA::p("SELECT `pcontact`.`id`
|
||||
FROM `contact`
|
||||
INNER JOIN `contact` AS `pcontact`
|
||||
ON `contact`.`nurl` = `pcontact`.`nurl`
|
||||
AND `pcontact`.`uid` = 0
|
||||
WHERE `contact`.`uid` = ?
|
||||
AND NOT `contact`.`self`
|
||||
AND `contact`.`rel` IN (?, ?)",
|
||||
api_user(),
|
||||
$rel,
|
||||
Contact::FRIEND
|
||||
);
|
||||
if (!DBA::isResult($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($r as $rr) {
|
||||
foreach (DBA::toArray($contacts) as $contact) {
|
||||
if ($stringify_ids) {
|
||||
$ids[] = $rr['id'];
|
||||
$ids[] = $contact['id'];
|
||||
} else {
|
||||
$ids[] = intval($rr['id']);
|
||||
$ids[] = intval($contact['id']);
|
||||
}
|
||||
}
|
||||
|
||||
return api_format_data("ids", $type, ['id' => $ids]);
|
||||
return api_format_data('ids', $type, ['id' => $ids]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3676,11 +3680,14 @@ function api_ff_ids($type)
|
|||
* @return array|string
|
||||
* @throws BadRequestException
|
||||
* @throws ForbiddenException
|
||||
* @throws ImagickException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws UnauthorizedException
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids
|
||||
*/
|
||||
function api_friends_ids($type)
|
||||
{
|
||||
return api_ff_ids($type);
|
||||
return api_ff_ids($type, Contact::SHARING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3691,11 +3698,14 @@ function api_friends_ids($type)
|
|||
* @return array|string
|
||||
* @throws BadRequestException
|
||||
* @throws ForbiddenException
|
||||
* @throws ImagickException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws UnauthorizedException
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids
|
||||
*/
|
||||
function api_followers_ids($type)
|
||||
{
|
||||
return api_ff_ids($type);
|
||||
return api_ff_ids($type, Contact::FOLLOWER);
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
|
|
|
@ -13,6 +13,7 @@ use Friendica\Core\Config\PConfiguration;
|
|||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Test\Util\Database\StaticDatabase;
|
||||
use Monolog\Handler\TestHandler;
|
||||
|
@ -2922,8 +2923,8 @@ class ApiTest extends DatabaseTest
|
|||
*/
|
||||
public function testApiFfIds()
|
||||
{
|
||||
$result = api_ff_ids('json');
|
||||
$this->assertNull($result);
|
||||
$result = api_ff_ids('json', Contact::FOLLOWER);
|
||||
$this->assertEquals(['id' => []], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2945,7 +2946,7 @@ class ApiTest extends DatabaseTest
|
|||
public function testApiFfIdsWithoutAuthenticatedUser()
|
||||
{
|
||||
$_SESSION['authenticated'] = false;
|
||||
api_ff_ids('json');
|
||||
api_ff_ids('json', Contact::FOLLOWER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2956,7 +2957,7 @@ class ApiTest extends DatabaseTest
|
|||
public function testApiFriendsIds()
|
||||
{
|
||||
$result = api_friends_ids('json');
|
||||
$this->assertNull($result);
|
||||
$this->assertEquals(['id' => []], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2967,7 +2968,7 @@ class ApiTest extends DatabaseTest
|
|||
public function testApiFollowersIds()
|
||||
{
|
||||
$result = api_followers_ids('json');
|
||||
$this->assertNull($result);
|
||||
$this->assertEquals(['id' => []], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue