Register an address book with recent contacts
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
8ad91baf8d
commit
3dc9aaf5b8
8 changed files with 330 additions and 0 deletions
|
@ -38,10 +38,15 @@ use OC\Authentication\Listeners\RemoteWipeEmailListener;
|
|||
use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
|
||||
use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
|
||||
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
|
||||
use OC\Contacts\Interaction\AddressBook;
|
||||
use OC\Contacts\Interaction\Listeners\ContactInteractionListener;
|
||||
use OC\Contacts\Interaction\Service\Store;
|
||||
use OC\Core\Notification\RemoveLinkSharesNotifier;
|
||||
use OC\DB\MissingIndexInformation;
|
||||
use OC\DB\SchemaWrapper;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\Contacts\Events\ContactInteractedWithEvent;
|
||||
use OCP\Contacts\IManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IServerContainer;
|
||||
|
@ -168,6 +173,7 @@ class Application extends App {
|
|||
}
|
||||
);
|
||||
|
||||
$eventDispatcher->addServiceListener(ContactInteractedWithEvent::class, ContactInteractionListener::class);
|
||||
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
|
||||
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
|
||||
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
|
||||
|
@ -175,6 +181,13 @@ class Application extends App {
|
|||
$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
|
||||
$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
|
||||
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
|
||||
|
||||
/** @var IManager $contactsManager */
|
||||
$contactsManager = $container->query(IManager::class);
|
||||
$contactsManager->registerAddressBook(new AddressBook(
|
||||
$container->query(Store::class),
|
||||
$container->getServer()->getL10N('lib')
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -697,6 +697,11 @@ return array(
|
|||
'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\\EMailProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php',
|
||||
'OC\\Contacts\\Interaction\\AddressBook' => $baseDir . '/lib/private/Contacts/Interaction/AddressBook.php',
|
||||
'OC\\Contacts\\Interaction\\Db\\RecentContact' => $baseDir . '/lib/private/Contacts/Interaction/Db/RecentContact.php',
|
||||
'OC\\Contacts\\Interaction\\Db\\RecentContactMapper' => $baseDir . '/lib/private/Contacts/Interaction/Db/RecentContactMapper.php',
|
||||
'OC\\Contacts\\Interaction\\Listeners\\ContactInteractionListener' => $baseDir . '/lib/private/Contacts/Interaction/Listeners/ContactInteractionListener.php',
|
||||
'OC\\Contacts\\Interaction\\Service\\Store' => $baseDir . '/lib/private/Contacts/Interaction/Service/Store.php',
|
||||
'OC\\Core\\Application' => $baseDir . '/core/Application.php',
|
||||
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
|
||||
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => $baseDir . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
|
||||
|
|
|
@ -726,6 +726,11 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'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\\EMailProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php',
|
||||
'OC\\Contacts\\Interaction\\AddressBook' => __DIR__ . '/../../..' . '/lib/private/Contacts/Interaction/AddressBook.php',
|
||||
'OC\\Contacts\\Interaction\\Db\\RecentContact' => __DIR__ . '/../../..' . '/lib/private/Contacts/Interaction/Db/RecentContact.php',
|
||||
'OC\\Contacts\\Interaction\\Db\\RecentContactMapper' => __DIR__ . '/../../..' . '/lib/private/Contacts/Interaction/Db/RecentContactMapper.php',
|
||||
'OC\\Contacts\\Interaction\\Listeners\\ContactInteractionListener' => __DIR__ . '/../../..' . '/lib/private/Contacts/Interaction/Listeners/ContactInteractionListener.php',
|
||||
'OC\\Contacts\\Interaction\\Service\\Store' => __DIR__ . '/../../..' . '/lib/private/Contacts/Interaction/Service/Store.php',
|
||||
'OC\\Core\\Application' => __DIR__ . '/../../..' . '/core/Application.php',
|
||||
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
|
||||
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
|
||||
|
|
82
lib/private/Contacts/Interaction/AddressBook.php
Normal file
82
lib/private/Contacts/Interaction/AddressBook.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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 OC\Contacts\Interaction;
|
||||
|
||||
use Exception;
|
||||
use OC\Contacts\Interaction\Service\Store;
|
||||
use OCP\Constants;
|
||||
use OCP\IAddressBook;
|
||||
use OCP\IL10N;
|
||||
|
||||
class AddressBook implements IAddressBook {
|
||||
|
||||
/** @var Store */
|
||||
private $store;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
public function __construct(Store $store,
|
||||
IL10N $l10n) {
|
||||
$this->store = $store;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
public function getKey() {
|
||||
return 'recent';
|
||||
}
|
||||
|
||||
public function getUri(): string {
|
||||
return 'recent';
|
||||
}
|
||||
|
||||
public function getDisplayName(): string {
|
||||
return $this->l10n->t('Recent contacts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pattern
|
||||
* @param array $searchProperties
|
||||
* @param array $options
|
||||
*/
|
||||
public function search($pattern, $searchProperties, $options): array {
|
||||
// TODO: Implement search() method.
|
||||
return $this->store->search($pattern, $searchProperties);
|
||||
}
|
||||
|
||||
public function createOrUpdate($properties): void {
|
||||
throw new Exception("This addressbook is immutable");
|
||||
}
|
||||
|
||||
public function getPermissions(): int {
|
||||
return Constants::PERMISSION_READ;
|
||||
}
|
||||
|
||||
public function delete($id): void {
|
||||
throw new Exception("This addressbook is immutable");
|
||||
}
|
||||
|
||||
}
|
70
lib/private/Contacts/Interaction/Db/RecentContact.php
Normal file
70
lib/private/Contacts/Interaction/Db/RecentContact.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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 OC\Contacts\Interaction\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\Contacts\Events\ContactInteractedWithEvent;
|
||||
|
||||
/**
|
||||
* @method void setUid(string $uid)
|
||||
* @method string|null getUid()
|
||||
* @method void setEmail(string $email)
|
||||
* @method string|null getEmail()
|
||||
* @method void setFederatedCloudId(string $federatedCloudId)
|
||||
* @method string getFederatedCloudId()
|
||||
*/
|
||||
class RecentContact extends Entity {
|
||||
|
||||
protected $uid;
|
||||
|
||||
protected $email;
|
||||
|
||||
protected $federatedCloudId;
|
||||
|
||||
protected $createdAt;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('uid', 'string');
|
||||
$this->addType('email', 'string');
|
||||
$this->addType('federatedCloudId', 'string');
|
||||
$this->addType('createdAt', 'int');
|
||||
}
|
||||
|
||||
public static function fromEvent(ContactInteractedWithEvent $event): self {
|
||||
$contact = new self();
|
||||
if ($event->getUid() !== null) {
|
||||
$contact->setUid($event->getUid());
|
||||
}
|
||||
if ($event->getEmail() !== null) {
|
||||
$contact->setEmail($event->getEmail());
|
||||
}
|
||||
if ($event->getFederatedCloudId() !== null) {
|
||||
$contact->setFederatedCloudId($event->getFederatedCloudId());
|
||||
}
|
||||
return $contact;
|
||||
}
|
||||
|
||||
}
|
37
lib/private/Contacts/Interaction/Db/RecentContactMapper.php
Normal file
37
lib/private/Contacts/Interaction/Db/RecentContactMapper.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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 OC\Contacts\Interaction\Db;
|
||||
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class RecentContactMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'recent_contact');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @author 2019 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\Interaction\Listeners;
|
||||
|
||||
use OC\Contacts\Interaction\Db\RecentContact;
|
||||
use OC\Contacts\Interaction\Service\Store;
|
||||
use OCP\Contacts\Events\ContactInteractedWithEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\ILogger;
|
||||
|
||||
class ContactInteractionListener implements IEventListener {
|
||||
|
||||
/** @var Store */
|
||||
private $store;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(Store $store,
|
||||
ILogger $logger) {
|
||||
$this->store = $store;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!($event instanceof ContactInteractedWithEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) {
|
||||
$this->logger->warning("Contact interaction event has no user identifier set");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->store->import(RecentContact::fromEvent($event));
|
||||
}
|
||||
|
||||
}
|
56
lib/private/Contacts/Interaction/Service/Store.php
Normal file
56
lib/private/Contacts/Interaction/Service/Store.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?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 OC\Contacts\Interaction\Service;
|
||||
|
||||
use OC\Contacts\Interaction\Db\RecentContact;
|
||||
use OC\Contacts\Interaction\Db\RecentContactMapper;
|
||||
use OCP\ILogger;
|
||||
|
||||
class Store {
|
||||
|
||||
/** @var RecentContactMapper */
|
||||
private $mapper;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
public function __construct(RecentContactMapper $mapper,
|
||||
ILogger $logger) {
|
||||
$this->mapper = $mapper;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function import(RecentContact $contact): void {
|
||||
$this->mapper->insert($contact);
|
||||
}
|
||||
|
||||
public function search(string $pattern, array $properties): array {
|
||||
return [
|
||||
['id' => 13, 'FN' => '', 'EMAIL' => 'a@b.c'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue