mirror of
https://github.com/friendica/friendica
synced 2024-11-10 22:22:53 +00:00
Correct value of Mastodon API Account acct field for local users
This commit is contained in:
parent
bef16702c7
commit
c286772fb5
3 changed files with 26 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Friendica\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
|
@ -62,17 +63,21 @@ class Account
|
|||
/**
|
||||
* 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);
|
||||
|
|
|
@ -79,7 +79,7 @@ class Instance
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,15 @@ class FollowRequests extends Api
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
@ -58,7 +67,8 @@ class FollowRequests extends Api
|
|||
/**
|
||||
* @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 = [])
|
||||
{
|
||||
|
@ -66,6 +76,8 @@ class FollowRequests extends Api
|
|||
$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)) {
|
||||
|
@ -94,7 +106,7 @@ class FollowRequests extends Api
|
|||
|
||||
$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'];
|
||||
|
@ -107,13 +119,11 @@ class FollowRequests extends Api
|
|||
$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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue