From 1056bc661fc3492e9b26972156773377d6898893 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 10 Jan 2022 10:17:05 +0000 Subject: [PATCH] [COMPONENT][FreeNetwork] Restore Galaxy feed --- components/Collection/Collection.php | 5 ++++- .../Collection/Util/Controller/Collection.php | 2 +- components/Collection/Util/Parser.php | 4 ++-- components/Feed/Controller/Feeds.php | 14 +++----------- components/FreeNetwork/Controller/Feeds.php | 11 +++-------- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/components/Collection/Collection.php b/components/Collection/Collection.php index b44ddf31e7..54b217cec6 100644 --- a/components/Collection/Collection.php +++ b/components/Collection/Collection.php @@ -68,8 +68,11 @@ class Collection extends Component { if (str_contains($term, ':')) { $term = explode(':', $term); - if (Formatting::startsWith($term[0], 'note-')) { + if (Formatting::startsWith($term[0], 'note')) { switch ($term[0]) { + case 'notes-all': + $note_expr = $eb->neq('note.created', null); + break; case 'note-local': $note_expr = $eb->eq('note.is_local', filter_var($term[1], \FILTER_VALIDATE_BOOLEAN)); break; diff --git a/components/Collection/Util/Controller/Collection.php b/components/Collection/Util/Controller/Collection.php index da8e5ac04f..77bcdb82c5 100644 --- a/components/Collection/Util/Controller/Collection.php +++ b/components/Collection/Util/Controller/Collection.php @@ -14,7 +14,7 @@ class Collection extends Controller public function query(string $query, ?string $locale = null, ?Actor $actor = null) { $actor ??= Common::actor(); - $locale ??= $actor?->getTopLanguage()?->getLocale() ?? Common::currentLanguage()->getLocale(); + $locale ??= Common::currentLanguage()->getLocale(); return CollectionModule::query($query, $this->int('page') ?? 1, $locale, $actor); } } diff --git a/components/Collection/Util/Parser.php b/components/Collection/Util/Parser.php index 993eb80054..e16e246756 100644 --- a/components/Collection/Util/Parser.php +++ b/components/Collection/Util/Parser.php @@ -82,13 +82,13 @@ abstract class Parser if (\is_null($note_res) && \is_null($actor_res)) { // @phpstan-ignore-line throw new ServerException("No one claimed responsibility for a match term: {$term}"); } - if (!\is_null($note_res) && !empty($note_res)) { // @phpstan-ignore-line + if (!empty($note_res)) { // @phpstan-ignore-line if (\is_array($note_res)) { $note_res = $eb->orX(...$note_res); } $note_parts[] = $note_res; } - if (!\is_null($actor_res) && !empty($actor_res)) { + if (!empty($actor_res)) { if (\is_array($actor_res)) { $actor_res = $eb->orX(...$actor_res); } diff --git a/components/Feed/Controller/Feeds.php b/components/Feed/Controller/Feeds.php index d43e6ae3db..e43c622032 100644 --- a/components/Feed/Controller/Feeds.php +++ b/components/Feed/Controller/Feeds.php @@ -47,10 +47,7 @@ class Feeds extends FeedController */ public function public(Request $request): array { - $data = $this->query( - query: 'note-local:true', - locale: Common::currentLanguage()->getLocale(), - ); + $data = $this->query('note-local:true'); return [ '_template' => 'collection/notes.html.twig', 'page_title' => _m(\is_null(Common::user()) ? 'Feed' : 'Planet'), @@ -63,13 +60,8 @@ class Feeds extends FeedController */ public function home(Request $request): array { - $user = Common::ensureLoggedIn(); - $actor = $user->getActor(); - $data = $this->query( - query: 'note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business', - locale: Common::currentLanguage()->getLocale(), - actor: $actor, - ); + Common::ensureLoggedIn(); + $data = $this->query('note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business'); return [ '_template' => 'collection/notes.html.twig', 'page_title' => _m('Home'), diff --git a/components/FreeNetwork/Controller/Feeds.php b/components/FreeNetwork/Controller/Feeds.php index 7ef8e807e0..04e7169cee 100644 --- a/components/FreeNetwork/Controller/Feeds.php +++ b/components/FreeNetwork/Controller/Feeds.php @@ -51,10 +51,7 @@ class Feeds extends FeedController public function network(Request $request): array { Common::ensureLoggedIn(); - $data = $this->query( - query: 'note-local:false', - locale: Common::currentLanguage()->getLocale(), - ); + $data = $this->query('note-local:false'); return [ '_template' => 'collection/notes.html.twig', 'page_title' => _m('Meteorites'), @@ -71,6 +68,7 @@ class Feeds extends FeedController public function clique(Request $request): array { Common::ensureLoggedIn(); + // TODO: maybe make this a Collection::query $notes = DB::dql( <<<'EOF' SELECT n FROM \App\Entity\Note AS n @@ -99,10 +97,7 @@ class Feeds extends FeedController public function federated(Request $request): array { Common::ensureLoggedIn(); - $data = $this->query( - query: '', - locale: Common::currentLanguage()->getLocale(), - ); + $data = $this->query('notes-all:yeah'); return [ '_template' => 'collection/notes.html.twig', 'page_title' => _m('Galaxy'),