Skip to content

Commit

Permalink
Make ContactsStore a public API
Browse files Browse the repository at this point in the history
Signed-off-by: Tobia De Koninck <[email protected]>
  • Loading branch information
LEDfan committed Sep 25, 2017
1 parent 199c4b2 commit 5628e76
Show file tree
Hide file tree
Showing 6 changed files with 60 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 @@ -52,5 +52,7 @@ function(GenericEvent $event) use ($app) {
$user = \OC::$server->getUserSession()->getUser();
if (!is_null($user)) {
$app->setupContactsProvider($cm, $user->getUID());
} else {
$app->setupSystemContactsProvider($cm);
}
});
10 changes: 10 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public function setupContactsProvider(IManager $contactsManager, $userID) {
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
}

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

public function registerHooks() {
/** @var HookManager $hm */
$hm = $this->getContainer()->query(HookManager::class);
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 @@ -54,6 +54,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
3 changes: 2 additions & 1 deletion lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,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 @@ -54,6 +54,7 @@
use OC\Authentication\LoginCredentials\Store;
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 @@ -1066,6 +1067,17 @@ public function __construct($webRoot, \OC\Config $config) {
$c->query(\OCP\Share\IManager::class)
);
});

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


}

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

namespace OCP\Contacts\ContactsMenu;

use OCP\IUser;

interface IContactsStore {


/**
* @param IUser $user
* @param $filter
* @return IEntry[]
*/
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
*/
public function findOne(IUser $user, $shareType, $shareWith);

}

0 comments on commit 5628e76

Please sign in to comment.