|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright Copyright (c) 2020, Georg Ehrke |
| 7 | + * |
| 8 | + * @author Georg Ehrke <[email protected]> |
| 9 | + * |
| 10 | + * @license AGPL-3.0 |
| 11 | + * |
| 12 | + * This code is free software: you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 14 | + * as published by the Free Software Foundation. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace OCA\UserStatus\AppInfo; |
| 27 | + |
| 28 | +use OCA\UserStatus\Capabilities; |
| 29 | +use OCA\UserStatus\Listener\UserDeletedListener; |
| 30 | +use OCA\UserStatus\Listener\UserLiveStatusListener; |
| 31 | +use OCP\AppFramework\App; |
| 32 | +use OCP\EventDispatcher\IEventDispatcher; |
| 33 | +use OCP\User\Events\UserDeletedEvent; |
| 34 | +use OCP\User\Events\UserLiveStatusEvent; |
| 35 | + |
| 36 | +/** |
| 37 | + * Class Application |
| 38 | + * |
| 39 | + * @package OCA\UserStatus\AppInfo |
| 40 | + */ |
| 41 | +class Application extends App { |
| 42 | + |
| 43 | + /** @var string */ |
| 44 | + public const APP_ID = 'user_status'; |
| 45 | + |
| 46 | + /** |
| 47 | + * Application constructor. |
| 48 | + * |
| 49 | + * @param array $urlParams |
| 50 | + */ |
| 51 | + public function __construct(array $urlParams = []) { |
| 52 | + parent::__construct(self::APP_ID, $urlParams); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Registers capabilities that will be exposed |
| 57 | + * via the OCS API endpoint |
| 58 | + */ |
| 59 | + public function registerCapabilities(): void { |
| 60 | + $this->getContainer() |
| 61 | + ->registerCapability(Capabilities::class); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Registers a listener for the user-delete event |
| 66 | + * to automatically delete a user's status on |
| 67 | + * account deletion |
| 68 | + */ |
| 69 | + public function registerEvents(): void { |
| 70 | + /** @var IEventDispatcher $dispatcher */ |
| 71 | + $dispatcher = $this->getContainer() |
| 72 | + ->query(IEventDispatcher::class); |
| 73 | + |
| 74 | + $dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class); |
| 75 | + $dispatcher->addServiceListener(UserLiveStatusEvent::class, UserLiveStatusListener::class); |
| 76 | + } |
| 77 | +} |
0 commit comments