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 <tobia@ledfan.be>
  • Loading branch information
LEDfan committed Dec 9, 2017
1 parent 855acc7 commit a7bc93d
Show file tree
Hide file tree
Showing 6 changed files with 58 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
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
10 changes: 10 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 @@ -1109,6 +1110,15 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getConfig()
);
});

$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 a7bc93d

Please sign in to comment.