2021-11-26 21:48:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2021-11-26 21:48:13 +00:00
|
|
|
*
|
|
|
|
* @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\Friendships;
|
|
|
|
|
|
|
|
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/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
|
|
|
|
*/
|
|
|
|
class Incoming extends ContactEndpoint
|
|
|
|
{
|
2021-11-27 18:58:24 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2021-11-26 21:48:13 +00:00
|
|
|
{
|
|
|
|
self::checkAllowedScope(self::SCOPE_READ);
|
|
|
|
$uid = BaseApi::getCurrentUserID();
|
|
|
|
|
|
|
|
// Expected value for user_id parameter: public/user contact id
|
2022-01-16 16:40:13 +00:00
|
|
|
$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);
|
|
|
|
|
2021-11-26 21:48:13 +00:00
|
|
|
// Friendica-specific
|
2022-01-16 16:40:13 +00:00
|
|
|
$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);
|
2021-11-26 21:48:13 +00:00
|
|
|
|
2022-03-02 05:05:49 +00:00
|
|
|
$params = ['order' => ['contact-id' => true], 'limit' => $count];
|
2021-11-26 21:48:13 +00:00
|
|
|
|
2022-03-02 05:05:49 +00:00
|
|
|
$condition = ["`uid` = ? AND NOT `blocked` AND NOT `ignore` AND `contact-id` != 0 AND (`suggest-cid` = 0 OR `suggest-cid` IS NULL)", $uid];
|
2021-11-26 21:48:13 +00:00
|
|
|
|
2022-03-02 05:05:49 +00:00
|
|
|
$total_count = (int)DBA::count('intro', $condition);
|
2021-11-26 21:48:13 +00:00
|
|
|
|
|
|
|
if (!empty($max_id)) {
|
2022-03-02 05:05:49 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]);
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($since_id)) {
|
2022-03-02 05:05:49 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]);
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($min_id)) {
|
2022-03-02 05:05:49 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
|
2021-11-26 21:48:13 +00:00
|
|
|
|
2022-03-02 05:05:49 +00:00
|
|
|
$params['order'] = ['contact-id'];
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$ids = [];
|
|
|
|
|
2022-03-02 05:05:49 +00:00
|
|
|
$contacts = DBA::select('intro', ['contact-id'], $condition, $params);
|
2021-11-26 21:48:13 +00:00
|
|
|
while ($contact = DBA::fetch($contacts)) {
|
2022-03-02 05:05:49 +00:00
|
|
|
self::setBoundaries($contact['contact-id']);
|
|
|
|
$ids[] = $contact['contact-id'];
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
DBA::close($contacts);
|
|
|
|
|
|
|
|
if (!empty($min_id)) {
|
2021-12-05 06:22:04 +00:00
|
|
|
$ids = array_reverse($ids);
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);
|
|
|
|
|
|
|
|
self::setLinkHeader();
|
|
|
|
|
2021-12-04 22:32:03 +00:00
|
|
|
$this->response->exit('incoming', ['incoming' => $return]);
|
2021-11-26 21:48:13 +00:00
|
|
|
}
|
|
|
|
}
|