aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-03-22 12:39:23 +0100
committerThomas Citharel <tcit@tcit.fr>2022-05-12 18:31:59 +0200
commit232322fe062031d5fe5b5297ca60b22bc1da1d30 (patch)
treea2591d9ed9caf669cbc7c16142a84b00f435df8f /lib
parent32139610c5e11ee84c71cc1db3e58523f749aa27 (diff)
downloadnextcloud-server-232322fe062031d5fe5b5297ca60b22bc1da1d30.tar.gz
nextcloud-server-232322fe062031d5fe5b5297ca60b22bc1da1d30.zip
Modernize contacts menu
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Contacts/ContactsMenu/ActionProviderStore.php14
-rw-r--r--lib/private/Contacts/ContactsMenu/Actions/LinkAction.php54
-rw-r--r--lib/private/Contacts/ContactsMenu/ContactsStore.php56
-rw-r--r--lib/private/Contacts/ContactsMenu/Entry.php52
-rw-r--r--lib/private/Contacts/ContactsMenu/Manager.php37
-rw-r--r--lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php12
-rw-r--r--lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php27
-rw-r--r--lib/public/Contacts/ContactsMenu/IAction.php10
-rw-r--r--lib/public/Contacts/ContactsMenu/IContactsStore.php14
-rw-r--r--lib/public/Contacts/ContactsMenu/ILinkAction.php6
10 files changed, 69 insertions, 213 deletions
diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
index 1db99497a21..c93879afa5b 100644
--- a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
+++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
@@ -38,15 +38,9 @@ use OCP\IUser;
use Psr\Log\LoggerInterface;
class ActionProviderStore {
-
- /** @var IServerContainer */
- private $serverContainer;
-
- /** @var AppManager */
- private $appManager;
-
- /** @var LoggerInterface */
- private $logger;
+ private IServerContainer $serverContainer;
+ private AppManager $appManager;
+ private LoggerInterface $logger;
public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
$this->serverContainer = $serverContainer;
@@ -67,7 +61,7 @@ class ActionProviderStore {
foreach ($allClasses as $class) {
try {
- $providers[] = $this->serverContainer->query($class);
+ $providers[] = $this->serverContainer->get($class);
} catch (QueryException $ex) {
$this->logger->error(
'Could not load contacts menu action provider ' . $class,
diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
index 3f917854aac..a3054c9ee52 100644
--- a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
+++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
@@ -25,73 +25,44 @@ namespace OC\Contacts\ContactsMenu\Actions;
use OCP\Contacts\ContactsMenu\ILinkAction;
class LinkAction implements ILinkAction {
-
- /** @var string */
- private $icon;
-
- /** @var string */
- private $name;
-
- /** @var string */
- private $href;
-
- /** @var int */
- private $priority = 10;
-
- /** @var string */
- private $appId;
+ private string $icon = '';
+ private string $name = '';
+ private string $href = '';
+ private int $priority = 10;
+ private string $appId = '';
/**
* @param string $icon absolute URI to an icon
*/
- public function setIcon($icon) {
+ public function setIcon(string $icon) {
$this->icon = $icon;
}
- /**
- * @param string $name
- */
- public function setName($name) {
+ public function setName(string $name) {
$this->name = $name;
}
- /**
- * @return string
- */
- public function getName() {
+ public function getName(): string {
return $this->name;
}
- /**
- * @param int $priority
- */
- public function setPriority($priority) {
+ public function setPriority(int $priority) {
$this->priority = $priority;
}
- /**
- * @return int
- */
- public function getPriority() {
+ public function getPriority(): int {
return $this->priority;
}
- /**
- * @param string $href
- */
- public function setHref($href) {
+ public function setHref(string $href) {
$this->href = $href;
}
- /**
- * @return string
- */
- public function getHref() {
+ public function getHref(): string {
return $this->href;
}
/**
- * @param string $appId
* @since 23.0.0
*/
public function setAppId(string $appId) {
@@ -99,7 +70,6 @@ class LinkAction implements ILinkAction {
}
/**
- * @return string
* @since 23.0.0
*/
public function getAppId(): string {
diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php
index 0ac388ce00a..020e8604910 100644
--- a/lib/private/Contacts/ContactsMenu/ContactsStore.php
+++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php
@@ -44,30 +44,14 @@ use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
class ContactsStore implements IContactsStore {
-
- /** @var IManager */
- private $contactsManager;
-
- /** @var IConfig */
- private $config;
-
- /** @var ProfileManager */
- private $profileManager;
-
- /** @var IUserManager */
- private $userManager;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var IGroupManager */
- private $groupManager;
-
- /** @var KnownUserService */
- private $knownUserService;
-
- /** @var IL10NFactory */
- private $l10nFactory;
+ private IManager $contactsManager;
+ private IConfig $config;
+ private ProfileManager $profileManager;
+ private IUserManager $userManager;
+ private IURLGenerator $urlGenerator;
+ private IGroupManager $groupManager;
+ private KnownUserService $knownUserService;
+ private IL10NFactory $l10nFactory;
public function __construct(
IManager $contactsManager,
@@ -90,11 +74,9 @@ class ContactsStore implements IContactsStore {
}
/**
- * @param IUser $user
- * @param string|null $filter
* @return IEntry[]
*/
- public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
+ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array {
$options = [
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
@@ -152,8 +134,8 @@ class ContactsStore implements IContactsStore {
private function filterContacts(
IUser $self,
array $entries,
- $filter
- ) {
+ ?string $filter
+ ): array {
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
@@ -168,7 +150,7 @@ class ContactsStore implements IContactsStore {
$selfGroups = $this->groupManager->getUserGroupIds($self);
if ($excludedGroups) {
- $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
+ $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list');
$decodedExcludeGroups = json_decode($excludedGroups, true);
$excludeGroupsList = $decodedExcludeGroups ?? [];
@@ -253,13 +235,7 @@ class ContactsStore implements IContactsStore {
}));
}
- /**
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry|null
- */
- public function findOne(IUser $user, $shareType, $shareWith) {
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
switch ($shareType) {
case 0:
case 6:
@@ -305,11 +281,7 @@ class ContactsStore implements IContactsStore {
return $match;
}
- /**
- * @param array $contact
- * @return Entry
- */
- private function contactArrayToEntry(array $contact) {
+ private function contactArrayToEntry(array $contact): Entry {
$entry = new Entry();
if (isset($contact['id'])) {
diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php
index 915a0434cc8..3bbe679e999 100644
--- a/lib/private/Contacts/ContactsMenu/Entry.php
+++ b/lib/private/Contacts/ContactsMenu/Entry.php
@@ -35,51 +35,34 @@ class Entry implements IEntry {
/** @var string|int|null */
private $id = null;
- /** @var string */
- private $fullName = '';
+ private string $fullName = '';
/** @var string[] */
- private $emailAddresses = [];
+ private array $emailAddresses = [];
- /** @var string|null */
- private $avatar;
+ private ?string $avatar = null;
- /** @var string|null */
- private $profileTitle;
+ private ?string $profileTitle = null;
- /** @var string|null */
- private $profileUrl;
+ private ?string $profileUrl = null;
/** @var IAction[] */
- private $actions = [];
+ private array $actions = [];
- /** @var array */
- private $properties = [];
+ private array $properties = [];
- /**
- * @param string $id
- */
public function setId(string $id): void {
$this->id = $id;
}
- /**
- * @param string $displayName
- */
public function setFullName(string $displayName): void {
$this->fullName = $displayName;
}
- /**
- * @return string
- */
public function getFullName(): string {
return $this->fullName;
}
- /**
- * @param string $address
- */
public function addEMailAddress(string $address): void {
$this->emailAddresses[] = $address;
}
@@ -91,51 +74,30 @@ class Entry implements IEntry {
return $this->emailAddresses;
}
- /**
- * @param string $avatar
- */
public function setAvatar(string $avatar): void {
$this->avatar = $avatar;
}
- /**
- * @return string
- */
public function getAvatar(): ?string {
return $this->avatar;
}
- /**
- * @param string $profileTitle
- */
public function setProfileTitle(string $profileTitle): void {
$this->profileTitle = $profileTitle;
}
- /**
- * @return string
- */
public function getProfileTitle(): ?string {
return $this->profileTitle;
}
- /**
- * @param string $profileUrl
- */
public function setProfileUrl(string $profileUrl): void {
$this->profileUrl = $profileUrl;
}
- /**
- * @return string
- */
public function getProfileUrl(): ?string {
return $this->profileUrl;
}
- /**
- * @param IAction $action
- */
public function addAction(IAction $action): void {
$this->actions[] = $action;
$this->sortActions();
diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php
index 73a5a475d85..5c3367a3d09 100644
--- a/lib/private/Contacts/ContactsMenu/Manager.php
+++ b/lib/private/Contacts/ContactsMenu/Manager.php
@@ -25,6 +25,7 @@
*/
namespace OC\Contacts\ContactsMenu;
+use Exception;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Contacts\ContactsMenu\IEntry;
@@ -32,24 +33,11 @@ use OCP\IConfig;
use OCP\IUser;
class Manager {
+ private ContactsStore $store;
+ private ActionProviderStore $actionProviderStore;
+ private IAppManager $appManager;
+ private IConfig $config;
- /** @var ContactsStore */
- private $store;
-
- /** @var ActionProviderStore */
- private $actionProviderStore;
-
- /** @var IAppManager */
- private $appManager;
-
- /** @var IConfig */
- private $config;
-
- /**
- * @param ContactsStore $store
- * @param ActionProviderStore $actionProviderStore
- * @param IAppManager $appManager
- */
public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) {
$this->store = $store;
$this->actionProviderStore = $actionProviderStore;
@@ -61,10 +49,11 @@ class Manager {
* @param IUser $user
* @param string|null $filter
* @return array
+ * @throws Exception
*/
- public function getEntries(IUser $user, $filter) {
+ public function getEntries(IUser $user, ?string $filter): array {
$maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT));
- $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
+ $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength');
$topEntries = [];
if (strlen($filter ?? '') >= $minSearchStringLength) {
$entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults);
@@ -82,12 +71,9 @@ class Manager {
}
/**
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry
+ * @throws Exception
*/
- public function findOne(IUser $user, $shareType, $shareWith) {
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
$entry = $this->store->findOne($user, $shareType, $shareWith);
if ($entry) {
$this->processEntries([$entry], $user);
@@ -100,7 +86,7 @@ class Manager {
* @param IEntry[] $entries
* @return IEntry[]
*/
- private function sortEntries(array $entries) {
+ private function sortEntries(array $entries): array {
usort($entries, function (IEntry $entryA, IEntry $entryB) {
return strcasecmp($entryA->getFullName(), $entryB->getFullName());
});
@@ -110,6 +96,7 @@ class Manager {
/**
* @param IEntry[] $entries
* @param IUser $user
+ * @throws Exception
*/
private function processEntries(array $entries, IUser $user) {
$providers = $this->actionProviderStore->getProviders($user);
diff --git a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php
index d69f219e84c..b79052e1f5d 100644
--- a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php
+++ b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php
@@ -28,17 +28,9 @@ use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IURLGenerator;
class EMailProvider implements IProvider {
+ private IActionFactory $actionFactory;
+ private IURLGenerator $urlGenerator;
- /** @var IActionFactory */
- private $actionFactory;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /**
- * @param IActionFactory $actionFactory
- * @param IURLGenerator $urlGenerator
- */
public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) {
$this->actionFactory = $actionFactory;
$this->urlGenerator = $urlGenerator;
diff --git a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
index e654319c3fa..af941fd7fd1 100644
--- a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
+++ b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
@@ -33,29 +33,12 @@ use OCP\IUserManager;
use OCP\L10N\IFactory as IL10NFactory;
class ProfileProvider implements IProvider {
+ private IActionFactory $actionFactory;
+ private ProfileManager $profileManager;
+ private IL10NFactory $l10nFactory;
+ private IURLGenerator $urlGenerator;
+ private IUserManager $userManager;
- /** @var IActionFactory */
- private $actionFactory;
-
- /** @var ProfileManager */
- private $profileManager;
-
- /** @var IL10NFactory */
- private $l10nFactory;
-
- /** @var IURLGenerator */
- private $urlGenerator;
-
- /** @var IUserManager */
- private $userManager;
-
- /**
- * @param IActionFactory $actionFactory
- * @param ProfileManager $profileManager
- * @param IL10NFactory $l10nFactory
- * @param IURLGenerator $urlGenerator
- * @param IUserManager $userManager
- */
public function __construct(
IActionFactory $actionFactory,
ProfileManager $profileManager,
diff --git a/lib/public/Contacts/ContactsMenu/IAction.php b/lib/public/Contacts/ContactsMenu/IAction.php
index 9b08bbbf04b..f6022fefac3 100644
--- a/lib/public/Contacts/ContactsMenu/IAction.php
+++ b/lib/public/Contacts/ContactsMenu/IAction.php
@@ -35,31 +35,31 @@ interface IAction extends JsonSerializable {
* @param string $icon absolute URI to an icon
* @since 12.0
*/
- public function setIcon($icon);
+ public function setIcon(string $icon);
/**
* @return string localized action name, e.g. 'Call'
* @since 12.0
*/
- public function getName();
+ public function getName(): string;
/**
* @param string $name localized action name, e.g. 'Call'
* @since 12.0
*/
- public function setName($name);
+ public function setName(string $name);
/**
* @param int $priority priorize actions, high order ones are shown on top
* @since 12.0
*/
- public function setPriority($priority);
+ public function setPriority(int $priority);
/**
* @return int priority to priorize actions, high order ones are shown on top
* @since 12.0
*/
- public function getPriority();
+ public function getPriority(): int;
/**
* @param string $appId
diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php
index 3aa51888450..8b36f9cde5c 100644
--- a/lib/public/Contacts/ContactsMenu/IContactsStore.php
+++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php
@@ -34,21 +34,17 @@ interface IContactsStore {
/**
* @param IUser $user
- * @param string $filter
- * @param int $limit added 19.0.2
- * @param int $offset added 19.0.2
+ * @param string|null $filter
+ * @param int|null $limit added 19.0.2
+ * @param int|null $offset added 19.0.2
* @return IEntry[]
* @since 13.0.0
*/
- public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null);
+ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array;
/**
* @brief finds a contact by specifying the property to search on ($shareType) and the value ($shareWith)
- * @param IUser $user
- * @param integer $shareType
- * @param string $shareWith
- * @return IEntry|null
* @since 13.0.0
*/
- public function findOne(IUser $user, $shareType, $shareWith);
+ public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry;
}
diff --git a/lib/public/Contacts/ContactsMenu/ILinkAction.php b/lib/public/Contacts/ContactsMenu/ILinkAction.php
index 63e77f5446f..936dd22bcf2 100644
--- a/lib/public/Contacts/ContactsMenu/ILinkAction.php
+++ b/lib/public/Contacts/ContactsMenu/ILinkAction.php
@@ -28,14 +28,14 @@ namespace OCP\Contacts\ContactsMenu;
interface ILinkAction extends IAction {
/**
- * @since 12.0
* @param string $href the target URL of the action
+ * @since 12.0
*/
- public function setHref($href);
+ public function setHref(string $href);
/**
* @since 12.0
* @return string
*/
- public function getHref();
+ public function getHref(): string;
}