diff --git a/apps/comments/appinfo/app.php b/apps/comments/appinfo/app.php index 6d6775dd15..491b4f7648 100644 --- a/apps/comments/appinfo/app.php +++ b/apps/comments/appinfo/app.php @@ -21,5 +21,4 @@ * */ -$application = new \OCA\Comments\AppInfo\Application(); -$application->register(); +\OC::$server->query(\OCA\Comments\AppInfo\Application::class); diff --git a/apps/comments/composer/composer/autoload_classmap.php b/apps/comments/composer/composer/autoload_classmap.php index 4f2cfaebde..ef14522c9c 100644 --- a/apps/comments/composer/composer/autoload_classmap.php +++ b/apps/comments/composer/composer/autoload_classmap.php @@ -16,6 +16,7 @@ return array( 'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php', 'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php', 'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php', + 'OCA\\Comments\\Listener\\LoadSidebarScripts' => $baseDir . '/../lib/Listener/LoadSidebarScripts.php', 'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php', 'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', 'OCA\\Comments\\Search\\Provider' => $baseDir . '/../lib/Search/Provider.php', diff --git a/apps/comments/composer/composer/autoload_static.php b/apps/comments/composer/composer/autoload_static.php index 685a2d3296..68733b4c03 100644 --- a/apps/comments/composer/composer/autoload_static.php +++ b/apps/comments/composer/composer/autoload_static.php @@ -31,6 +31,7 @@ class ComposerStaticInitComments 'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php', 'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php', 'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php', + 'OCA\\Comments\\Listener\\LoadSidebarScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarScripts.php', 'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php', 'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', 'OCA\\Comments\\Search\\Provider' => __DIR__ . '/..' . '/../lib/Search/Provider.php', diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index 793d1e9f7b..e2f79c9638 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -1,8 +1,9 @@ * * @author Arthur Schiwon + * @author John Molakvoæ * * @license GNU AGPL version 3 or any later version * @@ -27,33 +28,39 @@ use OCA\Comments\Controller\Notifications; use OCA\Comments\EventHandler; use OCA\Comments\JSSettingsHelper; use OCA\Comments\Listener\LoadAdditionalScripts; +use OCA\Comments\Listener\LoadSidebarScripts; use OCA\Comments\Notification\Notifier; use OCA\Comments\Search\Provider; use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Files\Event\LoadSidebar; use OCP\AppFramework\App; use OCP\Comments\CommentsEntityEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; class Application extends App { + const APP_ID = 'comments'; + public function __construct (array $urlParams = array()) { - parent::__construct('comments', $urlParams); + parent::__construct(self::APP_ID, $urlParams); $container = $this->getContainer(); $container->registerAlias('NotificationsController', Notifications::class); $jsSettingsHelper = new JSSettingsHelper($container->getServer()); Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); + + $this->register(); } - public function register() { + private function register() { $server = $this->getContainer()->getServer(); /** @var IEventDispatcher $newDispatcher */ $dispatcher = $server->query(IEventDispatcher::class); - $this->registerSidebarScripts($dispatcher); + + $this->registerEventsScripts($dispatcher); $this->registerDavEntity($dispatcher); $this->registerNotifier(); $this->registerCommentsEventHandler(); @@ -61,8 +68,9 @@ class Application extends App { $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); } - protected function registerSidebarScripts(IEventDispatcher $dispatcher) { + protected function registerEventsScripts(IEventDispatcher $dispatcher) { $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); + $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class); } protected function registerDavEntity(IEventDispatcher $dispatcher) { diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php index b1e9447bea..a9c5c18a7c 100644 --- a/apps/comments/lib/Listener/LoadAdditionalScripts.php +++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php @@ -4,6 +4,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2019, Roeland Jago Douma * * @author Roeland Jago Douma + * @author John Molakvoæ * * @license GNU AGPL version 3 or any later version * @@ -24,6 +25,7 @@ declare(strict_types=1); namespace OCA\Comments\Listener; +use OCA\Comments\AppInfo\Application; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -35,7 +37,9 @@ class LoadAdditionalScripts implements IEventListener { return; } - Util::addScript('comments', 'comments'); + // TODO: make sure to only include the sidebar script when + // we properly split it between files list and sidebar + Util::addScript(Application::APP_ID, 'comments'); } } diff --git a/apps/comments/lib/Listener/LoadSidebarScripts.php b/apps/comments/lib/Listener/LoadSidebarScripts.php new file mode 100644 index 0000000000..b0468b2dd2 --- /dev/null +++ b/apps/comments/lib/Listener/LoadSidebarScripts.php @@ -0,0 +1,45 @@ + + * + * @author Roeland Jago Douma + * @author John Molakvoæ + * + * @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 . + * + */ + +namespace OCA\Comments\Listener; + +use OCA\Comments\AppInfo\Application; +use OCA\Files\Event\LoadSidebar; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class LoadSidebarScripts implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof LoadSidebar)) { + return; + } + + // TODO: make sure to only include the sidebar script when + // we properly split it between files list and sidebar + Util::addScript(Application::APP_ID, 'comments'); + } + +}