app.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Vincent Petry <pvince81@owncloud.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. $eventDispatcher = \OC::$server->getEventDispatcher();
  24. $eventDispatcher->addListener(
  25. 'OCA\Files::loadAdditionalScripts',
  26. function() {
  27. \OCP\Util::addScript('oc-backbone-webdav');
  28. \OCP\Util::addScript('comments', 'app');
  29. \OCP\Util::addScript('comments', 'commentmodel');
  30. \OCP\Util::addScript('comments', 'commentcollection');
  31. \OCP\Util::addScript('comments', 'commentsummarymodel');
  32. \OCP\Util::addScript('comments', 'commentstabview');
  33. \OCP\Util::addScript('comments', 'filesplugin');
  34. \OCP\Util::addScript('comments', 'activitytabviewplugin');
  35. \OCP\Util::addStyle('comments', 'comments');
  36. }
  37. );
  38. $eventDispatcher->addListener(\OCP\Comments\CommentsEntityEvent::EVENT_ENTITY, function(\OCP\Comments\CommentsEntityEvent $event) {
  39. $event->addEntityCollection('files', function($name) {
  40. $nodes = \OC::$server->getUserFolder()->getById(intval($name));
  41. return !empty($nodes);
  42. });
  43. });
  44. $notificationManager = \OC::$server->getNotificationManager();
  45. $notificationManager->registerNotifier(
  46. function() {
  47. $application = new \OCP\AppFramework\App('comments');
  48. return $application->getContainer()->query(\OCA\Comments\Notification\Notifier::class);
  49. },
  50. function () {
  51. $l = \OC::$server->getL10N('comments');
  52. return ['id' => 'comments', 'name' => $l->t('Comments')];
  53. }
  54. );
  55. $commentsManager = \OC::$server->getCommentsManager();
  56. $commentsManager->registerEventHandler(function () {
  57. $application = new \OCP\AppFramework\App('comments');
  58. /** @var \OCA\Comments\EventHandler $handler */
  59. $handler = $application->getContainer()->query(\OCA\Comments\EventHandler::class);
  60. return $handler;
  61. });
  62. $commentsManager->registerDisplayNameResolver('user', function($id) {
  63. $manager = \OC::$server->getUserManager();
  64. $user = $manager->get($id);
  65. if(is_null($user)) {
  66. $l = \OC::$server->getL10N('comments');
  67. $displayName = $l->t('Unknown user');
  68. } else {
  69. $displayName = $user->getDisplayName();
  70. }
  71. return $displayName;
  72. });