Merge remote-tracking branch 'upstream/2023.09-rc' into server-discovery

This commit is contained in:
Michael 2023-11-27 19:28:13 +00:00
commit 67f727e3b3
6 changed files with 31 additions and 36 deletions

View file

@ -224,10 +224,10 @@ class Smilies
if (strlen($word) < 2) { if (strlen($word) < 2) {
continue; continue;
} }
$ord1 = ord($word); $ord1 = ord($word[0]);
$ord2 = ord($word[1]); $ord2 = ord($word[1]);
// A smiley shortcode must not begin or end with whitespaces. // A smiley shortcode must not begin or end with whitespaces.
if (ctype_space($ord1) || ctype_space($word[strlen($word) - 1])) { if (ctype_space($word[0]) || ctype_space($word[strlen($word) - 1])) {
continue; continue;
} }
$ord1_bitset |= 1 << ($ord1 & 31); $ord1_bitset |= 1 << ($ord1 & 31);

View file

@ -26,6 +26,8 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Factory\Api\Mastodon\Account as AccountFactory;
use Friendica\Model\User;
use Friendica\Module\Api\ApiResponse; use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Object\Api\Mastodon\Instance as InstanceEntity; use Friendica\Object\Api\Mastodon\Instance as InstanceEntity;
@ -46,12 +48,16 @@ class Instance extends BaseApi
/** @var IManageConfigValues */ /** @var IManageConfigValues */
private $config; private $config;
public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = []) /** @var AccountFactory */
private $accountFactory;
public function __construct(AccountFactory $accountFactory, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = [])
{ {
parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->database = $database; $this->database = $database;
$this->config = $config; $this->config = $config;
$this->accountFactory = $accountFactory;
} }
/** /**
@ -62,7 +68,13 @@ class Instance extends BaseApi
*/ */
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
$this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules(), $this->buildConfigurationInfo())); $administrator = User::getFirstAdmin(['nickname']);
if ($administrator) {
$adminContact = $this->database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]);
$contact_account = $this->accountFactory->createFromUriId($adminContact['uri-id']);
}
$this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, $this->buildConfigurationInfo(), $contact_account ?? null, System::getRules()));
} }
private function buildConfigurationInfo(): InstanceV2Entity\Configuration private function buildConfigurationInfo(): InstanceV2Entity\Configuration

View file

@ -27,10 +27,8 @@ use Friendica\BaseDataTransferObject;
use Friendica\Contact\Header; use Friendica\Contact\Header;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Register; use Friendica\Module\Register;
use Friendica\Network\HTTPException;
use Friendica\Object\Api\Mastodon\InstanceV2\Configuration; use Friendica\Object\Api\Mastodon\InstanceV2\Configuration;
/** /**
@ -68,23 +66,14 @@ class Instance extends BaseDataTransferObject
protected $approval_required; protected $approval_required;
/** @var bool */ /** @var bool */
protected $invites_enabled; protected $invites_enabled;
/** @var Account|null */
/** @var Configuration */ /** @var Configuration */
protected $configuration; protected $configuration;
/** @var Account|null */
protected $contact_account = null; protected $contact_account = null;
/** @var array */ /** @var array */
protected $rules = []; protected $rules = [];
/** public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, Configuration $configuration, ?Account $contact_account, array $rules)
* @param IManageConfigValues $config
* @param BaseURL $baseUrl
* @param Database $database
* @param array $rules
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
* @throws \ImagickException
*/
public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [], Configuration $configuration)
{ {
$register_policy = intval($config->get('config', 'register_policy')); $register_policy = intval($config->get('config', 'register_policy'));
@ -102,13 +91,7 @@ class Instance extends BaseDataTransferObject
$this->approval_required = ($register_policy == Register::APPROVE); $this->approval_required = ($register_policy == Register::APPROVE);
$this->invites_enabled = false; $this->invites_enabled = false;
$this->configuration = $configuration; $this->configuration = $configuration;
$this->contact_account = []; $this->contact_account = $contact_account ?? [];
$this->rules = $rules; $this->rules = $rules;
$administrator = User::getFirstAdmin(['nickname']);
if ($administrator) {
$adminContact = $database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]);
$this->contact_account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);
}
} }
} }

View file

@ -606,7 +606,7 @@ class Processor
} catch (\Exception $exception) { } catch (\Exception $exception) {
Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]); Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]);
return true; return true;
} }
// @todo To ensure that the remote system is working correctly, we can check if the "Content-Type" contains JSON // @todo To ensure that the remote system is working correctly, we can check if the "Content-Type" contains JSON
if (in_array($curlResult->getReturnCode(), [401, 404])) { if (in_array($curlResult->getReturnCode(), [401, 404])) {
@ -1114,7 +1114,7 @@ class Processor
if (!empty($item['source']) && DI::config()->get('debug', 'store_source')) { if (!empty($item['source']) && DI::config()->get('debug', 'store_source')) {
Post\Activity::insert($item['uri-id'], $item['source']); Post\Activity::insert($item['uri-id'], $item['source']);
} }
continue; continue;
} }
@ -1613,7 +1613,7 @@ class Processor
} else { } else {
return null; return null;
} }
$ldactivity['recursion-depth'] = !empty($child['recursion-depth']) ? $child['recursion-depth'] + 1 : 0; $ldactivity['recursion-depth'] = !empty($child['recursion-depth']) ? $child['recursion-depth'] + 1 : 0;
if ($object_actor != $actor) { if ($object_actor != $actor) {
@ -1725,7 +1725,7 @@ class Processor
$tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []); $tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []);
if (!empty($tags)) { if (!empty($tags)) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (($tag['type'] != 'Hashtag') && !strpos($tag['type'], ':Hashtag')) { if (($tag['type'] != 'Hashtag') && !strpos($tag['type'], ':Hashtag') || empty($tag['name'])) {
continue; continue;
} }
$messageTags[] = ltrim(mb_strtolower($tag['name']), '#'); $messageTags[] = ltrim(mb_strtolower($tag['name']), '#');

View file

@ -2,11 +2,11 @@
<div class="field select"> <div class="field select">
<label for="id_{{$field.0}}">{{$field.1}}</label> <label for="id_{{$field.0}}">{{$field.1}}</label>
<select name="{{$field.0}}" id="id_{{$field.0}}" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}> <select name="{{$field.0}}" id="id_{{$field.0}}" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
{{foreach $field.4 as $opt=>$val}} {{foreach $field.4 as $opt => $val}}
{{if $field.5=='multiple'}} {{if $field.5 == 'multiple'}}
<option value="{{$opt}}" dir="auto"{{if $opt|in_array:$field.2}} selected="selected"{{/if}}>{{$val}}</option> <option value="{{$opt}}" dir="auto"{{if in_array($opt, $field.2)}} selected="selected"{{/if}}>{{$val}}</option>
{{else}} {{else}}
<option value="{{$opt}}" dir="auto"{{if $opt==$field.2}} selected="selected"{{/if}}>{{$val}}</option> <option value="{{$opt}}" dir="auto"{{if $opt == $field.2}} selected="selected"{{/if}}>{{$val}}</option>
{{/if}} {{/if}}
{{/foreach}} {{/foreach}}
</select> </select>

View file

@ -2,11 +2,11 @@
<div class="form-group field select"> <div class="form-group field select">
<label for="id_{{$field.0}}">{{$field.1}}</label> <label for="id_{{$field.0}}">{{$field.1}}</label>
<select name="{{$field.0}}" id="id_{{$field.0}}" class="form-control" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}> <select name="{{$field.0}}" id="id_{{$field.0}}" class="form-control" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
{{foreach $field.4 as $opt=>$val}} {{foreach $field.4 as $opt => $val}}
{{if $field.5=='multiple'}} {{if $field.5 == 'multiple'}}
<option value="{{$opt}}" {{if $opt|in_array:$field.2}}selected="selected"{{/if}}>{{$val}}</option> <option value="{{$opt}}" {{if in_array($opt, $field.2)}}selected="selected"{{/if}}>{{$val}}</option>
{{else}} {{else}}
<option value="{{$opt}}" {{if $opt==$field.2}}selected="selected"{{/if}}>{{$val}}</option> <option value="{{$opt}}" {{if $opt == $field.2}}selected="selected"{{/if}}>{{$val}}</option>
{{/if}} {{/if}}
{{/foreach}} {{/foreach}}
</select> </select>