diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2020-09-24 11:32:55 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2020-09-24 11:32:55 -0100 |
commit | 6d9afed84221d5485330f62eff6be1bebee404f3 (patch) | |
tree | e045542cb98a62a9f17efa095694e1ed5ce733a0 /lib | |
parent | 888d9931413f5ddbb540ca8d9ca4833cf74ddbde (diff) |
compat nc20
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 80 | ||||
-rw-r--r-- | lib/Listeners/WellKnownListener.php | 83 | ||||
-rw-r--r-- | lib/Service/WellKnownService.php (renamed from lib/Service/WebfingerService.php) | 17 |
3 files changed, 126 insertions, 54 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9aeb978a..568d02fa 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -31,17 +31,20 @@ declare(strict_types=1); namespace OCA\Social\AppInfo; +use Closure; use OC\DB\SchemaWrapper; -use OC\Webfinger\Event\WebfingerEvent; -use OC\Webfinger\Model\WebfingerObject; +use OC\WellKnown\Event\WellKnownEvent; +use OCA\Social\Listeners\WellKnownListener; use OCA\Social\Notification\Notifier; use OCA\Social\Service\ConfigService; use OCA\Social\Service\UpdateService; -use OCA\Social\Service\WebfingerService; use OCP\AppFramework\App; -use OCP\AppFramework\IAppContainer; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; -use OCP\EventDispatcher\IEventDispatcher; +use OCP\IServerContainer; +use Throwable; /** @@ -49,22 +52,12 @@ use OCP\EventDispatcher\IEventDispatcher; * * @package OCA\Social\AppInfo */ -class Application extends App { +class Application extends App implements IBootstrap { const APP_NAME = 'social'; - /** @var ConfigService */ - private $configService; - - /** @var UpdateService */ - private $updateService; - - /** @var IAppContainer */ - private $container; - - /** * Application constructor. * @@ -72,61 +65,58 @@ class Application extends App { */ public function __construct(array $params = []) { parent::__construct(self::APP_NAME, $params); + } - $this->container = $this->getContainer(); - $manager = $this->container->getServer() - ->getNotificationManager(); - $manager->registerNotifierService(Notifier::class); + /** + * @param IRegistrationContext $context + */ + public function register(IRegistrationContext $context): void { + $context->registerEventListener(WellKnownEvent::class, WellKnownListener::class); } /** - * + * @param IBootContext $context */ - public function registerWebfinger() { - /** @var IEventDispatcher $eventDispatcher */ - $eventDispatcher = \OC::$server->query(IEventDispatcher::class); - $eventDispatcher->addListener( - '\OC\Webfinger::onRequest', - function(WebfingerEvent $e) { - /** @var WebfingerService $webfingerService */ - $webfingerService = $this->container->query(WebfingerService::class); - try { - $webfingerService->webfinger($e); - } catch (\Exception $e) { - } - } - ); + public function boot(IBootContext $context): void { + $manager = $context->getServerContainer() + ->getNotificationManager(); + $manager->registerNotifierService(Notifier::class); + + try { + $context->injectFn(Closure::fromCallable([$this, 'checkUpgradeStatus'])); + } catch (Throwable $e) { + } } /** + * Register Navigation Tab * + * @param IServerContainer $container */ - public function checkUpgradeStatus() { - $upgradeChecked = $this->container->getServer() - ->getConfig() - ->getAppValue(Application::APP_NAME, 'update_checked', ''); + protected function checkUpgradeStatus(IServerContainer $container) { + $upgradeChecked = $container->getConfig() + ->getAppValue(Application::APP_NAME, 'update_checked', ''); if ($upgradeChecked === '0.3') { return; } try { - $this->configService = $this->container->query(ConfigService::class); - $this->updateService = $this->container->query(UpdateService::class); + $configService = $container->query(ConfigService::class); + $updateService = $container->query(UpdateService::class); } catch (QueryException $e) { return; } - $server = $this->container->getServer(); - $schema = new SchemaWrapper($server->getDatabaseConnection()); + $schema = new SchemaWrapper($container->getDatabaseConnection()); if ($schema->hasTable('social_a2_stream')) { - $this->updateService->checkUpdateStatus(); + $updateService->checkUpdateStatus(); } - $this->configService->setAppValue('update_checked', '0.3'); + $configService->setAppValue('update_checked', '0.3'); } } diff --git a/lib/Listeners/WellKnownListener.php b/lib/Listeners/WellKnownListener.php new file mode 100644 index 00000000..8eb18c64 --- /dev/null +++ b/lib/Listeners/WellKnownListener.php @@ -0,0 +1,83 @@ +<?php +declare(strict_types=1); + + +/** + * Nextcloud - Social Support + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2020, Maxence Lange <maxence@artificial-owl.com> + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\Social\Listeners; + + +use OC\WellKnown\Event\WellKnownEvent; +use OCA\Social\Exceptions\CacheActorDoesNotExistException; +use OCA\Social\Exceptions\SocialAppConfigException; +use OCA\Social\Exceptions\UnauthorizedFediverseException; +use OCA\Social\Service\WellKnownService; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\WellKnown\IWellKnownManager; + + +/** + * Class WellKnownListener + * + * @package OCA\Social\Listeners + */ +class WellKnownListener implements IEventListener { + + + private $wellKnownService; + + + /** + * WellKnownListener constructor. + * + * @param WellKnownService $wellKnownService + */ + public function __construct(WellKnownService $wellKnownService) { + $this->wellKnownService = $wellKnownService; + } + + + /** + * @param Event $event + */ + public function handle(Event $event): void { + if (!$event instanceof WellKnownEvent) { + return; + } + + $wellKnown = $event->getWellKnown(); + if ($wellKnown->getService() === IWellKnownManager::WEBFINGER) { + try { + $this->wellKnownService->webfinger($wellKnown); + } catch (CacheActorDoesNotExistException | SocialAppConfigException | UnauthorizedFediverseException $e) { + } + } + } + +} + diff --git a/lib/Service/WebfingerService.php b/lib/Service/WellKnownService.php index c0169886..2ce5342f 100644 --- a/lib/Service/WebfingerService.php +++ b/lib/Service/WellKnownService.php @@ -37,8 +37,9 @@ use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UnauthorizedFediverseException; use OCA\Social\Model\WebfingerLink; use OCP\IURLGenerator; +use OCP\WellKnown\Model\IWellKnown; -class WebfingerService { +class WellKnownService { /** @var IURLGenerator */ @@ -86,17 +87,16 @@ class WebfingerService { /** - * @param WebfingerEvent $event + * @param IWellKnown $wellKnown * * @throws CacheActorDoesNotExistException - * @throws UnauthorizedFediverseException * @throws SocialAppConfigException + * @throws UnauthorizedFediverseException */ - public function webfinger(WebfingerEvent $event) { + public function webfinger(IWellKnown $wellKnown) { $this->fediverseService->jailed(); - $subject = $event->getWebfinger() - ->getSubject(); + $subject = $wellKnown->getSubject(); if (strpos($subject, 'acct:') === 0) { $subject = substr($subject, 5); @@ -124,9 +124,8 @@ class WebfingerService { $subscribe = $this->urlGenerator->linkToRouteAbsolute('social.OStatus.subscribe') . '?uri={uri}'; $linkOstatus->setTemplate($subscribe); - $event->getWebfinger() - ->addLinkSerialized($linkPerson) - ->addLinkSerialized($linkOstatus); + $wellKnown->addLinkSerialized($linkPerson) + ->addLinkSerialized($linkOstatus); } } |