]> git.mxchange.org Git - friendica.git/commitdiff
Added endpoint
authorMichael <heluecht@pirati.ca>
Mon, 29 Nov 2021 06:09:28 +0000 (06:09 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 29 Nov 2021 06:09:28 +0000 (06:09 +0000)
src/Module/Api/Friendica/Notification/Seen.php
src/Module/Api/Twitter/Friendships/Show.php [new file with mode: 0644]
static/routes.config.php

index 396779bc38f66ba493c3af2b64a8b55641003e75..f9a375f2bd1d1f13043fc9094c05c77f125675ff 100644 (file)
@@ -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 (file)
index 0000000..2e9a604
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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);
+       }
+}
index f2c3ca4612d1f1c9cc9b0673458bfc2ff2d71f4e..aadd36990490b1837358822b987fb390caf0c850 100644 (file)
@@ -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}]'