You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Comments\AppInfo;
  28. use OCA\Comments\Controller\Notifications;
  29. use OCA\Comments\EventHandler;
  30. use OCA\Comments\JSSettingsHelper;
  31. use OCA\Comments\Listener\LoadAdditionalScripts;
  32. use OCA\Comments\Listener\LoadSidebarScripts;
  33. use OCA\Comments\Notification\Notifier;
  34. use OCA\Comments\Search\Provider;
  35. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  36. use OCA\Files\Event\LoadSidebar;
  37. use OCP\AppFramework\App;
  38. use OCP\Comments\CommentsEntityEvent;
  39. use OCP\EventDispatcher\IEventDispatcher;
  40. use OCP\Util;
  41. class Application extends App {
  42. const APP_ID = 'comments';
  43. public function __construct(array $urlParams = []) {
  44. parent::__construct(self::APP_ID, $urlParams);
  45. $container = $this->getContainer();
  46. $container->registerAlias('NotificationsController', Notifications::class);
  47. $jsSettingsHelper = new JSSettingsHelper($container->getServer());
  48. Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
  49. $this->register();
  50. }
  51. private function register() {
  52. $server = $this->getContainer()->getServer();
  53. /** @var IEventDispatcher $newDispatcher */
  54. $dispatcher = $server->query(IEventDispatcher::class);
  55. $this->registerEventsScripts($dispatcher);
  56. $this->registerDavEntity($dispatcher);
  57. $this->registerNotifier();
  58. $this->registerCommentsEventHandler();
  59. $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
  60. }
  61. protected function registerEventsScripts(IEventDispatcher $dispatcher) {
  62. $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class);
  63. $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class);
  64. }
  65. protected function registerDavEntity(IEventDispatcher $dispatcher) {
  66. $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
  67. $event->addEntityCollection('files', function ($name) {
  68. $nodes = \OC::$server->getUserFolder()->getById((int)$name);
  69. return !empty($nodes);
  70. });
  71. });
  72. }
  73. protected function registerNotifier() {
  74. $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
  75. }
  76. protected function registerCommentsEventHandler() {
  77. $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () {
  78. return $this->getContainer()->query(EventHandler::class);
  79. });
  80. }
  81. }