Add POST follow request Mastodon API endpoint

This commit is contained in:
Hypolite Petovan 2019-12-11 03:50:09 -05:00
parent 1625330e70
commit 2d47952921
3 changed files with 44 additions and 4 deletions

View 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