From 8a495bd71491c9a2f95897a08a500aa3197c9afb Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 4 Dec 2021 13:08:33 +0000 Subject: [PATCH] [CONTROLLER][Feeds][EVENT] Refactor and add 'FilterNoteList' event --- src/Controller/Feeds.php | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Controller/Feeds.php b/src/Controller/Feeds.php index d4bc88172f..d22ed7c808 100644 --- a/src/Controller/Feeds.php +++ b/src/Controller/Feeds.php @@ -41,6 +41,7 @@ use App\Core\Event; use function App\Core\I18n\_m; use App\Core\VisibilityScope; use App\Entity\Note; +use App\Util\Common; use App\Util\Exception\ClientException; use App\Util\Exception\NotFoundException; use Symfony\Component\HttpFoundation\Request; @@ -53,20 +54,34 @@ class Feeds extends Controller private $message_scope = VisibilityScope::MESSAGE; private $subscriber_scope = VisibilityScope::PUBLIC | VisibilityScope::SUBSCRIBER; - public function public(Request $request) + private function feed(string $title, array $notes) { - $notes = Note::getAllNotes($this->instance_scope); + $actor = Common::actor(); + if (!\is_null($actor)) { + $notes_out = null; + Event::handle('FilterNoteList', [$actor, $notes, &$notes_out]); + $notes = $notes_out; + } $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); return [ '_template' => 'feeds/feed.html.twig', + 'page_title' => $title, 'notes' => $notes_out, - 'page_title' => 'Public feed', ]; } + public function public(Request $request) + { + $notes = Note::getAllNotes($this->instance_scope); + return $this->feed( + title: 'Public feed', + notes: $notes, + ); + } + public function home(Request $request, string $nickname) { try { @@ -102,27 +117,18 @@ class Feeds extends Controller END; $notes = DB::sql($query, ['target_actor_id' => $target->getId()]); - $notes_out = null; - Event::handle('FormatNoteList', [$notes, &$notes_out]); - - return [ - '_template' => 'feeds/feed.html.twig', - 'notes' => $notes_out, - 'page_title' => 'Home feed', - ]; + return $this->feed( + title: 'Home feed', + notes: $notes, + ); } public function network(Request $request) { $notes = Note::getAllNotes($this->public_scope); - - $notes_out = null; - Event::handle('FormatNoteList', [$notes, &$notes_out]); - - return [ - '_template' => 'feeds/feed.html.twig', - 'notes' => $notes_out, - 'page_title' => 'Network feed', - ]; + return $this->feed( + title: 'Network feed', + notes: $notes, + ); } }