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.3KB

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