diff --git a/appinfo/info.xml b/appinfo/info.xml index 7d1be1da..767ce03f 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ 🎉 Nextcloud becomes part of the federated social networks! socialPubController = $socialPubController; $this->fediverseService = $fediverseService; diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 900ef551..75e61cba 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -113,7 +113,7 @@ class ApiController extends Controller { PostService $postService, ConfigService $configService ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->urlGenerator = $urlGenerator; $this->userSession = $userSession; diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index 863c4684..6946cd70 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -91,7 +91,7 @@ class LocalController extends Controller { BoostService $boostService, LikeService $likeService, DocumentService $documentService, MiscService $miscService ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->userId = $userId; $this->cacheActorService = $cacheActorService; diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 0684a61a..3f82ea57 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -90,7 +90,7 @@ class NavigationController extends Controller { CheckService $checkService, MiscService $miscService ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->userId = $userId; $this->l10n = $l10n; @@ -140,8 +140,8 @@ class NavigationController extends Controller { if ($cloudAddress !== null) { $this->configService->setCloudUrl($cloudAddress); } else { - $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData); - return new TemplateResponse(Application::APP_NAME, 'main'); + $this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', $serverData); + return new TemplateResponse(Application::APP_ID, 'main'); } } } @@ -172,8 +172,8 @@ class NavigationController extends Controller { $serverData['checks'] = $checks; } - $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData); - return new TemplateResponse(Application::APP_NAME, 'main'); + $this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', $serverData); + return new TemplateResponse(Application::APP_ID, 'main'); } private function setupCloudAddress(): string { diff --git a/lib/Controller/OAuthController.php b/lib/Controller/OAuthController.php index 680d4f08..0b1f74db 100644 --- a/lib/Controller/OAuthController.php +++ b/lib/Controller/OAuthController.php @@ -71,7 +71,7 @@ class OAuthController extends Controller { LoggerInterface $logger, IInitialState $initialState ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->userSession = $userSession; $this->urlGenerator = $urlGenerator; @@ -187,7 +187,7 @@ class OAuthController extends Controller { $client = $this->clientService->getFromClientId($client_id); $this->initialState->provideInitialState('appName', $client->getAppName()); - return new TemplateResponse(Application::APP_NAME, 'oauth2', [ + return new TemplateResponse(Application::APP_ID, 'oauth2', [ 'request' => [ 'clientId' => $client_id, diff --git a/lib/Controller/OStatusController.php b/lib/Controller/OStatusController.php index 195c6f72..72996f06 100644 --- a/lib/Controller/OStatusController.php +++ b/lib/Controller/OStatusController.php @@ -64,7 +64,7 @@ class OStatusController extends Controller { IRequest $request, IInitialStateService $initialStateService, CacheActorService $cacheActorService, AccountService $accountService, CurlService $curlService, MiscService $miscService, IUserSession $userSession ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->initialStateService = $initialStateService; $this->cacheActorService = $cacheActorService; diff --git a/lib/Controller/QueueController.php b/lib/Controller/QueueController.php index 82731f58..16bf1b2a 100644 --- a/lib/Controller/QueueController.php +++ b/lib/Controller/QueueController.php @@ -56,7 +56,7 @@ class QueueController extends Controller { IRequest $request, RequestQueueService $requestQueueService, ActivityService $activityService, MiscService $miscService ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->requestQueueService = $requestQueueService; $this->activityService = $activityService; diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index 07278909..1255e2f1 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -74,7 +74,7 @@ class SocialPubController extends Controller { CacheActorService $cacheActorService, AccountService $accountService, StreamService $streamService, ConfigService $configService ) { - parent::__construct(Application::APP_NAME, $request); + parent::__construct(Application::APP_ID, $request); $this->userId = $userId; $this->initialStateService = $initialStateService; @@ -113,7 +113,7 @@ class SocialPubController extends Controller { $this->initialStateService->provideInitialState('social', 'serverData', [ 'public' => true, ]); - $page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data); + $page = new PublicTemplateResponse(Application::APP_ID, 'main', $data); $page->setStatus($status); $page->setHeaderTitle($this->l10n->t('Social')); @@ -190,10 +190,10 @@ class SocialPubController extends Controller { 'application' => 'Social' ]; - $this->initialStateService->provideInitialState(Application::APP_NAME, 'item', $stream); - $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', [ + $this->initialStateService->provideInitialState(Application::APP_ID, 'item', $stream); + $this->initialStateService->provideInitialState(Application::APP_ID, 'serverData', [ 'public' => ($this->userId === null), ]); - return new TemplateResponse(Application::APP_NAME, 'main', $data); + return new TemplateResponse(Application::APP_ID, 'main', $data); } } diff --git a/lib/Dashboard/SocialWidget.php b/lib/Dashboard/SocialWidget.php index ad5395b9..1b6f1f2a 100644 --- a/lib/Dashboard/SocialWidget.php +++ b/lib/Dashboard/SocialWidget.php @@ -79,7 +79,7 @@ class SocialWidget implements IWidget { * @inheritDoc */ public function load(): void { - \OCP\Util::addScript(Application::APP_NAME, 'social-dashboard'); - \OCP\Util::addStyle(Application::APP_NAME, 'dashboard'); + \OCP\Util::addScript(Application::APP_ID, 'social-dashboard'); + \OCP\Util::addStyle(Application::APP_ID, 'dashboard'); } } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index fd1fc17c..b3096b98 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -76,7 +76,7 @@ class Notifier implements INotifier { * @since 17.0.0 */ public function getID(): string { - return Application::APP_NAME; + return Application::APP_ID; } /** @@ -97,11 +97,11 @@ class Notifier implements INotifier { * @throws InvalidArgumentException */ public function prepare(INotification $notification, string $languageCode): INotification { - if ($notification->getApp() !== Application::APP_NAME) { + if ($notification->getApp() !== Application::APP_ID) { throw new InvalidArgumentException(); } - $l10n = $this->factory->get(Application::APP_NAME, $languageCode); + $l10n = $this->factory->get(Application::APP_ID, $languageCode); $notification->setIcon( $this->url->getAbsoluteURL($this->url->imagePath('social', 'social_dark.svg')) diff --git a/lib/Providers/ContactsMenuProvider.php b/lib/Providers/ContactsMenuProvider.php index 15479e4c..ae818aa9 100644 --- a/lib/Providers/ContactsMenuProvider.php +++ b/lib/Providers/ContactsMenuProvider.php @@ -97,7 +97,7 @@ class ContactsMenuProvider implements IProvider { 'social.ActivityPub.actorAlias', ['username' => $actor->getPreferredUsername()] ); - $action = $this->actionFactory->newLinkAction($icon, $action, $link, Application::APP_NAME); + $action = $this->actionFactory->newLinkAction($icon, $action, $link, Application::APP_ID); $entry->addAction($action); } catch (Exception $e) { return; diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 033990b7..ae84aed5 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -132,7 +132,7 @@ class ConfigService { $defaultValue = $this->defaults[$key]; } - return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue); + return $this->config->getAppValue(Application::APP_ID, $key, $defaultValue); } /** @@ -148,7 +148,7 @@ class ConfigService { $defaultValue = $this->defaults[$key]; } - return (int)$this->config->getAppValue(Application::APP_NAME, $key, $defaultValue); + return (int)$this->config->getAppValue(Application::APP_ID, $key, $defaultValue); } /** @@ -160,7 +160,7 @@ class ConfigService { * @return void */ public function setAppValue($key, $value) { - $this->config->setAppValue(Application::APP_NAME, $key, $value); + $this->config->setAppValue(Application::APP_ID, $key, $value); } /** @@ -171,7 +171,7 @@ class ConfigService { * @return string */ public function deleteAppValue($key) { - return $this->config->deleteAppValue(Application::APP_NAME, $key); + return $this->config->deleteAppValue(Application::APP_ID, $key); } /** @@ -190,7 +190,7 @@ class ConfigService { $defaultValue = ''; if ($app === '') { - $app = Application::APP_NAME; + $app = Application::APP_ID; if (array_key_exists($key, $this->defaults)) { $defaultValue = $this->defaults[$key]; } @@ -209,7 +209,7 @@ class ConfigService { * @throws PreConditionNotMetException */ public function setUserValue($key, $value) { - return $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value); + return $this->config->setUserValue($this->userId, Application::APP_ID, $key, $value); } /** @@ -221,7 +221,7 @@ class ConfigService { * @return string */ public function getValueForUser($userId, $key) { - return $this->config->getUserValue($userId, Application::APP_NAME, $key); + return $this->config->getUserValue($userId, Application::APP_ID, $key); } /** @@ -235,7 +235,7 @@ class ConfigService { * @throws PreConditionNotMetException */ public function setValueForUser($userId, $key, $value) { - return $this->config->setUserValue($userId, Application::APP_NAME, $key, $value); + return $this->config->setUserValue($userId, Application::APP_ID, $key, $value); } @@ -268,7 +268,7 @@ class ConfigService { * */ public function unsetAppConfig() { - $this->config->deleteAppValues(Application::APP_NAME); + $this->config->deleteAppValues(Application::APP_ID); } diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php index 4c756253..72daf3f9 100644 --- a/lib/Service/InstanceService.php +++ b/lib/Service/InstanceService.php @@ -62,7 +62,7 @@ class InstanceService { public function createLocal(): Instance { $instance = new Instance(); $instance->setLocal(true) - ->setVersion($this->config->getAppValue(Application::APP_NAME, 'installed_version', '0.0')) + ->setVersion($this->config->getAppValue(Application::APP_ID, 'installed_version', '0.0')) ->setApprovalRequired(false) ->setDescription($this->config->getAppValue('theming', 'slogan', 'a safe home for your data')) ->setTitle($this->config->getAppValue('theming', 'name', 'Nextcloud Social')); diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index a7abbc7a..121db528 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -58,7 +58,7 @@ class MiscService { */ public function log(string $message, $level = 2) { $data = array( - 'app' => Application::APP_NAME, + 'app' => Application::APP_ID, 'level' => $level ); diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index dbe3261a..d95a9ffa 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -581,7 +581,7 @@ class SignatureService { private static function getContextCacheFolder(): ISimpleFolder { $path = 'context'; - $appData = Server::get(IAppDataFactory::class)->get(Application::APP_NAME); + $appData = Server::get(IAppDataFactory::class)->get(Application::APP_ID); try { $folder = $appData->getFolder($path); } catch (NotFoundException $e) { diff --git a/lib/WellKnown/WebfingerHandler.php b/lib/WellKnown/WebfingerHandler.php index a6a11ed7..1ffd8889 100644 --- a/lib/WellKnown/WebfingerHandler.php +++ b/lib/WellKnown/WebfingerHandler.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace OCA\Social\WellKnown; +use OCA\Social\AppInfo\Application; use OCA\Social\Db\CacheActorsRequest; use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\CacheActorDoesNotExistException; @@ -76,21 +77,29 @@ class WebfingerHandler implements IHandler { try { $this->fediverseService->jailed(); } catch (UnauthorizedFediverseException $e) { - return null; + return $previousResponse; } + $response = null; switch (strtolower($service)) { case 'webfinger': - return $this->handleWebfinger($context); + $response = $this->handleWebfinger($context, $previousResponse); + break; case 'nodeinfo': - return $this->handleNodeInfo($context); + $response = $this->handleNodeInfo($context); + break; case 'host-meta': - return $this->handleHostMeta($context); + $response = $this->handleHostMeta($context); + break; } - return null; + if ($response !== null) { + return $response; + } + + return $previousResponse; } @@ -101,16 +110,34 @@ class WebfingerHandler implements IHandler { * * @return IResponse|null */ - public function handleWebfinger(IRequestContext $context): ?IResponse { + public function handleWebfinger(IRequestContext $context, ?IResponse $previousResponse): ?IResponse { $subject = $context->getHttpRequest()->getParam('resource') ?? ''; - if (strpos($subject, 'acct:') === 0) { + if (str_starts_with($subject, 'acct:')) { $subject = substr($subject, 5); } + if ($subject === Application::APP_SUBJECT) { + if ($previousResponse !== null && method_exists($previousResponse, 'addLink')) { + $previousResponse->addLink( + Application::APP_REL, + 'application/json', + $this->urlGenerator->linkToRouteAbsolute('social.Navigation.navigate'), + [], + [ + 'app' => Application::APP_ID, + 'name' => Application::APP_NAME, + 'version' => $this->configService->getAppValue('installed_version'), + ] + ); + } + + return $previousResponse; + } + $actor = null; try { $actor = $this->cacheActorService->getFromLocalAccount($subject); - } catch (ActorDoesNotExistException | SocialAppConfigException $e) { + } catch (ActorDoesNotExistException|SocialAppConfigException $e) { return null; } catch (CacheActorDoesNotExistException $e) { }