From 7b65eecf7296d7401e28907f21c0aeae593298be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 23 Sep 2020 08:43:07 +0200 Subject: [PATCH 1/3] Only load user status script when needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/Listener/BeforeTemplateRenderedListener.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php index fa3d8ce9e6..0daaaa9fcf 100644 --- a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php @@ -28,6 +28,7 @@ namespace OCA\UserStatus\Listener; use OCA\UserStatus\AppInfo\Application; use OCA\UserStatus\Service\JSDataService; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\IInitialStateService; @@ -61,7 +62,7 @@ class BeforeTemplateRenderedListener implements IEventListener { return; } - if (!$event->isLoggedIn()) { + if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) { return; } From bc0a429822a74b996a5b30c52e4eaa3a5ec3a884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 23 Sep 2020 08:43:36 +0200 Subject: [PATCH 2/3] Add acutal response to BeforeTemplateRenderedEvent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../Middleware/AdditionalScriptsMiddleware.php | 2 +- .../Http/Events/BeforeTemplateRenderedEvent.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php index 6c65ee8b2c..28f322f42b 100644 --- a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php +++ b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php @@ -71,7 +71,7 @@ class AdditionalScriptsMiddleware extends Middleware { $isLoggedIn = false; } - $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn)); + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); } return $response; diff --git a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php index 3d48e9a269..b96b86abd5 100644 --- a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php +++ b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCP\AppFramework\Http\Events; +use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; /** @@ -38,14 +39,17 @@ use OCP\EventDispatcher\Event; class BeforeTemplateRenderedEvent extends Event { /** @var bool */ private $loggedIn; + /** @var TemplateResponse */ + private $response; /** * @since 20.0.0 */ - public function __construct(bool $loggedIn) { + public function __construct(bool $loggedIn, TemplateResponse $response) { parent::__construct(); $this->loggedIn = $loggedIn; + $this->response = $response; } /** @@ -54,4 +58,11 @@ class BeforeTemplateRenderedEvent extends Event { public function isLoggedIn(): bool { return $this->loggedIn; } + + /** + * @since 20.0.0 + */ + public function getResponse(): TemplateResponse { + return $this->response; + } } From a6b4770afc689ab37a2f1f6da777bce8eeb4b4df Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 19 Oct 2020 10:00:15 +0200 Subject: [PATCH 3/3] Update @since tag Signed-off-by: Morris Jobke --- .../AppFramework/Http/Events/BeforeTemplateRenderedEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php index b96b86abd5..79c6825d0d 100644 --- a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php +++ b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php @@ -60,7 +60,7 @@ class BeforeTemplateRenderedEvent extends Event { } /** - * @since 20.0.0 + * @since 20.0.1 */ public function getResponse(): TemplateResponse { return $this->response;