From e72715f1abb85f00464753e17c87489dd0c8f0da Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 11 Aug 2019 11:22:26 +0200 Subject: [PATCH] Respect default user visibility and sensitivity of media --- src/Controller/FediPlanController.php | 2 +- src/Form/ComposeType.php | 19 +++++++++++--- src/Services/Mastodon_api.php | 10 +++++++ src/SocialEntity/MastodonAccount.php | 38 ++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/Controller/FediPlanController.php b/src/Controller/FediPlanController.php index 40d02dc..af022e5 100644 --- a/src/Controller/FediPlanController.php +++ b/src/Controller/FediPlanController.php @@ -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 */ diff --git a/src/Form/ComposeType.php b/src/Form/ComposeType.php index a1611df..dce6bcf 100644 --- a/src/Form/ComposeType.php +++ b/src/Form/ComposeType.php @@ -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 ]); } diff --git a/src/Services/Mastodon_api.php b/src/Services/Mastodon_api.php index afca43d..601ee88 100644 --- a/src/Services/Mastodon_api.php +++ b/src/Services/Mastodon_api.php @@ -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; } diff --git a/src/SocialEntity/MastodonAccount.php b/src/SocialEntity/MastodonAccount.php index 737fe0b..fadb64f 100644 --- a/src/SocialEntity/MastodonAccount.php +++ b/src/SocialEntity/MastodonAccount.php @@ -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; + } + + + }