aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Profile
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Profile')
-rw-r--r--lib/private/Profile/Actions/BlueskyAction.php65
-rw-r--r--lib/private/Profile/ProfileManager.php31
2 files changed, 96 insertions, 0 deletions
diff --git a/lib/private/Profile/Actions/BlueskyAction.php b/lib/private/Profile/Actions/BlueskyAction.php
new file mode 100644
index 00000000000..d05682aac1a
--- /dev/null
+++ b/lib/private/Profile/Actions/BlueskyAction.php
@@ -0,0 +1,65 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Profile\Actions;
+
+use OCP\Accounts\IAccountManager;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\L10N\IFactory;
+use OCP\Profile\ILinkAction;
+
+class BlueskyAction implements ILinkAction {
+ private string $value = '';
+
+ public function __construct(
+ private IAccountManager $accountManager,
+ private IFactory $l10nFactory,
+ private IURLGenerator $urlGenerator,
+ ) {
+ }
+
+ public function preload(IUser $targetUser): void {
+ $account = $this->accountManager->getAccount($targetUser);
+ $this->value = $account->getProperty(IAccountManager::PROPERTY_BLUESKY)->getValue();
+ }
+
+ public function getAppId(): string {
+ return 'core';
+ }
+
+ public function getId(): string {
+ return IAccountManager::PROPERTY_BLUESKY;
+ }
+
+ public function getDisplayId(): string {
+ return $this->l10nFactory->get('lib')->t('Bluesky');
+ }
+
+ public function getTitle(): string {
+ $displayUsername = $this->value;
+ return $this->l10nFactory->get('lib')->t('View %s on Bluesky', [$displayUsername]);
+ }
+
+ public function getPriority(): int {
+ return 60;
+ }
+
+ public function getIcon(): string {
+ return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/bluesky.svg'));
+ }
+
+ public function getTarget(): ?string {
+ if (empty($this->value)) {
+ return null;
+ }
+ $username = $this->value;
+ return 'https://bsky.app/profile/' . $username;
+ }
+}
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php
index 1ade208fbcf..c38412f6bd0 100644
--- a/lib/private/Profile/ProfileManager.php
+++ b/lib/private/Profile/ProfileManager.php
@@ -10,10 +10,12 @@ declare(strict_types=1);
namespace OC\Profile;
use OC\AppFramework\Bootstrap\Coordinator;
+use OC\Config\PresetManager;
use OC\Core\Db\ProfileConfig;
use OC\Core\Db\ProfileConfigMapper;
use OC\Core\ResponseDefinitions;
use OC\KnownUser\KnownUserService;
+use OC\Profile\Actions\BlueskyAction;
use OC\Profile\Actions\EmailAction;
use OC\Profile\Actions\FediverseAction;
use OC\Profile\Actions\PhoneAction;
@@ -24,6 +26,7 @@ use OCP\Accounts\PropertyDoesNotExistException;
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Cache\CappedMemoryCache;
+use OCP\Config\Lexicon\Preset;
use OCP\IConfig;
use OCP\IUser;
use OCP\L10N\IFactory;
@@ -56,6 +59,7 @@ class ProfileManager implements IProfileManager {
PhoneAction::class,
WebsiteAction::class,
TwitterAction::class,
+ BlueskyAction::class,
FediverseAction::class,
];
@@ -83,6 +87,7 @@ class ProfileManager implements IProfileManager {
private IFactory $l10nFactory,
private LoggerInterface $logger,
private Coordinator $coordinator,
+ private readonly PresetManager $presetManager,
) {
$this->configCache = new CappedMemoryCache();
}
@@ -313,6 +318,7 @@ class ProfileManager implements IProfileManager {
// Construct the default config for account properties
$propertiesConfig = [];
foreach (self::DEFAULT_PROPERTY_VISIBILITY as $property => $visibility) {
+ $this->applyDefaultProfilePreset($property, $visibility);
$propertiesConfig[$property] = ['visibility' => $visibility];
}
@@ -320,6 +326,31 @@ class ProfileManager implements IProfileManager {
}
/**
+ * modify property visibility, based on current Preset
+ *
+ * @psalm-suppress UnhandledMatchCondition if conditions are not met, we do not change $visibility
+ */
+ private function applyDefaultProfilePreset(string $property, string &$visibility): void {
+ try {
+ $overwrite = match ($this->presetManager->getLexiconPreset()) {
+ Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match ($property) {
+ IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
+ },
+ Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match ($property) {
+ IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
+ },
+ Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match ($property) {
+ IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
+ },
+ };
+ } catch (\UnhandledMatchError) {
+ return;
+ }
+
+ $visibility = $overwrite;
+ }
+
+ /**
* Return the profile config of the target user,
* if a config does not already exist a default config is created and returned
*/