- used `$this->getRequestValue($request, 'foo', <bar>)` instead of `$request['foo'] ?? <bar>` - fixed wrong variable naming - changed double-quotes to single - see https://github.com/friendica/friendica/issues/11631#issuecomment-1196410497
89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
|
*
|
|
* @license GNU AGPL version 3 or any later version
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
namespace Friendica\Module\Api\Twitter\Friends;
|
|
|
|
use Friendica\Core\System;
|
|
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-ids
|
|
*/
|
|
class Ids extends ContactEndpoint
|
|
{
|
|
protected function rawContent(array $request = [])
|
|
{
|
|
self::checkAllowedScope(self::SCOPE_READ);
|
|
$uid = BaseApi::getCurrentUserID();
|
|
|
|
// Expected value for user_id parameter: public/user contact id
|
|
$cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid);
|
|
$cursor = $this->getRequestValue($request, 'cursor', -1);
|
|
$stringify_ids = $this->getRequestValue($request, 'stringify_ids', false);
|
|
$count = $this->getRequestValue($request, 'count', self::DEFAULT_COUNT, 1, self::MAX_COUNT);
|
|
|
|
// Friendica-specific
|
|
$since_id = $this->getRequestValue($request, 'since_id', 0, 0);
|
|
$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'];
|
|
}
|
|
DBA::close($followers);
|
|
|
|
if (!empty($min_id)) {
|
|
$ids = array_reverse($ids);
|
|
}
|
|
|
|
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);
|
|
|
|
self::setLinkHeader();
|
|
|
|
System::jsonExit($return);
|
|
}
|
|
}
|