Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e5269c1 authored by AVINASH GUSAIN's avatar AVINASH GUSAIN
Browse files

create task on first login

parent 41ab43e5
Loading
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -8,9 +8,19 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCA\EcloudThemeHelper\Listeners\BeforeTemplateRenderedListener;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\Defaults;
use OCP\IUser;
use OCP\Util;
use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;


class Application extends App implements IBootstrap {
	public const APP_ID = 'ecloud-theme-helper';
	public const TASKS_CALENDAR_URI = 'tasks';
	public const TASKS_CALENDAR_NAME = 'Tasks';

	public function __construct(array $urlParams = []) {
		parent::__construct(self::APP_ID, $urlParams);
@@ -21,5 +31,27 @@ class Application extends App implements IBootstrap {
	}

	public function boot(IBootContext $context): void {
		$context->injectFn([$this, 'createTasksCalendar']);
	}
	public function createTasksCalendar(CalDavBackend $calDav, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void {
		$dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults) {
			$user = $event->getSubject();
			if (!$user instanceof IUser) {
				return;
			}
			$userId = $user->getUID();
			$principal = 'principals/users/' . $userId;
			if ($calDav->getCalendarsForUserCount($principal) === 0) {

					$calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [
						'{DAV:}displayname' => self::TASKS_CALENDAR_NAME,
						'{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(),
						'components' => 'VEVENT'
					]);

			}

		});
	}

}