Fork of nextcloud/integration_mastodon v5.2.0 (6a56211), AGPL-3.0, with
upstream copyright notices and CHANGELOG preserved unchanged.
Rebranded: app ID, namespace, dashboard widgets, reference provider, icon
component, search provider IDs and every user-facing string. GoToSocial
calls them posts, not toots, and its mascot is a sloth.
Deliberately NOT rebranded: MastodonAPIService, MastodonAPIController,
route names and config keys. They speak the Mastodon client API, which is
what GoToSocial implements -- renaming them would make the code claim a
protocol that does not exist, and would make this fork expensive to rebase
on future upstream releases.
Translations are inherited. Strings reworded by the rebrand fall back to
English; the rest still work in all 124 locales.
Assisted-by: Claude Code:claude-opus-5
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Nextcloud - GoToSocial
|
|
*
|
|
*
|
|
* @author Julien Veyssier <julien-nc@posteo.net>
|
|
* @copyright Julien Veyssier 2020
|
|
*/
|
|
|
|
namespace OCA\GoToSocial\AppInfo;
|
|
|
|
use Closure;
|
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
|
use OCA\GoToSocial\Dashboard\GoToSocialHomeWidget;
|
|
use OCA\GoToSocial\Dashboard\GoToSocialWidget;
|
|
use OCA\GoToSocial\Listener\LoadAdditionalScriptsListener;
|
|
use OCA\GoToSocial\Reference\GoToSocialReferenceProvider;
|
|
use OCA\GoToSocial\Search\SearchAccountsProvider;
|
|
use OCA\GoToSocial\Search\SearchHashtagsProvider;
|
|
use OCA\GoToSocial\Search\SearchStatusesProvider;
|
|
use OCA\GoToSocial\Service\MastodonAPIService;
|
|
use OCP\AppFramework\App;
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
|
use OCP\IConfig;
|
|
use OCP\IL10N;
|
|
use OCP\INavigationManager;
|
|
use OCP\IURLGenerator;
|
|
use OCP\IUserSession;
|
|
|
|
class Application extends App implements IBootstrap {
|
|
|
|
public const APP_ID = 'integration_gotosocial';
|
|
|
|
public function __construct(array $urlParams = []) {
|
|
parent::__construct(self::APP_ID, $urlParams);
|
|
}
|
|
|
|
public function register(IRegistrationContext $context): void {
|
|
$context->registerDashboardWidget(GoToSocialWidget::class);
|
|
$context->registerDashboardWidget(GoToSocialHomeWidget::class);
|
|
|
|
$context->registerSearchProvider(SearchStatusesProvider::class);
|
|
$context->registerSearchProvider(SearchAccountsProvider::class);
|
|
$context->registerSearchProvider(SearchHashtagsProvider::class);
|
|
|
|
$context->registerReferenceProvider(GoToSocialReferenceProvider::class);
|
|
|
|
// for socialsharing
|
|
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class);
|
|
}
|
|
|
|
public function boot(IBootContext $context): void {
|
|
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
|
|
}
|
|
|
|
public function registerNavigation(IUserSession $userSession, IConfig $config, MastodonAPIService $mastodonAPIService): void {
|
|
$user = $userSession->getUser();
|
|
if ($user !== null) {
|
|
$userId = $user->getUID();
|
|
$container = $this->getContainer();
|
|
|
|
if ($config->getUserValue($userId, self::APP_ID, 'navigation_enabled', '0') === '1') {
|
|
$mastodonUrl = $mastodonAPIService->getGoToSocialUrl($userId);
|
|
if ($mastodonUrl !== '') {
|
|
$container->get(INavigationManager::class)->add(function () use ($container, $mastodonUrl) {
|
|
$urlGenerator = $container->get(IURLGenerator::class);
|
|
$l10n = $container->get(IL10N::class);
|
|
return [
|
|
'id' => self::APP_ID,
|
|
'order' => 10,
|
|
'href' => $mastodonUrl,
|
|
'target' => '_blank',
|
|
'icon' => $urlGenerator->imagePath(self::APP_ID, 'app.svg'),
|
|
'name' => $l10n->t('GoToSocial'),
|
|
];
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|