]> git.mxchange.org Git - friendica.git/blob - src/Module/Api/Twitter/Friendships/Incoming.php
spelling: days
[friendica.git] / src / Module / Api / Twitter / Friendships / Incoming.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Api\Twitter\Friendships;
23
24 use Friendica\Database\DBA;
25 use Friendica\Module\Api\Twitter\ContactEndpoint;
26 use Friendica\Module\BaseApi;
27
28 /**
29  * @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
30  */
31 class Incoming extends ContactEndpoint
32 {
33         protected function rawContent(array $request = [])
34         {
35                 self::checkAllowedScope(self::SCOPE_READ);
36                 $uid = BaseApi::getCurrentUserID();
37
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);
42
43                 // Friendica-specific
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);
47
48                 $params = ['order' => ['contact-id' => true], 'limit' => $count];
49
50                 $condition = ["`uid` = ? AND NOT `blocked` AND NOT `ignore` AND `contact-id` != 0 AND (`suggest-cid` = 0 OR `suggest-cid` IS NULL)", $uid];
51
52                 $total_count = (int)DBA::count('intro', $condition);
53
54                 if (!empty($max_id)) {
55                         $condition = DBA::mergeConditions($condition, ["`contact-id` < ?", $max_id]);
56                 }
57
58                 if (!empty($since_id)) {
59                         $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $since_id]);
60                 }
61
62                 if (!empty($min_id)) {
63                         $condition = DBA::mergeConditions($condition, ["`contact-id` > ?", $min_id]);
64
65                         $params['order'] = ['contact-id'];
66                 }
67
68                 $ids = [];
69
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'];
74                 }
75                 DBA::close($contacts);
76
77                 if (!empty($min_id)) {
78                         $ids = array_reverse($ids);
79                 }
80
81                 $return = self::ids($ids, $total_count, $cursor, $count, $stringify_ids);
82
83                 $this->response->setHeader(self::getLinkHeader());
84
85                 $this->response->exit('incoming', ['incoming' => $return]);
86         }
87 }