]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/FollowRequests.php
Add POST follow request Mastodon API endpoint
[friendica.git] / src / Module / Api / Mastodon / FollowRequests.php
index 16417b46900ab878c817909042c951a8210822c8..55bf70a9549b7153cc247c8b723d4d02b38385ff 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\App\BaseURL;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Model\Introduction;
 use Friendica\Module\Base\Api;
 use Friendica\Network\HTTPException;
 
@@ -24,6 +25,37 @@ class FollowRequests extends Api
                }
        }
 
+       public static function post(array $parameters = [])
+       {
+               parent::post($parameters);
+
+               /** @var Introduction $Intro */
+               $Intro = self::getClass(Introduction::class);
+               $Intro->fetch(['id' => $parameters['id'], 'uid' => self::$current_user_id]);
+
+               $contactId = $Intro->{'contact-id'};
+
+               $relationship = new Mastodon\Relationship();
+               $relationship->id = $contactId;
+
+               switch ($parameters['action']) {
+                       case 'authorize':
+                               $Intro->confirm();
+                               $relationship = Mastodon\Relationship::createFromContact(Contact::getById($contactId));
+                               break;
+                       case 'ignore':
+                               $Intro->ignore();
+                               break;
+                       case 'reject':
+                               $Intro->discard();
+                               break;
+                       default:
+                               throw new HTTPException\BadRequestException('Unexpected action parameter, expecting "authorize", "ignore" or "reject"');
+               }
+
+               System::jsonExit($relationship);
+       }
+
        /**
         * @param array $parameters
         * @throws HTTPException\InternalServerErrorException