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\Friendships;
24 use Friendica\Database\DBA;
26 use Friendica\Model\Contact;
27 use Friendica\Module\Api\Twitter\ContactEndpoint;
28 use Friendica\Module\BaseApi;
29 use Friendica\Network\HTTPException\NotFoundException;
32 * @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show
34 class Show extends ContactEndpoint
36 protected function rawContent(array $request = [])
38 self::checkAllowedScope(self::SCOPE_READ);
39 $uid = BaseApi::getCurrentUserID();
41 $source_cid = BaseApi::getContactIDForSearchterm($request['source_screen_name'] ?? '', '', $request['source_id'] ?? 0, $uid);
43 $target_cid = BaseApi::getContactIDForSearchterm($request['target_screen_name'] ?? '', '', $request['target_id'] ?? 0, $uid);
45 $source = Contact::getById($source_cid);
47 throw new NotFoundException('Source not found');
50 $target = Contact::getById($target_cid);
52 throw new NotFoundException('Target not found');
58 if ($source_cid == Contact::getPublicIdByUserId($uid)) {
59 $cdata = Contact::getPublicAndUserContactID($target_cid, $uid);
60 if (!empty($cdata['user'])) {
61 $usercontact = Contact::getById($cdata['user'], ['rel']);
62 switch ($usercontact['rel'] ?? Contact::NOTHING) {
63 case Contact::FOLLOWER:
68 case Contact::SHARING:
80 $follower = DBA::exists('contact-relation', ['cid' => $source_cid, 'relation-cid' => $target_cid, 'follows' => true]);
81 $following = DBA::exists('contact-relation', ['relation-cid' => $source_cid, 'cid' => $target_cid, 'follows' => true]);
87 'id' => $source['id'],
88 'id_str' => (string)$source['id'],
89 'screen_name' => $source['nick'],
90 'following' => $following,
91 'followed_by' => $follower,
92 'live_following' => false,
93 'following_received' => null,
94 'following_requested' => null,
95 'notifications_enabled' => null,
96 'can_dm' => $following && $follower,
100 'want_retweets' => null,
101 'all_replies' => null,
102 'marked_spam' => null
105 'id' => $target['id'],
106 'id_str' => (string)$target['id'],
107 'screen_name' => $target['nick'],
108 'following' => $follower,
109 'followed_by' => $following,
110 'following_received' => null,
111 'following_requested' => null
116 DI::apiResponse()->exit('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null);