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; ...@@ -29,6 +29,7 @@ use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\HookManager; use OCA\DAV\HookManager;
use \OCP\AppFramework\App; use \OCP\AppFramework\App;
use OCP\Contacts\IManager; use OCP\Contacts\IManager;
use OCP\IUser;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App { class Application extends App {
...@@ -58,6 +59,16 @@ class Application extends App { ...@@ -58,6 +59,16 @@ class Application extends App {
$hm = $this->getContainer()->query(HookManager::class); $hm = $this->getContainer()->query(HookManager::class);
$hm->setup(); $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) { $listener = function($event) {
if ($event instanceof GenericEvent) { if ($event instanceof GenericEvent) {
/** @var BirthdayService $b */ /** @var BirthdayService $b */
...@@ -70,7 +81,6 @@ class Application extends App { ...@@ -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::createCard', $listener);
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
......
...@@ -84,10 +84,6 @@ class HookManager { ...@@ -84,10 +84,6 @@ class HookManager {
'changeUser', 'changeUser',
$this, $this,
'changeUser'); 'changeUser');
Util::connectHook('OC_User',
'post_login',
$this,
'postLogin');
} }
public function postCreateUser($params) { public function postCreateUser($params) {
...@@ -123,8 +119,7 @@ class HookManager { ...@@ -123,8 +119,7 @@ class HookManager {
$this->syncService->updateUser($user); $this->syncService->updateUser($user);
} }
public function postLogin($params) { public function firstLogin(IUser $user = null) {
$user = $this->userManager->get($params['uid']);
if (!is_null($user)) { if (!is_null($user)) {
$principal = 'principals/users/' . $user->getUID(); $principal = 'principals/users/' . $user->getUID();
$calendars = $this->calDav->getCalendarsForUser($principal); $calendars = $this->calDav->getCalendarsForUser($principal);
......
Supports Markdown
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