diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-10-10 16:11:25 +0200 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2023-10-31 11:52:46 -0700 |
commit | ac168cf9ff07ef57cda2453626e25d5a00283c21 (patch) | |
tree | 541e9e351b9e5625c12a5dea8b0e121ac1c5496b /lib/private/Contacts | |
parent | b4e707059def28bf4544ae43272bf62d5662961b (diff) | |
download | nextcloud-server-ac168cf9ff07ef57cda2453626e25d5a00283c21.tar.gz nextcloud-server-ac168cf9ff07ef57cda2453626e25d5a00283c21.zip |
feat(contactsmenu): Show user status
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Contacts')
-rw-r--r-- | lib/private/Contacts/ContactsMenu/ActionProviderStore.php | 13 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/ContactsStore.php | 2 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/Entry.php | 30 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/Manager.php | 13 |
4 files changed, 49 insertions, 9 deletions
diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php index 7ba5db4bb33..67354a5fb2d 100644 --- a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php +++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php @@ -33,6 +33,7 @@ use OC\Contacts\ContactsMenu\Providers\EMailProvider; use OC\Contacts\ContactsMenu\Providers\LocalTimeProvider; use OC\Contacts\ContactsMenu\Providers\ProfileProvider; use OCP\AppFramework\QueryException; +use OCP\Contacts\ContactsMenu\IBulkProvider; use OCP\Contacts\ContactsMenu\IProvider; use OCP\IServerContainer; use OCP\IUser; @@ -47,18 +48,26 @@ class ActionProviderStore { } /** - * @return IProvider[] + * @return list<IProvider|IBulkProvider> * @throws Exception */ public function getProviders(IUser $user): array { $appClasses = $this->getAppProviderClasses($user); $providerClasses = $this->getServerProviderClasses(); $allClasses = array_merge($providerClasses, $appClasses); + /** @var list<IProvider|IBulkProvider> $providers */ $providers = []; foreach ($allClasses as $class) { try { - $providers[] = $this->serverContainer->get($class); + $provider = $this->serverContainer->get($class); + if ($provider instanceof IProvider || $provider instanceof IBulkProvider) { + $providers[] = $provider; + } else { + $this->logger->warning('Ignoring invalid contacts menu provider', [ + 'class' => $class, + ]); + } } catch (QueryException $ex) { $this->logger->error( 'Could not load contacts menu action provider ' . $class, diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index c692b486ae4..189d7eede1c 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -268,8 +268,10 @@ class ContactsStore implements IContactsStore { if (isset($contact['UID'])) { $uid = $contact['UID']; $entry->setId($uid); + $entry->setProperty('isUser', false); if (isset($contact['isLocalSystemBook'])) { $avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]); + $entry->setProperty('isUser', true); } elseif (isset($contact['FN'])) { $avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $contact['FN'], 'size' => 64]); } else { diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php index f1cb4f9c52f..ee55a74b051 100644 --- a/lib/private/Contacts/ContactsMenu/Entry.php +++ b/lib/private/Contacts/ContactsMenu/Entry.php @@ -29,6 +29,7 @@ namespace OC\Contacts\ContactsMenu; use OCP\Contacts\ContactsMenu\IAction; use OCP\Contacts\ContactsMenu\IEntry; +use function array_merge; class Entry implements IEntry { /** @var string|int|null */ @@ -50,6 +51,10 @@ class Entry implements IEntry { private array $properties = []; + private ?string $status = null; + private ?string $statusMessage = null; + private ?string $statusIcon = null; + public function setId(string $id): void { $this->id = $id; } @@ -102,6 +107,14 @@ class Entry implements IEntry { $this->sortActions(); } + public function setStatus(string $status, + string $statusMessage = null, + string $icon = null): void { + $this->status = $status; + $this->statusMessage = $statusMessage; + $this->statusIcon = $icon; + } + /** * @return IAction[] */ @@ -127,11 +140,15 @@ class Entry implements IEntry { }); } + public function setProperty(string $propertyName, mixed $value) { + $this->properties[$propertyName] = $value; + } + /** - * @param array $contact key-value array containing additional properties + * @param array $properties key-value array containing additional properties */ - public function setProperties(array $contact): void { - $this->properties = $contact; + public function setProperties(array $properties): void { + $this->properties = array_merge($this->properties, $properties); } public function getProperty(string $key): mixed { @@ -142,7 +159,7 @@ class Entry implements IEntry { } /** - * @return array{id: int|string|null, fullName: string, avatar: string|null, topAction: mixed, actions: array, lastMessage: '', emailAddresses: string[], profileTitle: string|null, profileUrl: string|null} + * @return array{id: int|string|null, fullName: string, avatar: string|null, topAction: mixed, actions: array, lastMessage: '', emailAddresses: string[], profileTitle: string|null, profileUrl: string|null, status: string|null, statusMessage: null|string, statusIcon: null|string, isUser: bool, uid: mixed} */ public function jsonSerialize(): array { $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; @@ -160,6 +177,11 @@ class Entry implements IEntry { 'emailAddresses' => $this->getEMailAddresses(), 'profileTitle' => $this->profileTitle, 'profileUrl' => $this->profileUrl, + 'status' => $this->status, + 'statusMessage' => $this->statusMessage, + 'statusIcon' => $this->statusIcon, + 'isUser' => $this->getProperty('isUser') === true, + 'uid' => $this->getProperty('UID'), ]; } } diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php index 490cf602283..22dbb524046 100644 --- a/lib/private/Contacts/ContactsMenu/Manager.php +++ b/lib/private/Contacts/ContactsMenu/Manager.php @@ -28,7 +28,9 @@ namespace OC\Contacts\ContactsMenu; use Exception; use OCP\App\IAppManager; use OCP\Constants; +use OCP\Contacts\ContactsMenu\IBulkProvider; use OCP\Contacts\ContactsMenu\IEntry; +use OCP\Contacts\ContactsMenu\IProvider; use OCP\IConfig; use OCP\IUser; @@ -92,9 +94,14 @@ class Manager { */ private function processEntries(array $entries, IUser $user): void { $providers = $this->actionProviderStore->getProviders($user); - foreach ($entries as $entry) { - foreach ($providers as $provider) { - $provider->process($entry); + + foreach ($providers as $provider) { + if ($provider instanceof IBulkProvider && !($provider instanceof IProvider)) { + $provider->process($entries); + } elseif ($provider instanceof IProvider && !($provider instanceof IBulkProvider)) { + foreach ($entries as $entry) { + $provider->process($entry); + } } } } |