From cee2d143c9cff99be30b8b35c2190cd9cfd85dc1 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Wed, 16 Feb 2022 06:58:11 +0000 Subject: [PATCH] [COMPONENT][Posting] Add storeLocalPage Minor refactoring and bug fixing --- components/Blog/Controller/Post.php | 17 +++---------- components/Posting/Posting.php | 38 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/components/Blog/Controller/Post.php b/components/Blog/Controller/Post.php index 6a4056c3ff..2a466c4c6d 100644 --- a/components/Blog/Controller/Post.php +++ b/components/Blog/Controller/Post.php @@ -27,6 +27,7 @@ use App\Core\ActorLocalRoles; use App\Core\Controller; use App\Core\Event; use App\Core\Form; +use Symfony\Component\HttpFoundation\RedirectResponse; use function App\Core\I18n\_m; use App\Core\Router\Router; use App\Core\VisibilityScope; @@ -138,7 +139,7 @@ class Post extends Controller $extra_args = []; Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]); - Posting::storeLocalNote( + $note = Posting::storeLocalPage( actor: $actor, content: $data['content'], content_type: $content_type, @@ -150,19 +151,7 @@ class Post extends Controller process_note_content_extra_args: $extra_args, ); - try { - if ($request->query->has('from')) { - $from = $request->query->get('from'); - if (str_contains($from, '#')) { - [$from, $fragment] = explode('#', $from); - } - Router::match($from); - throw new RedirectException(url: $from . (isset($fragment) ? '#' . $fragment : '')); - } - } catch (ResourceNotFoundException $e) { - // continue - } - throw new RedirectException(); + return new RedirectResponse($note->getConversationUrl()); } } catch (FormSizeFileException $e) { throw new ClientException(_m('Invalid file size given'), previous: $e); diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index a5d1ac8acd..b1d67f4e81 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -210,6 +210,44 @@ class Posting extends Component return Event::next; } + /** + * @throws DuplicateFoundException + * @throws ClientException + * @throws ServerException + */ + public static function storeLocalPage( + Actor $actor, + ?string $content, + string $content_type, + ?string $locale = null, + ?VisibilityScope $scope = null, + array $targets = [], + null|int|Note $reply_to = null, + array $attachments = [], + array $processed_attachments = [], + array $process_note_content_extra_args = [], + bool $notify = true, + ?string $rendered = null, + string $source = 'web', + ): Note { + $note = self::storeLocalNote( + actor: $actor, + content: $content, + content_type: $content_type, + locale: $locale, + scope: $scope, + targets: $targets, + reply_to: $reply_to, + attachments: $attachments, + processed_attachments: $processed_attachments, + process_note_content_extra_args: $process_note_content_extra_args, + notify: $notify, + rendered: $rendered, + source: $source + ); + return $note->setType(NoteType::PAGE); + } + /** * Store the given note with $content and $attachments, created by * $actor_id, possibly as a reply to note $reply_to and with flag