namespace Friendica\Api\Mastodon;
+use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
/**
* Creates an account record from a public contact record. Expects all contact table fields to be set.
*
- * @param array $publicContact Full contact table record with uid = 0
- * @param array $apcontact Optional full apcontact table record
+ * @param BaseURL $baseUrl
+ * @param array $publicContact Full contact table record with uid = 0
+ * @param array $apcontact Optional full apcontact table record
* @return Account
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function create(array $publicContact, array $apcontact = [])
+ public static function create(BaseURL $baseUrl, array $publicContact, array $apcontact = [])
{
$account = new Account();
$account->id = $publicContact['id'];
$account->username = $publicContact['nick'];
- $account->acct = $publicContact['addr'];
+ $account->acct =
+ strpos($publicContact['url'], $baseUrl->get() . '/') === 0 ?
+ $publicContact['nick'] :
+ $publicContact['addr'];
$account->display_name = $publicContact['name'];
$account->locked = !empty($apcontact['manually-approve']);
$account->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::ATOM);
if (!empty($administrator)) {
$adminContact = DBA::selectFirst('contact', [], ['nick' => $administrator['nickname'], 'self' => true]);
$apcontact = APContact::getByURL($adminContact['url'], false);
- $instance->contact_account = Account::create($adminContact, $apcontact);
+ $instance->contact_account = Account::create($baseUrl, $adminContact, $apcontact);
}
}
}
}
+ /**
+ * @param array $parameters
+ * @throws HTTPException\BadRequestException
+ * @throws HTTPException\ForbiddenException
+ * @throws HTTPException\NotFoundException
+ * @throws HTTPException\UnauthorizedException
+ * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#accept-follow
+ * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#reject-follow
+ */
public static function post(array $parameters = [])
{
parent::post($parameters);
/**
* @param array $parameters
* @throws HTTPException\InternalServerErrorException
- * @see https://docs.joinmastodon.org/api/rest/follow-requests/#get-api-v1-follow-requests
+ * @throws \ImagickException
+ * @see https://docs.joinmastodon.org/methods/accounts/follow_requests#pending-follows
*/
public static function rawContent(array $parameters = [])
{
$max_id = $_GET['max_id'] ?? null;
$limit = intval($_GET['limit'] ?? 40);
+ $baseUrl = DI::baseUrl();
+
if (isset($since_id) && isset($max_id)) {
$condition = ['`uid` = ? AND NOT `ignore` AND `id` > ? AND `id` < ?', self::$current_user_id, $since_id, $max_id];
} elseif (isset($since_id)) {
$publicContact = Contact::getById($cdata['public']);
$apcontact = APContact::getByURL($publicContact['url'], false);
- $account = Mastodon\Account::create($publicContact, $apcontact);
+ $account = Mastodon\Account::create($baseUrl, $publicContact, $apcontact);
// Not ideal, the same "account" can have multiple ids depending on the context
$account->id = $intro['id'];
$base_query['limit'] = $limit;
}
- $BaseURL = DI::baseUrl();
-
$links = [];
if ($count > $limit) {
- $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $intros[count($intros) - 1]['id']]) . '>; rel="next"';
+ $links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['max_id' => $intros[count($intros) - 1]['id']]) . '>; rel="next"';
}
- $links[] = '<' . $BaseURL->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $intros[0]['id']]) . '>; rel="prev"';
+ $links[] = '<' . $baseUrl->get() . '/api/v1/follow_requests?' . http_build_query($base_query + ['since_id' => $intros[0]['id']]) . '>; rel="prev"';
header('Link: ' . implode(', ', $links));