Unverified Commit 6c8d3ce4 authored by Thomas Müller's avatar Thomas Müller
Browse files

Use firstLogin event to trigger creation of default calendar and default address book

parent baaaec77
......@@ -29,6 +29,7 @@ use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\HookManager;
use \OCP\AppFramework\App;
use OCP\Contacts\IManager;
use OCP\IUser;
use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App {
......@@ -58,6 +59,16 @@ class Application extends App {
$hm = $this->getContainer()->query(HookManager::class);
$hm->setup();
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
// first time login event setup
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
if ($event instanceof GenericEvent) {
$hm->firstLogin($event->getSubject());
}
});
// carddav/caldav sync event setup
$listener = function($event) {
if ($event instanceof GenericEvent) {
/** @var BirthdayService $b */
......@@ -70,7 +81,6 @@ class Application extends App {
}
};
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
......
......@@ -84,10 +84,6 @@ class HookManager {
'changeUser',
$this,
'changeUser');
Util::connectHook('OC_User',
'post_login',
$this,
'postLogin');
}
public function postCreateUser($params) {
......@@ -123,8 +119,7 @@ class HookManager {
$this->syncService->updateUser($user);
}
public function postLogin($params) {
$user = $this->userManager->get($params['uid']);
public function firstLogin(IUser $user = null) {
if (!is_null($user)) {
$principal = 'principals/users/' . $user->getUID();
$calendars = $this->calDav->getCalendarsForUser($principal);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment