From 141c5f678594e79c9d734b79460597a2b8edb7be Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 2 Jan 2022 23:59:23 +0000 Subject: [PATCH] [COMPONENT][Collection][CONTROLLER][Collection] Add utility method to call Feed::query in Collection, which handles getting and passing the page --- components/Collection/Util/Controller/Collection.php | 5 +++++ components/Conversation/Controller/Conversation.php | 3 +-- components/Conversation/Controller/Reply.php | 4 ++-- components/Feed/Controller/Feeds.php | 7 ++----- components/FreeNetwork/Controller/Feeds.php | 7 ++----- components/Search/Controller/Search.php | 3 +-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/components/Collection/Util/Controller/Collection.php b/components/Collection/Util/Controller/Collection.php index b5efe91365..ca605c65a8 100644 --- a/components/Collection/Util/Controller/Collection.php +++ b/components/Collection/Util/Controller/Collection.php @@ -5,7 +5,12 @@ declare(strict_types = 1); namespace Component\Collection\Util\Controller; use App\Core\Controller; +use Component\Feed\Feed; class Collection extends Controller { + public function query(string $query, ?string $language = null, ?Actor $actor = null) + { + return Feed::query($query, $this->int('page') ?? 1, $language, $actor); + } } diff --git a/components/Conversation/Controller/Conversation.php b/components/Conversation/Controller/Conversation.php index edb40b07f8..ad84eda714 100644 --- a/components/Conversation/Controller/Conversation.php +++ b/components/Conversation/Controller/Conversation.php @@ -34,7 +34,6 @@ use App\Util\Common; use App\Util\Exception\RedirectException; use Component\Collection\Util\Controller\FeedController; use Component\Conversation\Entity\ConversationMute; -use Component\Feed\Feed; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; @@ -47,7 +46,7 @@ class Conversation extends FeedController */ public function showConversation(Request $request, int $conversation_id) { - $data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1); + $data = $this->query(query: "note-conversation:{$conversation_id}"); $notes = $data['notes']; return [ '_template' => 'collection/notes.html.twig', diff --git a/components/Conversation/Controller/Reply.php b/components/Conversation/Controller/Reply.php index d03be7a972..47db43f08d 100644 --- a/components/Conversation/Controller/Reply.php +++ b/components/Conversation/Controller/Reply.php @@ -59,8 +59,8 @@ class Reply extends FeedController } $conversation_id = $note->getConversationId(); - $data = Feed::query(query: "note-conversation:{$conversation_id}", page: $this->int('p') ?? 1); - $notes = $data['notes']; + $data = $this->query(query: "note-conversation:{$conversation_id}"); + $notes = $data['notes']; return [ '_template' => 'collection/notes.html.twig', 'notes' => $notes, diff --git a/components/Feed/Controller/Feeds.php b/components/Feed/Controller/Feeds.php index 5b0382df39..56a01ef2dc 100644 --- a/components/Feed/Controller/Feeds.php +++ b/components/Feed/Controller/Feeds.php @@ -38,7 +38,6 @@ namespace Component\Feed\Controller; use function App\Core\I18n\_m; use App\Util\Common; use Component\Collection\Util\Controller\FeedController; -use Component\Feed\Feed; use Symfony\Component\HttpFoundation\Request; class Feeds extends FeedController @@ -48,9 +47,8 @@ class Feeds extends FeedController */ public function public(Request $request): array { - $data = Feed::query( + $data = $this->query( query: 'note-local:true', - page: $this->int('p'), language: Common::actor()?->getTopLanguage()?->getLocale(), ); return [ @@ -67,9 +65,8 @@ class Feeds extends FeedController { $user = Common::ensureLoggedIn(); $actor = $user->getActor(); - $data = Feed::query( + $data = $this->query( query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business', - page: $this->int('p'), language: $actor->getTopLanguage()->getLocale(), actor: $actor, ); diff --git a/components/FreeNetwork/Controller/Feeds.php b/components/FreeNetwork/Controller/Feeds.php index 8961a36f95..f9db70b7fe 100644 --- a/components/FreeNetwork/Controller/Feeds.php +++ b/components/FreeNetwork/Controller/Feeds.php @@ -38,7 +38,6 @@ use App\Core\DB\DB; use function App\Core\I18n\_m; use App\Util\Common; use Component\Collection\Util\Controller\FeedController; -use Component\Feed\Feed; use Symfony\Component\HttpFoundation\Request; class Feeds extends FeedController @@ -52,9 +51,8 @@ class Feeds extends FeedController public function network(Request $request): array { Common::ensureLoggedIn(); - $data = Feed::query( + $data = $this->query( query: 'note-local:false', - page: $this->int('p'), language: Common::actor()?->getTopLanguage()?->getLocale(), ); return [ @@ -101,9 +99,8 @@ class Feeds extends FeedController public function federated(Request $request): array { Common::ensureLoggedIn(); - $data = Feed::query( + $data = $this->query( query: '', - page: $this->int('p'), language: Common::actor()?->getTopLanguage()?->getLocale(), ); return [ diff --git a/components/Search/Controller/Search.php b/components/Search/Controller/Search.php index 0d286be854..13c7a8f8cc 100644 --- a/components/Search/Controller/Search.php +++ b/components/Search/Controller/Search.php @@ -31,7 +31,6 @@ use App\Util\Exception\RedirectException; use App\Util\Form\FormFields; use App\Util\Formatting; use Component\Collection\Util\Controller\FeedController; -use Component\Feed\Feed; use Component\Search as Comp; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -49,7 +48,7 @@ class Search extends FeedController $language = !\is_null($actor) ? $actor->getTopLanguage()->getLocale() : null; $q = $this->string('q'); - $data = Feed::query(query: $q, page: $this->int('p'), language: $language); + $data = $this->query(query: $q, language: $language); $notes = $data['notes']; $actors = $data['actors'];