Application.php 3.0 KB

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