diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-01-24 07:47:14 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2017-04-25 20:47:17 +0200 |
commit | d091793ceb1ab2a60133608e844e1d83a5de19f2 (patch) | |
tree | 12c4c5863c5ede094a78c534e03d6718823abb04 /lib | |
parent | db94b5d4af711f6e18aac0c9d4b0357a3b9123d1 (diff) | |
download | nextcloud-server-d091793ceb1ab2a60133608e844e1d83a5de19f2.tar.gz nextcloud-server-d091793ceb1ab2a60133608e844e1d83a5de19f2.zip |
Contacts menu
* load list of contacts from the server
* show last message of each contact
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
18 files changed, 963 insertions, 8 deletions
diff --git a/lib/composer/composer/ClassLoader.php b/lib/composer/composer/ClassLoader.php index 2c72175e772..4626994fd4d 100644 --- a/lib/composer/composer/ClassLoader.php +++ b/lib/composer/composer/ClassLoader.php @@ -374,13 +374,9 @@ class ClassLoader $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { - $subPath = $class; - while (false !== $lastPos = strrpos($subPath, '\\')) { - $subPath = substr($subPath, 0, $lastPos); - $search = $subPath.'\\'; - if (isset($this->prefixDirsPsr4[$search])) { - foreach ($this->prefixDirsPsr4[$search] as $dir) { - $length = $this->prefixLengthsPsr4[$first][$search]; + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { return $file; } diff --git a/lib/composer/composer/LICENSE b/lib/composer/composer/LICENSE index f27399a042d..1a28124886d 100644 --- a/lib/composer/composer/LICENSE +++ b/lib/composer/composer/LICENSE @@ -1,5 +1,5 @@ -Copyright (c) Nils Adermann, Jordi Boggiano +Copyright (c) 2016 Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 0d5f067779d..0e858a54aeb 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -80,6 +80,11 @@ return array( 'OCP\\Console\\ConsoleEvent' => $baseDir . '/lib/public/Console/ConsoleEvent.php', 'OCP\\Constants' => $baseDir . '/lib/public/Constants.php', 'OCP\\Contacts' => $baseDir . '/lib/public/Contacts.php', + 'OCP\\Contacts\\ContactsMenu\\IAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/IAction.php', + 'OCP\\Contacts\\ContactsMenu\\IActionFactory' => $baseDir . '/lib/public/Contacts/ContactsMenu/IActionFactory.php', + 'OCP\\Contacts\\ContactsMenu\\IEntry' => $baseDir . '/lib/public/Contacts/ContactsMenu/IEntry.php', + 'OCP\\Contacts\\ContactsMenu\\ILinkAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/ILinkAction.php', + 'OCP\\Contacts\\ContactsMenu\\IProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IProvider.php', 'OCP\\Contacts\\IManager' => $baseDir . '/lib/public/Contacts/IManager.php', 'OCP\\DB' => $baseDir . '/lib/public/DB.php', 'OCP\\DB\\QueryBuilder\\ICompositeExpression' => $baseDir . '/lib/public/DB/QueryBuilder/ICompositeExpression.php', @@ -373,6 +378,14 @@ return array( 'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php', 'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php', 'OC\\ContactsManager' => $baseDir . '/lib/private/ContactsManager.php', + 'OC\\Contacts\\ContactsMenu\\ActionFactory' => $baseDir . '/lib/private/Contacts/ContactsMenu/ActionFactory.php', + 'OC\\Contacts\\ContactsMenu\\ActionProviderStore' => $baseDir . '/lib/private/Contacts/ContactsMenu/ActionProviderStore.php', + 'OC\\Contacts\\ContactsMenu\\Actions\\LinkAction' => $baseDir . '/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php', + 'OC\\Contacts\\ContactsMenu\\ContactsStore' => $baseDir . '/lib/private/Contacts/ContactsMenu/ContactsStore.php', + 'OC\\Contacts\\ContactsMenu\\Entry' => $baseDir . '/lib/private/Contacts/ContactsMenu/Entry.php', + 'OC\\Contacts\\ContactsMenu\\Manager' => $baseDir . '/lib/private/Contacts/ContactsMenu/Manager.php', + 'OC\\Contacts\\ContactsMenu\\Providers\\DetailsProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/DetailsProvider.php', + 'OC\\Contacts\\ContactsMenu\\Providers\\EMailProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php', 'OC\\Core\\Application' => $baseDir . '/core/Application.php', 'OC\\Core\\Command\\App\\CheckCode' => $baseDir . '/core/Command/App/CheckCode.php', 'OC\\Core\\Command\\App\\Disable' => $baseDir . '/core/Command/App/Disable.php', @@ -444,6 +457,7 @@ return array( 'OC\\Core\\Command\\User\\ResetPassword' => $baseDir . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\Setting' => $baseDir . '/core/Command/User/Setting.php', 'OC\\Core\\Controller\\AvatarController' => $baseDir . '/core/Controller/AvatarController.php', + 'OC\\Core\\Controller\\ContactsMenuController' => $baseDir . '/core/Controller/ContactsMenuController.php', 'OC\\Core\\Controller\\CssController' => $baseDir . '/core/Controller/CssController.php', 'OC\\Core\\Controller\\JsController' => $baseDir . '/core/Controller/JsController.php', 'OC\\Core\\Controller\\LoginController' => $baseDir . '/core/Controller/LoginController.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 82c31c24a21..73fba39b23a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -110,6 +110,11 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Console\\ConsoleEvent' => __DIR__ . '/../../..' . '/lib/public/Console/ConsoleEvent.php', 'OCP\\Constants' => __DIR__ . '/../../..' . '/lib/public/Constants.php', 'OCP\\Contacts' => __DIR__ . '/../../..' . '/lib/public/Contacts.php', + 'OCP\\Contacts\\ContactsMenu\\IAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IAction.php', + 'OCP\\Contacts\\ContactsMenu\\IActionFactory' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IActionFactory.php', + 'OCP\\Contacts\\ContactsMenu\\IEntry' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IEntry.php', + 'OCP\\Contacts\\ContactsMenu\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/ILinkAction.php', + 'OCP\\Contacts\\ContactsMenu\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IProvider.php', 'OCP\\Contacts\\IManager' => __DIR__ . '/../../..' . '/lib/public/Contacts/IManager.php', 'OCP\\DB' => __DIR__ . '/../../..' . '/lib/public/DB.php', 'OCP\\DB\\QueryBuilder\\ICompositeExpression' => __DIR__ . '/../../..' . '/lib/public/DB/QueryBuilder/ICompositeExpression.php', @@ -403,6 +408,14 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php', 'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php', 'OC\\ContactsManager' => __DIR__ . '/../../..' . '/lib/private/ContactsManager.php', + 'OC\\Contacts\\ContactsMenu\\ActionFactory' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/ActionFactory.php', + 'OC\\Contacts\\ContactsMenu\\ActionProviderStore' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/ActionProviderStore.php', + 'OC\\Contacts\\ContactsMenu\\Actions\\LinkAction' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php', + 'OC\\Contacts\\ContactsMenu\\ContactsStore' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/ContactsStore.php', + 'OC\\Contacts\\ContactsMenu\\Entry' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Entry.php', + 'OC\\Contacts\\ContactsMenu\\Manager' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Manager.php', + 'OC\\Contacts\\ContactsMenu\\Providers\\DetailsProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/DetailsProvider.php', + 'OC\\Contacts\\ContactsMenu\\Providers\\EMailProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php', 'OC\\Core\\Application' => __DIR__ . '/../../..' . '/core/Application.php', 'OC\\Core\\Command\\App\\CheckCode' => __DIR__ . '/../../..' . '/core/Command/App/CheckCode.php', 'OC\\Core\\Command\\App\\Disable' => __DIR__ . '/../../..' . '/core/Command/App/Disable.php', @@ -474,6 +487,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Command\\User\\ResetPassword' => __DIR__ . '/../../..' . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\Setting' => __DIR__ . '/../../..' . '/core/Command/User/Setting.php', 'OC\\Core\\Controller\\AvatarController' => __DIR__ . '/../../..' . '/core/Controller/AvatarController.php', + 'OC\\Core\\Controller\\ContactsMenuController' => __DIR__ . '/../../..' . '/core/Controller/ContactsMenuController.php', 'OC\\Core\\Controller\\CssController' => __DIR__ . '/../../..' . '/core/Controller/CssController.php', 'OC\\Core\\Controller\\JsController' => __DIR__ . '/../../..' . '/core/Controller/JsController.php', 'OC\\Core\\Controller\\LoginController' => __DIR__ . '/../../..' . '/core/Controller/LoginController.php', diff --git a/lib/private/Contacts/ContactsMenu/ActionFactory.php b/lib/private/Contacts/ContactsMenu/ActionFactory.php new file mode 100644 index 00000000000..1d2a69c904d --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/ActionFactory.php @@ -0,0 +1,57 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu; + +use OC\Contacts\ContactsMenu\Actions\LinkAction; +use OCP\Contacts\ContactsMenu\IActionFactory; +use OCP\Contacts\ContactsMenu\ILinkAction; + +class ActionFactory implements IActionFactory { + + /** + * @param string $icon + * @param string $name + * @param string $href + * @return ILinkAction + */ + public function newLinkAction($icon, $name, $href) { + $action = new LinkAction(); + $action->setName($name); + $action->setIcon($icon); + $action->setHref($href); + return $action; + } + + /** + * @param string $icon + * @param string $name + * @param string $email + * @return ILinkAction + */ + public function newEMailAction($icon, $name, $email) { + return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); + } + +} diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php new file mode 100644 index 00000000000..cc5996377dd --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php @@ -0,0 +1,82 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu; + +use OC\Contacts\ContactsMenu\Providers\EMailProvider; +use OCP\AppFramework\QueryException; +use OCP\Contacts\ContactsMenu\IProvider; +use OCP\ILogger; +use OCP\IServerContainer; + +class ActionProviderStore { + + /** @var IServerContainer */ + private $serverContainer; + + /** @var ILogger */ + private $logger; + + /** + * @param IServerContainer $serverContainer + */ + public function __construct(IServerContainer $serverContainer, ILogger $logger) { + $this->serverContainer = $serverContainer; + $this->logger = $logger; + } + + /** + * @return IProvider[] + * @throws Exception + */ + public function getProviders() { + // TODO: include apps + $providerClasses = $this->getServerProviderClasses(); + $providers = []; + + foreach ($providerClasses as $class) { + try { + $providers[] = $this->serverContainer->query($class); + } catch (QueryException $ex) { + $this->logger->logException($ex, [ + 'message' => "Could not load contacts menu action provider $class", + 'app' => 'core', + ]); + throw new \Exception("Could not load contacts menu action provider"); + } + } + + return $providers; + } + + /** + * @return string[] + */ + private function getServerProviderClasses() { + return [ + EMailProvider::class, + ]; + } + +} diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php new file mode 100644 index 00000000000..5b8b0524a21 --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php @@ -0,0 +1,103 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +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; + + /** + * @param string $icon absolute URI to an icon + */ + public function setIcon($icon) { + $this->icon = $icon; + } + + /** + * @param string $name + */ + public function setName($name) { + $this->name = $name; + } + + /** + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * @param int $priority + */ + public function setPriority($priority) { + $this->priority = $priority; + } + + /** + * @return int + */ + public function getPriority() { + return $this->priority; + } + + /** + * @param string $href + */ + public function setHref($href) { + $this->href = $href; + } + + /** + * @return string + */ + public function getHref() { + return $this->href; + } + + /** + * @return array + */ + public function jsonSerialize() { + return [ + 'title' => $this->name, + 'icon' => $this->icon, + 'hyperlink' => $this->href, + ]; + } + +} diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php new file mode 100644 index 00000000000..fba970e93fa --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -0,0 +1,89 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu; + +use OCP\Contacts\ContactsMenu\IEntry; +use OCP\Contacts\IManager; + +class ContactsStore { + + /** @var IManager */ + private $contactsManager; + + /** + * @param IManager $contactsManager + */ + public function __construct(IManager $contactsManager) { + $this->contactsManager = $contactsManager; + } + + /** + * @param string|null $filter + * @return IEntry[] + */ + public function getContacts($filter) { + $allContacts = $this->contactsManager->search($filter ?: '', [ + 'FN', + ]); + + return array_map(function(array $contact) { + return $this->contactArrayToEntry($contact); + }, $allContacts); + } + + /** + * @param array $contact + * @return Entry + */ + private function contactArrayToEntry(array $contact) { + $entry = new Entry(); + + if (isset($contact['id'])) { + $entry->setId($contact['id']); + } + + if (isset($contact['FN'])) { + $entry->setFullName($contact['FN']); + } + + $avatarPrefix = "VALUE=uri:"; + if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { + $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); + } + + if (isset($contact['EMAIL'])) { + foreach ($contact['EMAIL'] as $email) { + $entry->addEMailAddress($email); + } + } + + // Attach all other properties to the entry too because some + // providers might make use of it. + $entry->setProperties($contact); + + return $entry; + } + +} diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php new file mode 100644 index 00000000000..9ea0511b9cc --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/Entry.php @@ -0,0 +1,169 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu; + +use OCP\Contacts\ContactsMenu\IAction; +use OCP\Contacts\ContactsMenu\IEntry; + +class Entry implements IEntry { + + /** @var string|int|null */ + private $id = null; + + /** @var string */ + private $fullName = ''; + + /** @var string[] */ + private $emailAddresses = []; + + /** @var string|null */ + private $avatar; + + /** @var IAction[] */ + private $actions = []; + + /** @var array */ + private $properties = []; + + /** + * @param string $id + */ + public function setId($id) { + $this->id = $id; + } + + /** + * @param string $displayName + */ + public function setFullName($displayName) { + $this->fullName = $displayName; + } + + /** + * @return string + */ + public function getFullName() { + return $this->fullName; + } + + /** + * @param string $address + */ + public function addEMailAddress($address) { + $this->emailAddresses[] = $address; + } + + /** + * @return string + */ + public function getEMailAddresses() { + return $this->emailAddresses; + } + + /** + * @param string $avatar + */ + public function setAvatar($avatar) { + $this->avatar = $avatar; + } + + /** + * @return string + */ + public function getAvatar() { + return $this->avatar; + } + + /** + * @param IAction $action + */ + public function addAction(IAction $action) { + $this->actions[] = $action; + $this->sortActions(); + } + + /** + * @return IAction[] + */ + public function getActions() { + return $this->actions; + } + + /** + * sort the actions by priority and name + */ + private function sortActions() { + usort($this->actions, function(IAction $action1, IAction $action2) { + $prio1 = $action1->getPriority(); + $prio2 = $action2->getPriority(); + + if ($prio1 === $prio2) { + // Ascending order for same priority + return strcasecmp($action1->getName(), $action2->getName()); + } + + // Descending order when priority differs + return $prio2 - $prio1; + }); + } + + /** + * @param array $contact key-value array containing additional properties + */ + public function setProperties(array $contact) { + $this->properties = $contact; + } + + /** + * @param string $key + * @return mixed + */ + public function getProperty($key) { + if (!isset($this->properties[$key])) { + return null; + } + return $this->properties[$key]; + } + + /** + * @return array + */ + public function jsonSerialize() { + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; + $otherActions = array_map(function(IAction $action) { + return $action->jsonSerialize(); + }, array_slice($this->actions, 1)); + + return [ + 'id' => $this->id, + 'fullName' => $this->fullName, + 'avatar' => $this->getAvatar(), + 'topAction' => $topAction, + 'actions' => $otherActions, + 'lastMessage' => '', + ]; + } + +} diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php new file mode 100644 index 00000000000..c759c4469da --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/Manager.php @@ -0,0 +1,98 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu; + +use OCP\App\IAppManager; +use OCP\Contacts\ContactsMenu\IEntry; +use OCP\IURLGenerator; + +class Manager { + + /** @var ContactsStore */ + private $store; + + /** @var ActionProviderStore */ + private $actionProviderStore; + + /** @var IAppManager */ + private $appManager; + + /** @var IURLGenerator */ + private $urlGenerator; + + /** + * @param ContactsStore $store + * @param ActionProviderStore $actionProviderStore + * @param IAppManager $appManager + */ + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager) { + $this->store = $store; + $this->actionProviderStore = $actionProviderStore; + $this->appManager = $appManager; + } + + /** + * @param string $userId + * @param string $filter + * @return array + */ + public function getEntries($userId, $filter) { + $entries = $this->store->getContacts($filter); + + $sortedEntries = $this->sortEntries($entries); + $topEntries = array_slice($sortedEntries, 0, 25); + $this->processEntries($topEntries); + + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $userId); + return [ + 'contacts' => $topEntries, + 'contactsAppEnabled' => $contactsEnabled, + ]; + } + + /** + * @param IEntry[] $entries + * @return IEntry[] + */ + private function sortEntries(array $entries) { + usort($entries, function(IEntry $entryA, IEntry $entryB) { + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); + }); + return $entries; + } + + /** + * @param IEntry[] $entries + */ + private function processEntries(array $entries) { + $providers = $this->actionProviderStore->getProviders(); + foreach ($entries as $entry) { + foreach ($providers as $provider) { + $provider->process($entry); + } + } + } + +} diff --git a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php new file mode 100644 index 00000000000..c74bdc0b8ff --- /dev/null +++ b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php @@ -0,0 +1,56 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Contacts\ContactsMenu\Providers; + +use OCP\Contacts\ContactsMenu\IActionFactory; +use OCP\Contacts\ContactsMenu\IEntry; +use OCP\Contacts\ContactsMenu\IProvider; + +class EMailProvider implements IProvider { + + /** @var IActionFactory */ + private $actionFactory; + + /** + * @param IActionFactory $actionFactory + */ + public function __construct(IActionFactory $actionFactory) { + $this->actionFactory = $actionFactory; + } + + /** + * @param IEntry $entry + */ + public function process(IEntry $entry) { + foreach ($entry->getEMailAddresses() as $address) { + // TODO: absolute path + // TODO: meaningful URL + // TODO: l10n + $action = $this->actionFactory->newEMailAction('icon-mail', 'Mail', $address); + $entry->addAction($action); + } + } + +} diff --git a/lib/private/Server.php b/lib/private/Server.php index f40a59ad334..7724feb551b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -50,6 +50,7 @@ use OC\AppFramework\Utility\SimpleContainer; use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\LoginCredentials\Store; use OC\Command\AsyncBus; +use OC\Contacts\ContactsMenu\ActionFactory; use OC\Diagnostics\EventLogger; use OC\Diagnostics\NullEventLogger; use OC\Diagnostics\NullQueryLogger; @@ -108,6 +109,8 @@ use OCP\IDBConnection; use OCP\IL10N; use OCP\IServerContainer; use OCP\ITempManager; +use OCP\Contacts\ContactsMenu\IActionFactory; +use OCP\IURLGenerator; use OCP\RichObjectStrings\IValidator; use OCP\Security\IContentSecurityPolicyManager; use OCP\Share\IShareHelper; @@ -133,9 +136,17 @@ class Server extends ServerContainer implements IServerContainer { parent::__construct(); $this->webRoot = $webRoot; + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { + return $c; + }); + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); + $this->registerAlias(IActionFactory::class, ActionFactory::class); + + + $this->registerService(\OCP\IPreview::class, function (Server $c) { return new PreviewManager( $c->getConfig(), diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php index 19b5e418110..9a919ff12f2 100644 --- a/lib/private/legacy/template.php +++ b/lib/private/legacy/template.php @@ -118,6 +118,7 @@ class OC_Template extends \OC\Template\Base { OC_Util::addScript('jquery-ui-fixes'); OC_Util::addScript('files/fileinfo'); OC_Util::addScript('files/client'); + OC_Util::addScript('contactsmenu'); if (\OC::$server->getConfig()->getSystemValue('debug')) { // Add the stuff we need always diff --git a/lib/public/Contacts/ContactsMenu/IAction.php b/lib/public/Contacts/ContactsMenu/IAction.php new file mode 100644 index 00000000000..44ad1af5ae8 --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IAction.php @@ -0,0 +1,65 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Contacts\ContactsMenu; + +use JsonSerializable; + +/** + * Apps should use the IActionFactory to create new action objects + * + * @since 12.0 + */ +interface IAction extends JsonSerializable { + + /** + * @param string $icon absolute URI to an icon + * @since 12.0 + */ + public function setIcon($icon); + + /** + * @return string localized action name, e.g. 'Call' + * @since 12.0 + */ + public function getName(); + + /** + * @param string $name localized action name, e.g. 'Call' + * @since 12.0 + */ + public function setName($name); + + /** + * @param int $priority priorize actions, high order ones are shown on top + * @since 12.0 + */ + public function setPriority($priority); + + /** + * @return int priority to priorize actions, high order ones are shown on top + * @since 12.0 + */ + public function getPriority(); +} diff --git a/lib/public/Contacts/ContactsMenu/IActionFactory.php b/lib/public/Contacts/ContactsMenu/IActionFactory.php new file mode 100644 index 00000000000..8778a729a56 --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IActionFactory.php @@ -0,0 +1,54 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Contacts\ContactsMenu; + +/** + * @since 12.0 + */ +interface IActionFactory { + + /** + * Construct and return a new link action for the contacts menu + * + * @since 12.0 + * + * @param string $icon full path to the action's icon + * @param string $name localized name of the action + * @param string $href target URL + * @return ILinkAction + */ + public function newLinkAction($icon, $name, $href); + + /** + * Construct and return a new email action for the contacts menu + * + * @since 12.0 + * + * @param string $icon full path to the action's icon + * @param string $name localized name of the action + * @param string $email target e-mail address + * @return ILinkAction + */ + public function newEMailAction($icon, $name, $email); +} diff --git a/lib/public/Contacts/ContactsMenu/IEntry.php b/lib/public/Contacts/ContactsMenu/IEntry.php new file mode 100644 index 00000000000..eb04147a1bc --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IEntry.php @@ -0,0 +1,66 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Contacts\ContactsMenu; + +use JsonSerializable; + +/** + * @since 12.0 + */ +interface IEntry extends JsonSerializable { + + /** + * @since 12.0 + * @return string + */ + public function getFullName(); + + /** + * @since 12.0 + * @return string[] + */ + public function getEMailAddresses(); + + /** + * @since 12.0 + * @return string|null image URI + */ + public function getAvatar(); + + /** + * @since 12.0 + * @param IAction $action an action to show in the contacts menu + */ + public function addAction(IAction $action); + + /** + * Get an arbitrary property from the contact + * + * @since 12.0 + * @param string $key + * @return mixed the value of the property or null + */ + public function getProperty($key); +} diff --git a/lib/public/Contacts/ContactsMenu/ILinkAction.php b/lib/public/Contacts/ContactsMenu/ILinkAction.php new file mode 100644 index 00000000000..4e29f757c26 --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/ILinkAction.php @@ -0,0 +1,43 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Contacts\ContactsMenu; + +/** + * @since 12.0 + */ +interface ILinkAction extends IAction { + + /** + * @since 12.0 + * @param string $href the target URL of the action + */ + public function setHref($href); + + /** + * @since 12.0 + * @return string + */ + public function getHref(); +} diff --git a/lib/public/Contacts/ContactsMenu/IProvider.php b/lib/public/Contacts/ContactsMenu/IProvider.php new file mode 100644 index 00000000000..17fcc003720 --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IProvider.php @@ -0,0 +1,37 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Contacts\ContactsMenu; + +/** + * @since 12.0 + */ +interface IProvider { + + /** + * @since 12.0 + * @param IEntry $entry + */ + public function process(IEntry $entry); +} |