<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Core\System;
use Friendica\Database\DBA;
+use Friendica\Model\Contact;
use Friendica\Module\Api\Twitter\ContactEndpoint;
use Friendica\Module\BaseApi;
*/
class Ids extends ContactEndpoint
{
- public function rawContent()
+ protected function rawContent(array $request = [])
{
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, ['options' => ['default' => -1]]);
- $stringify_ids = filter_input(INPUT_GET, 'stringify_ids', 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,
- ]]);
- // Friendica-specific
- $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);
-
- $cid = BaseApi::getContactIDForSearchterm($screen_name, $contact_id, $uid);
-
- $params = ['order' => ['cid' => true], 'limit' => $count];
-
- $condition = ['relation-cid' => $cid, 'follows' => true];
+ $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);
- $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'];
+ // 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);
+
+ 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];
+
+ $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);
}
- DBA::close($followers);
if (!empty($min_id)) {
- array_reverse($ids);
+ $ids = array_reverse($ids);
}
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);