fixup! Register an address book with recent contacts

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2020-03-04 16:07:04 +01:00
parent ca85654ec7
commit b93634146b
No known key found for this signature in database
GPG key ID: CC42AC2A7F0E56D8
6 changed files with 216 additions and 10 deletions

View file

@ -9,6 +9,7 @@ return array(
'OCA\\ContactsInteraction\\AddressBook' => $baseDir . '/../lib/AddressBook.php',
'OCA\\ContactsInteraction\\AddressBookProvider' => $baseDir . '/../lib/AddressBookProvider.php',
'OCA\\ContactsInteraction\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\ContactsInteraction\\Card' => $baseDir . '/../lib/Card.php',
'OCA\\ContactsInteraction\\Db\\RecentContact' => $baseDir . '/../lib/Db/RecentContact.php',
'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => $baseDir . '/../lib/Db/RecentContactMapper.php',
'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => $baseDir . '/../lib/Listeners/ContactInteractionListener.php',

View file

@ -24,6 +24,7 @@ class ComposerStaticInitContactsInteraction
'OCA\\ContactsInteraction\\AddressBook' => __DIR__ . '/..' . '/../lib/AddressBook.php',
'OCA\\ContactsInteraction\\AddressBookProvider' => __DIR__ . '/..' . '/../lib/AddressBookProvider.php',
'OCA\\ContactsInteraction\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\ContactsInteraction\\Card' => __DIR__ . '/..' . '/../lib/Card.php',
'OCA\\ContactsInteraction\\Db\\RecentContact' => __DIR__ . '/..' . '/../lib/Db/RecentContact.php',
'OCA\\ContactsInteraction\\Db\\RecentContactMapper' => __DIR__ . '/..' . '/../lib/Db/RecentContactMapper.php',
'OCA\\ContactsInteraction\\Listeners\\ContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listeners/ContactInteractionListener.php',

View file

@ -27,13 +27,16 @@ namespace OCA\ContactsInteraction;
use Exception;
use OCA\ContactsInteraction\AppInfo\Application;
use OCA\ContactsInteraction\Db\RecentContact;
use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
use OCA\DAV\DAV\Sharing\IShareable;
use OCP\IL10N;
use Sabre\DAV\Exception\NotImplemented;
use Sabre\DAV\PropPatch;
use Sabre\DAVACL\ACLTrait;
use Sabre\DAVACL\IACL;
class AddressBook extends ExternalAddressBook implements IACL {
class AddressBook extends ExternalAddressBook implements IACL, IShareable {
use ACLTrait;
@ -43,12 +46,17 @@ class AddressBook extends ExternalAddressBook implements IACL {
/** @var IL10N */
private $l10n;
/** @var string */
private $principalUri;
public function __construct(Store $store,
IL10N $l10n) {
IL10N $l10n,
string $principalUri) {
parent::__construct(Application::APP_ID, 'recent');
$this->store = $store;
$this->l10n = $l10n;
$this->principalUri = $principalUri;
}
/**
@ -70,13 +78,23 @@ class AddressBook extends ExternalAddressBook implements IACL {
*/
public function getChild($name) {
// TODO: Implement getChild() method.
throw new NotImplemented();
}
/**
* @inheritDoc
*/
public function getChildren(): array {
return [];
return [
new Card(
RecentContact::fromParams([
'id' => 13,
'email' => 'test@domain.com',
]),
$this->principalUri,
$this->getACL()
)
];
}
/**
@ -84,6 +102,7 @@ class AddressBook extends ExternalAddressBook implements IACL {
*/
public function childExists($name) {
// TODO: Implement childExists() method.
throw new NotImplemented();
}
/**
@ -91,6 +110,7 @@ class AddressBook extends ExternalAddressBook implements IACL {
*/
public function getLastModified() {
// TODO: Implement getLastModified() method.
throw new NotImplemented();
}
/**
@ -104,7 +124,14 @@ class AddressBook extends ExternalAddressBook implements IACL {
* @inheritDoc
*/
public function getProperties($properties) {
return [];
return [
'principaluri' => $this->principalUri,
'{DAV:}displayname' => $this->l10n->t('Recently contacted'),
];
}
public function getOwner(): string {
return $this->principalUri;
}
/**
@ -125,4 +152,25 @@ class AddressBook extends ExternalAddressBook implements IACL {
];
}
/**
* @inheritDoc
*/
function updateShares(array $add, array $remove) {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function getShares() {
return [];
}
/**
* @inheritDoc
*/
public function getResourceId() {
throw new NotImplemented();
}
}

View file

@ -75,7 +75,7 @@ class AddressBookProvider implements IAddressBookProvider {
*/
public function fetchAllForAddressBookHome(string $principalUri): array {
return [
new AddressBook($this->store, $this->l10n)
new AddressBook($this->store, $this->l10n, $principalUri)
];
}

View file

@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
/**
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2020 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 OCA\ContactsInteraction;
use OCA\ContactsInteraction\Db\RecentContact;
use Sabre\CardDAV\ICard;
use Sabre\DAV\Exception\NotImplemented;
use Sabre\DAVACL\ACLTrait;
use Sabre\DAVACL\IACL;
use function md5;
class Card implements ICard, IACL {
use ACLTrait;
/** @var RecentContact */
private $contact;
/** @var string */
private $principal;
/** @var array */
private $acls;
public function __construct(RecentContact $contact, string $principal, array $acls) {
$this->contact = $contact;
$this->principal = $principal;
$this->acls = $acls;
}
/**
* @inheritDoc
*/
function getOwner(): ?string {
$this->principal;
}
/**
* @inheritDoc
*/
function getACL(): array {
return $this->acls;
}
/**
* @inheritDoc
*/
function setAcls(array $acls): void {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function put($data): ?string {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function get() {
return 'BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;Mr.;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212
TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212
ADR;TYPE=WORK;PREF=1;LABEL="100 Waters Edge\nBaytown\, LA 30314\nUnited States of America":;;100 Waters Edge;Baytown;LA;30314;United States of America
ADR;TYPE=HOME;LABEL="42 Plantation St.\nBaytown\, LA 30314\nUnited States of America":;;42 Plantation St.;Baytown;LA;30314;United States of America
EMAIL:forrestgump@example.com
REV:20080424T195243Z
x-qq:21588891
END:VCARD';
}
/**
* @inheritDoc
*/
function getContentType(): ?string {
return 'text/vcard; charset=utf-8';
}
/**
* @inheritDoc
*/
function getETag(): ?string {
return null;
}
/**
* @inheritDoc
*/
function getSize(): int {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function delete(): void {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function getName(): string {
return md5((string) $this->contact->getId());
}
/**
* @inheritDoc
*/
function setName($name): void {
throw new NotImplemented();
}
/**
* @inheritDoc
*/
function getLastModified(): ?int {
throw new NotImplemented();
}
}

View file

@ -28,9 +28,12 @@ declare(strict_types=1);
namespace OCA\DAV\CardDAV;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CardDAV\Integration\IAddressBookProvider;
use OCP\IConfig;
use OCP\IL10N;
use Sabre\CardDAV\Backend;
use Sabre\CardDAV\IAddressBook;
use function array_map;
class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
@ -53,7 +56,7 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
/**
* Returns a list of address books
*
* @return array
* @return IAddressBook[]
*/
function getChildren() {
if ($this->l10n === null) {
@ -64,6 +67,7 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
}
$addressBooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);
/** @var IAddressBook[] $objects */
$objects = array_map(function(array $addressBook) {
if ($addressBook['principaluri'] === 'principals/system/system') {
return new SystemAddressbook($this->carddavBackend, $addressBook, $this->l10n, $this->config);
@ -71,11 +75,12 @@ class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
return new AddressBook($this->carddavBackend, $addressBook, $this->l10n);
}, $addressBooks);
foreach ($this->pluginManager->getAddressBookPlugins() as $plugin) {
$plugin->fetchAllForAddressBookHome($this->principalUri);
}
return $objects;
/** @var IAddressBook[][] $objectsFromPlugins */
$objectsFromPlugins = array_map(function(IAddressBookProvider $plugin): array {
return $plugin->fetchAllForAddressBookHome($this->principalUri);
}, $this->pluginManager->getAddressBookPlugins());
return array_merge($objects, ...$objectsFromPlugins);
}
/**