[Posting] Fix form name and remove unused recycle route and controller

This commit is contained in:
Hugo Sales 2020-09-05 21:28:53 +00:00 committed by Hugo Sales
parent 9865798766
commit 9573cab4cb
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 8 additions and 41 deletions

View File

@ -1,6 +1,7 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
@ -15,6 +16,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Component\Posting\Controller;
@ -43,13 +45,13 @@ class Post
throw new ClientException(_m('No such note'));
}
$actor_id = Common::ensureLoggedIn()->getActor()->getId();
$actor_id = Common::ensureLoggedIn()->getId();
$form = Form::create([
['reply_to', HiddenType::class, ['data' => (int) $reply_to]],
['content', TextareaType::class, ['label' => ' ']],
['attachments', FileType::class, ['label' => ' ', 'multiple' => true, 'required' => false]],
['save', SubmitType::class, ['label' => _m('Submit')]],
['reply', SubmitType::class, ['label' => _m('Submit')]],
]);
$form->handleRequest($request);
@ -70,42 +72,6 @@ class Post
];
}
public function recycle(Request $request, string $repeat_of)
{
$note = DB::find('note', ['id' => $repeat_of]);
$content_repeat = DB::dql('select n.content from App\Entity\Note n ' .
'where n.reply_to = ' . $repeat_of
);
if ($note == null) {
throw new ClientException(_m('No such note'));
}
$actor_id = Common::ensureLoggedIn()->getActor()->getId();
$form = Form::create([
['repeat_of', HiddenType::class, ['data' => (int) $repeat_of]],
['save', SubmitType::class, ['label' => _m('Submit')]],
]);
$form->handleRequest($request);
if ($form->isSubmitted()) {
$data = $form->getData();
if ($form->isValid()) {
self::storeNote($actor_id, $data[$content_repeat], $data['attachments'], $is_local = true, $data['reply_to'], $data['repeat_of']);
} else {
// TODO display errors
}
}
return [
'_template' => 'note/reply.html.twig',
'note' => $note,
'reply' => $form->createView(),
];
}
public static function storeNote(int $actor_id, string $content, array $attachments, bool $is_local, ?int $reply_to = null, ?int $repeat_of = null)
{
$note = Note::create(['gsactor_id' => $actor_id, 'content' => $content, 'is_local' => $is_local, 'reply_to' => $reply_to, 'repeat_of' => $repeat_of]);

View File

@ -25,6 +25,7 @@ use App\Core\Form;
use function App\Core\I18n\_m;
use App\Core\Module;
use App\Util\Common;
use App\Util\Exception\RedirectException;
use Component\Posting\Controller as C;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
@ -36,16 +37,15 @@ class Posting extends Module
public function onAddRoute($r)
{
$r->connect('note_reply', '/note/reply/{reply_to<\d*>}', [C\Post::class, 'reply']);
$r->connect('note_recycle', '/main/all', [C\Post::class, 'recycle']);
}
public function onStartTwigPopulateVars(array &$vars)
{
if (Common::user() == null) {
if (($user = Common::user()) == null) {
return;
}
$actor_id = Common::actor()->getId();
$actor_id = $user->getId();
$to_tags = [];
foreach (DB::dql('select c.tag from App\Entity\GSActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]) as $t) {
$t = $t['tag'];
@ -69,6 +69,7 @@ class Posting extends Module
$data = $form->getData();
if ($form->isValid()) {
C\Post::storeNote($actor_id, $data['content'], $data['attachments'], $is_local = true);
throw new RedirectException();
} else {
// TODO Display error
}