Fix comments app init and LoadSidebar event

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2019-11-04 19:25:42 +01:00
parent 13960b69da
commit 7ba5f39dbd
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
6 changed files with 67 additions and 9 deletions

View File

@ -21,5 +21,4 @@
*
*/
$application = new \OCA\Comments\AppInfo\Application();
$application->register();
\OC::$server->query(\OCA\Comments\AppInfo\Application::class);

View File

@ -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',

View File

@ -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',

View File

@ -1,8 +1,9 @@
<?php
/**
*
* @copyright Copyright (c) 2016, Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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) {

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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');
}
}

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author John Molakvoæ <skjnldsv@protonmail.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\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');
}
}