3 * @copyright Copyright (C) 2010-2022, 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\Friends;
24 use Friendica\Database\DBA;
25 use Friendica\Model\Contact;
26 use Friendica\Module\Api\Twitter\ContactEndpoint;
27 use Friendica\Module\BaseApi;
30 * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-list
32 class Lists extends ContactEndpoint
34 protected function rawContent(array $request = [])
36 self::checkAllowedScope(self::SCOPE_READ);
37 $uid = BaseApi::getCurrentUserID();
39 // Expected value for user_id parameter: public/user contact id
40 $cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), $uid);
41 $cursor = $this->getRequestValue($request, 'cursor', -1);
42 $skip_status = $this->getRequestValue($request, 'skip_status', false);
43 $include_user_entities = $this->getRequestValue($request, 'include_user_entities', false);
44 $count = $this->getRequestValue($request, 'count', self::DEFAULT_COUNT, 1, self::MAX_COUNT);
47 $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
48 $max_id = $this->getRequestValue($request, 'max_id', 0, 0);
49 $min_id = $this->getRequestValue($request, 'min_id', 0, 0);
51 if ($cid == Contact::getPublicIdByUserId($uid)) {
52 $params = ['order' => ['pid' => true], 'limit' => $count];
54 $condition = ['uid' => $uid, 'self' => false, 'rel' => [Contact::SHARING, Contact::FRIEND]];
56 if (!empty($max_id)) {
57 $condition = DBA::mergeConditions($condition, ["`pid` < ?", $max_id]);
60 if (!empty($since_id)) {
61 $condition = DBA::mergeConditions($condition, ["`pid` > ?", $since_id]);
64 if (!empty($min_id)) {
65 $condition = DBA::mergeConditions($condition, ["`pid` > ?", $min_id]);
67 $params['order'] = ['pid'];
72 foreach (Contact::selectAccountToArray(['pid'], $condition, $params) as $follower) {
73 self::setBoundaries($follower['pid']);
74 $ids[] = $follower['pid'];
77 $params = ['order' => ['cid' => true], 'limit' => $count];
79 $condition = ['relation-cid' => $cid, 'follows' => true];
81 $total_count = (int)DBA::count('contact-relation', $condition);
83 if (!empty($max_id)) {
84 $condition = DBA::mergeConditions($condition, ["`cid` < ?", $max_id]);
87 if (!empty($since_id)) {
88 $condition = DBA::mergeConditions($condition, ["`cid` > ?", $since_id]);
91 if (!empty($min_id)) {
92 $condition = DBA::mergeConditions($condition, ["`cid` > ?", $min_id]);
94 $params['order'] = ['cid'];
99 $followers = DBA::select('contact-relation', ['cid'], $condition, $params);
100 while ($follower = DBA::fetch($followers)) {
101 self::setBoundaries($follower['cid']);
102 $ids[] = $follower['cid'];
104 DBA::close($followers);
107 if (!empty($min_id)) {
108 $ids = array_reverse($ids);
111 $return = self::list($ids, $total_count, $uid, $cursor, $count, $skip_status, $include_user_entities);
113 self::setLinkHeader();
115 $this->response->exit('lists', ['lists' => $return]);