diff --git a/src/Module/Api/Friendica/Notification/Seen.php b/src/Module/Api/Friendica/Notification/Seen.php index 396779bc38..f9a375f2bd 100644 --- a/src/Module/Api/Friendica/Notification/Seen.php +++ b/src/Module/Api/Friendica/Notification/Seen.php @@ -71,6 +71,7 @@ class Seen extends BaseApi $ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()]; $data = ['status' => $ret]; DI::apiResponse()->exit('statuses', $data, $this->parameters['extension'] ?? null); + return; } // the item can't be found, but we set the notification as seen, so we count this as a success } diff --git a/src/Module/Api/Twitter/Friendships/Show.php b/src/Module/Api/Twitter/Friendships/Show.php new file mode 100644 index 0000000000..2e9a604c72 --- /dev/null +++ b/src/Module/Api/Twitter/Friendships/Show.php @@ -0,0 +1,119 @@ +. + * + */ + +namespace Friendica\Module\Api\Twitter\Friendships; + +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Model\Contact; +use Friendica\Module\Api\Twitter\ContactEndpoint; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException\NotFoundException; + +/** + * @see https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-friendships-show + */ +class Show extends ContactEndpoint +{ + protected function rawContent(array $request = []) + { + self::checkAllowedScope(self::SCOPE_READ); + $uid = BaseApi::getCurrentUserID(); + + $source_cid = BaseApi::getContactIDForSearchterm($_REQUEST['source_screen_name'] ?? '', '', $_REQUEST['source_id'] ?? 0, $uid); + + $target_cid = BaseApi::getContactIDForSearchterm($_REQUEST['target_screen_name'] ?? '', '', $_REQUEST['target_id'] ?? 0, $uid); + + $source = Contact::getById($source_cid); + if (empty($source)) { + throw new NotFoundException('Source not found'); + } + + $target = Contact::getById($target_cid); + if (empty($source)) { + throw new NotFoundException('Target not found'); + } + + $follower = false; + $following = false; + + if ($source_cid == Contact::getPublicIdByUserId($uid)) { + $cdata = Contact::getPublicAndUserContactID($target_cid, $uid); + if (!empty($cdata['user'])) { + $usercontact = Contact::getById($cdata['user'], ['rel']); + switch ($usercontact['rel'] ?? Contact::NOTHING) { + case Contact::FOLLOWER: + $follower = true; + $following = false; + break; + + case Contact::SHARING: + $follower = false; + $following = true; + break; + + case Contact::FRIEND: + $follower = true; + $following = true; + break; + } + } + } else { + $follower = DBA::exists('contact-relation', ['cid' => $source_cid, 'relation-cid' => $target_cid, 'follows' => true]); + $following = DBA::exists('contact-relation', ['relation-cid' => $source_cid, 'cid' => $target_cid, 'follows' => true]); + } + + $relationship = [ + 'relationship' => [ + 'source' => [ + 'id' => $source['id'], + 'id_str' => (string)$source['id'], + 'screen_name' => $source['nick'], + 'following' => $following, + 'followed_by' => $follower, + 'live_following' => false, + 'following_received' => null, + 'following_requested' => null, + 'notifications_enabled' => null, + 'can_dm' => $following && $follower, + 'blocking' => null, + 'blocked_by' => null, + 'muting' => null, + 'want_retweets' => null, + 'all_replies' => null, + 'marked_spam' => null + ], + 'target' => [ + 'id' => $target['id'], + 'id_str' => (string)$target['id'], + 'screen_name' => $target['nick'], + 'following' => $follower, + 'followed_by' => $following, + 'following_received' => null, + 'following_requested' => null + ] + ] + ]; + + DI::apiResponse()->exit('relationship', ['relationship' => $relationship], $this->parameters['extension'] ?? null); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index f2c3ca4612..aadd369904 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -70,6 +70,7 @@ $apiRoutes = [ '/friends/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friends\Lists::class, [R::GET ]], '/friendships/destroy[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friendships\Destroy::class, [ R::POST]], '/friendships/incoming[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friendships\Incoming::class, [R::GET ]], + '/friendships/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\Friendships\Show::class, [R::GET ]], '/friendica' => [ '/activity/{verb:attendmaybe|attendno|attendyes|dislike|like|unattendmaybe|unattendno|unattendyes|undislike|unlike}[.{extension:json|xml|rss|atom}]'