From 5516a77b3373bb9803e70cda748299f286f436cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Brand=C3=A3o?= Date: Wed, 2 Dec 2020 22:57:32 +0000 Subject: [PATCH] [UI][TIMELINES] Refactored query for public stream --- src/Controller/Network.php | 3 ++- src/Controller/Security.php | 4 +++- src/Entity/Note.php | 9 +++++++++ src/Util/Common.php | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Controller/Network.php b/src/Controller/Network.php index 6311d4305e..d5eb6e87c5 100644 --- a/src/Controller/Network.php +++ b/src/Controller/Network.php @@ -37,6 +37,7 @@ use App\Core\Controller; use App\Core\DB\DB; use App\Core\Event; use App\Core\NoteScope; +use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; use function App\Core\I18n\_m; @@ -61,7 +62,7 @@ class Network extends Controller return [ '_template' => 'network/public.html.twig', - 'notes' => $notes, + 'notes' => Note::getAllNotes($this->instance_scope), ]; } diff --git a/src/Controller/Security.php b/src/Controller/Security.php index 20d781698a..59a37e4f39 100644 --- a/src/Controller/Security.php +++ b/src/Controller/Security.php @@ -9,6 +9,7 @@ use function App\Core\I18n\_m; use App\Entity\Follow; use App\Entity\GSActor; use App\Entity\LocalUser; +use App\Entity\Note; use App\Security\Authenticator; use App\Security\EmailVerifier; use app\Util\Common; @@ -39,7 +40,7 @@ class Security extends Controller // last username entered by the user $last_username = $authenticationUtils->getLastUsername(); - return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error]; + return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error, 'notes' => Note::getAllNotes($this->instance_scope), ]; } public function logout() @@ -133,6 +134,7 @@ class Security extends Controller return [ '_template' => 'security/register.html.twig', 'registration_form' => $form->createView(), + 'notes' => Note::getAllNotes($this->instance_scope), ]; } } diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 5f660d8ef5..eaa906e3d4 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -199,6 +199,15 @@ class Note extends Entity Event::handle('GetAvatarUrl', [$this->getActorNickname(), &$url]); return $url; } + public function getAllNotes(int $noteScope): array + { + return DB::sql('select * from note n ' . + 'where n.reply_to is null and (n.scope & :notescope) <> 0 ' . + 'order by n.created DESC', + ['n' => 'App\Entity\Note'], + ['notescope' => $noteScope] + ); + } public function getAttachments(): array { diff --git a/src/Util/Common.php b/src/Util/Common.php index fbd6f750a7..e1acf04589 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -98,6 +98,14 @@ abstract class Common } } + public function getAllNotes(int $noteScope): array + { + return DB::sql('select * from note n ' . + "where n.reply_to is null and (n.scope & {$noteScope}) <> 0 " . + 'order by n.created DESC', + ['n' => 'App\Entity\Note']); + } + public static function ensureLoggedIn(): LocalUser { if (($user = self::user()) == null) {