3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Twitter\Friendships;
24 use Friendica\Database\DBA;
25 use Friendica\Module\Api\Twitter\ContactEndpoint;
26 use Friendica\Module\BaseApi;
29 * @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
31 class Incoming extends ContactEndpoint
33 protected function rawContent(array $request = [])
35 self::checkAllowedScope(self::SCOPE_READ);
36 $uid = BaseApi::getCurrentUserID();
38 // Expected value for user_id parameter: public/user contact id
39 $cursor = $this->getRequestValue($request, 'cursor', -1);
40 $stringify_ids = $this->getRequestValue($request, 'stringify_ids', false);
41 $count = $this->getRequestValue($request, 'count', self::DEFAULT_COUNT, 1, self::MAX_COUNT);
44 $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
45 $max_id = $this->getRequestValue($request, 'max_id', 0, 0);
46 $min_id = $this->getRequestValue($request, 'min_id', 0, 0);
48 $params = ['order' => ['contact-id' => true], 'limit' => $count];
50 $condition = ["`uid` = ? AND NOT `blocked` AND NOT `ignore` AND `contact-id` != 0 AND (`suggest-cid` = 0 OR `suggest-cid` IS NULL)", $uid];
52 $total_count = (int)DBA::count('intro', $condition);
54 if (!empty($max_id)) {
55 $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]);
58 if (!empty($since_id)) {
59 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]);
62 if (!empty($min_id)) {
63 $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
65 $params['order'] = ['contact-id'];
70 $contacts = DBA::select('intro', ['contact-id'], $condition, $params);
71 while ($contact = DBA::fetch($contacts)) {
72 self::setBoundaries($contact['contact-id']);
73 $ids[] = $contact['contact-id'];
75 DBA::close($contacts);
77 if (!empty($min_id)) {
78 $ids = array_reverse($ids);
81 $return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);
83 $this->response->setHeader(self::getLinkHeader());
85 $this->response->exit('incoming', ['incoming' => $return]);