Skip to content

Commit

Permalink
Merge pull request #6637 from nextcloud/contactsstore_public_api
Browse files Browse the repository at this point in the history
Make ContactsStore a public API
  • Loading branch information
rullzer authored Dec 11, 2017
2 parents bd80795 + cecfc28 commit 179be8d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/dav/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function(GenericEvent $event) use ($app) {
$user = \OC::$server->getUserSession()->getUser();
if (!is_null($user)) {
$app->setupContactsProvider($cm, $user->getUID());
} else {
$app->setupSystemContactsProvider($cm);
}
});

Expand Down
10 changes: 10 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public function setupContactsProvider(IContactsManager $contactsManager, $userID
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
}

/**
* @param IManager $contactsManager
*/
public function setupSystemContactsProvider(IContactsManager $contactsManager) {
/** @var ContactsManager $cm */
$cm = $this->getContainer()->query(ContactsManager::class);
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
}

/**
* @param ICalendarManager $calendarManager
* @param string $userId
Expand Down
8 changes: 8 additions & 0 deletions apps/dav/lib/CardDAV/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public function __construct(CardDavBackend $backend, IL10N $l10n) {
public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) {
$addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
$this->register($cm, $addressBooks, $urlGenerator);
$this->setupSystemContactsProvider($cm, $urlGenerator);
}

/**
* @param IManager $cm
* @param IURLGenerator $urlGenerator
*/
public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) {
$addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
$this->register($cm, $addressBooks, $urlGenerator);
}
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
'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\\IContactsStore' => $baseDir . '/lib/public/Contacts/ContactsMenu/IContactsStore.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',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'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\\IContactsStore' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IContactsStore.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',
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Contacts\ContactsMenu\IContactsStore;

class ContactsStore {
class ContactsStore implements IContactsStore {

/** @var IManager */
private $contactsManager;
Expand Down
12 changes: 12 additions & 0 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use OC\Collaboration\Collaborators\UserPlugin;
use OC\Command\CronBus;
use OC\Contacts\ContactsMenu\ActionFactory;
use OC\Contacts\ContactsMenu\ContactsStore;
use OC\Diagnostics\EventLogger;
use OC\Diagnostics\QueryLogger;
use OC\Federation\CloudIdManager;
Expand Down Expand Up @@ -114,6 +115,7 @@
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\AutoComplete\IManager;
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Defaults;
use OCA\Theming\Util;
use OCP\Federation\ICloudIdManager;
Expand Down Expand Up @@ -1129,6 +1131,16 @@ public function __construct($webRoot, \OC\Config $config) {
return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
});

$this->registerService(IContactsStore::class, function(Server $c) {
return new ContactsStore(
$c->getContactsManager(),
$c->getConfig(),
$c->getUserManager(),
$c->getGroupManager()
);
});
$this->registerAlias(IContactsStore::class, ContactsStore::class);

$this->connectDispatcher();
}

Expand Down
31 changes: 31 additions & 0 deletions lib/public/Contacts/ContactsMenu/IContactsStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace OCP\Contacts\ContactsMenu;

use OCP\IUser;

/**
* @since 13.0.0
*/
interface IContactsStore {


/**
* @param IUser $user
* @param $filter
* @return IEntry[]
* @since 13.0.0
*/
public function getContacts(IUser $user, $filter);

/**
* @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);

}

0 comments on commit 179be8d

Please sign in to comment.