Respect default user visibility and sensitivity of media

This commit is contained in:
Thomas 2019-08-11 11:22:26 +02:00
parent 50b38ad5ee
commit e72715f1ab
4 changed files with 64 additions and 5 deletions

View file

@ -126,7 +126,7 @@ class FediPlanController extends AbstractController
{
$compose = new Compose();
$form = $this->createForm(ComposeType::class, $compose);
$form = $this->createForm(ComposeType::class, $compose, ['user' => $this->getUser()]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var $data Compose */

View file

@ -36,6 +36,17 @@ class ComposeType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
/**@var $user \App\SocialEntity\MastodonAccount**/
$user = $options['user'];
if( $user->getDefaultSensitivity()) {
$checkbox = [
'required' => false,
'attr' => ['checked' => 'checked'],
];
}else {
$checkbox = ['required' => false];
}
$builder->add('content_warning', TextType::class, ['required' => false]);
$builder->add('content', TextareaType::class, ['required' => false]);
@ -46,10 +57,11 @@ class ComposeType extends AbstractType {
'status.visibility.unlisted' => 'unlisted',
'status.visibility.private' => 'private',
'status.visibility.direct' => 'direct',
]
],
'data' => $user->getDefaultVisibility(),
]);
$builder->add('timeZone', TimezoneType::class);
$builder->add('sensitive', CheckboxType::class, ['required' => false]);
$builder->add('sensitive', CheckboxType::class, $checkbox);
$builder->add('scheduled_at', \Symfony\Component\Form\Extension\Core\Type\DateTimeType::class,[
'widget' => 'single_text',
"data" => new \DateTime()
@ -63,7 +75,8 @@ class ComposeType extends AbstractType {
{
$resolver->setDefaults([
'data_class' => Compose::class,
'translation_domain' => 'fediplan'
'translation_domain' => 'fediplan',
'user' => null
]);
}

View file

@ -1237,6 +1237,16 @@ class Mastodon_api {
$MastodonAccount->addField($field);
}
}
if( $accountParams['source'] && $accountParams['source']['privacy']){
$MastodonAccount->setDefaultVisibility($accountParams['source']['privacy']);
}else{
$MastodonAccount->setDefaultVisibility("public");
}
if( $accountParams['source'] ){
$MastodonAccount->setDefaultSensitivity($accountParams['source']['sensitive']?1:0);
}else{
$MastodonAccount->setDefaultSensitivity(0);
}
return $MastodonAccount;
}

View file

@ -55,7 +55,9 @@ class MastodonAccount
private $Emojis;
private $default_sensitivity;
private $default_visibility;
public function __construct()
@ -386,5 +388,39 @@ class MastodonAccount
return $this;
}
/**
* @return mixed
*/
public function getDefaultSensitivity()
{
return $this->default_sensitivity;
}
/**
* @param mixed $default_sensitivity
*/
public function setDefaultSensitivity($default_sensitivity): void
{
$this->default_sensitivity = $default_sensitivity;
}
/**
* @return mixed
*/
public function getDefaultVisibility()
{
return $this->default_visibility;
}
/**
* @param mixed $default_visibility
*/
public function setDefaultVisibility($default_visibility): void
{
$this->default_visibility = $default_visibility;
}
}