Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2021-06-18 14:04:53 +0300
committerJulius Härtl <jus@bitgrid.net>2021-06-18 14:55:19 +0300
commitd5183d8c05e947a270de3f45d565a8aabdd62688 (patch)
treec70ee3273560dbcd14163aed4065f66ad8e19de1 /lib
parent4907489c8b501e8db7083b21ee26e6ca48e42f2c (diff)
Use the BeforeTemplateRenderedEvent and check if we show it as a user
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php23
-rw-r--r--lib/Listener/BeforeTemplateRenderedListener.php49
2 files changed, 55 insertions, 17 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 58c395a..340bfb1 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -26,17 +26,16 @@ namespace OCA\Notifications\AppInfo;
use OC\Authentication\Token\IProvider;
use OCA\Notifications\App;
use OCA\Notifications\Capabilities;
+use OCA\Notifications\Listener\BeforeTemplateRenderedListener;
use OCA\Notifications\Listener\UserDeletedListener;
use OCA\Notifications\Notifier\AdminNotifications;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\IAppContainer;
-use OCP\IRequest;
-use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\User\Events\UserDeletedEvent;
-use OCP\Util;
class Application extends \OCP\AppFramework\App implements IBootstrap {
public const APP_ID = 'notifications';
@@ -52,28 +51,18 @@ class Application extends \OCP\AppFramework\App implements IBootstrap {
return $c->getServer()->get(IProvider::class);
});
+ $context->registerNotifierService(AdminNotifications::class);
+
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
+ $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
}
public function boot(IBootContext $context): void {
$context->injectFn(\Closure::fromCallable([$this, 'registerAppAndNotifier']));
}
- public function registerAppAndNotifier(IManager $notificationManager, IRequest $request, IUserSession $userSession): void {
+ public function registerAppAndNotifier(IManager $notificationManager): void {
// notification app
$notificationManager->registerApp(App::class);
-
- // admin notifications
- $notificationManager->registerNotifierService(AdminNotifications::class);
-
- // User interface
- if ($userSession->getUser() !== null
- && strpos($request->getPathInfo(), '/s/') !== 0
- && strpos($request->getPathInfo(), '/login/') !== 0
- && strpos($request->getPathInfo(), '/apps/calendar/embed/') !== 0
- && substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php') {
- Util::addScript('notifications', 'notifications-main');
- Util::addStyle('notifications', 'styles');
- }
}
}
diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php
new file mode 100644
index 0000000..f1d761a
--- /dev/null
+++ b/lib/Listener/BeforeTemplateRenderedListener.php
@@ -0,0 +1,49 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Notifications\Listener;
+
+use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Util;
+
+class BeforeTemplateRenderedListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!($event instanceof BeforeTemplateRenderedEvent)) {
+ // Unrelated
+ return;
+ }
+
+ if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
+ return;
+ }
+
+ Util::addScript('notifications', 'notifications-main');
+ Util::addStyle('notifications', 'styles');
+ }
+}