diff --git a/apps/dav/lib/CalDAV/CalendarProvider.php b/apps/dav/lib/CalDAV/CalendarProvider.php index 30eb6ae426800..857a1354bb43c 100644 --- a/apps/dav/lib/CalDAV/CalendarProvider.php +++ b/apps/dav/lib/CalDAV/CalendarProvider.php @@ -25,6 +25,7 @@ */ namespace OCA\DAV\CalDAV; +use OCA\dav\lib\CalDAV\SchedulingInbox; use OCP\Calendar\ICalendarProvider; use OCP\IConfig; use OCP\IL10N; @@ -69,4 +70,10 @@ public function getCalendars(string $principalUri, array $calendarUris = []): ar } return $iCalendars; } + + public function getSchedulingInboxes(string $principalUri): array { + return [ + new SchedulingInbox($principalUri) + ]; + } } diff --git a/apps/dav/lib/CalDAV/SchedulingInbox.php b/apps/dav/lib/CalDAV/SchedulingInbox.php new file mode 100644 index 0000000000000..47d21efb56157 --- /dev/null +++ b/apps/dav/lib/CalDAV/SchedulingInbox.php @@ -0,0 +1,42 @@ + + * + * @author 2021 Christoph Wurst + * + * @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 . + */ + +namespace OCA\dav\lib\CalDAV; + +use OCP\Calendar\ISchedulingInbox; + +class SchedulingInbox implements ISchedulingInbox { + + /** @var string */ + private $principalUri; + + public function __construct(string $principalUri) { + $this->principalUri = $principalUri; + } + + public function getAvailability(): ?string { + return null; + } +} diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index 30ee60e49430f..5387f03c9aa6a 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -31,6 +31,11 @@ use OCP\Calendar\ICalendarProvider; use OCP\Calendar\ICalendarQuery; use OCP\Calendar\IManager; +use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; +use Throwable; +use function array_map; +use function array_merge; class Manager implements IManager { @@ -47,8 +52,18 @@ class Manager implements IManager { /** @var Coordinator */ private $coordinator; - public function __construct(Coordinator $coordinator) { + /** @var ContainerInterface */ + private $container; + + /** @var LoggerInterface */ + private $logger; + + public function __construct(Coordinator $coordinator, + ContainerInterface $container, + LoggerInterface $logger) { $this->coordinator = $coordinator; + $this->container = $container; + $this->logger = $logger; } /** @@ -159,9 +174,20 @@ public function searchForPrincipal(ICalendarQuery $query): array { } /** @var CalendarQuery $query */ - $calendars = array_merge(...array_map(static function (ICalendarProvider $p) use ($query) { - return $p->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); - }, $context->getCalendarProviders())); + $calendars = array_merge( + ...array_map(function ($registration) use ($query) { + try { + /** @var ICalendarProvider $provider */ + $provider = $this->container->get($registration->getService()); + } catch (Throwable $e) { + $this->logger->error('Could not load calendar provider ' . $registration->getService() . ': ' . $e->getMessage(), [ + 'exception' => $e, + ]); + } + + return $provider->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); + }, $context->getCalendarProviders()) + ); $results = []; /** @var ICalendar $calendar */ @@ -185,4 +211,26 @@ public function searchForPrincipal(ICalendarQuery $query): array { public function newQuery(string $principalUri): ICalendarQuery { return new CalendarQuery($principalUri); } + + public function getSchedulingInboxes(string $principalUri): array { + $context = $this->coordinator->getRegistrationContext(); + if ($context === null) { + return []; + } + + return array_merge( + ...array_map(function($registration) use ($principalUri) { + try { + /** @var ICalendarProvider $provider */ + $provider = $this->container->get($registration->getService()); + } catch (Throwable $e) { + $this->logger->error('Could not load calendar provider ' . $registration->getService() . ': ' . $e->getMessage(), [ + 'exception' => $e, + ]); + } + + return $provider->getSchedulingInboxes($principalUri); + }, $context->getCalendarProviders()) + ); + } } diff --git a/lib/public/Calendar/ICalendarProvider.php b/lib/public/Calendar/ICalendarProvider.php index d135910b08c87..a1fec8e6872d8 100644 --- a/lib/public/Calendar/ICalendarProvider.php +++ b/lib/public/Calendar/ICalendarProvider.php @@ -42,4 +42,15 @@ interface ICalendarProvider { * @since 23.0.0 */ public function getCalendars(string $principalUri, array $calendarUris = []): array; + + /** + * Get the principal's scheduling inboxes + * + * @param string $principalUri + * + * @return ISchedulingInbox[]] + * + * @since 23.0.0 + */ + public function getSchedulingInboxes(string $principalUri): array; } diff --git a/lib/public/Calendar/IManager.php b/lib/public/Calendar/IManager.php index eb4113bba9966..16c01fffc5b25 100644 --- a/lib/public/Calendar/IManager.php +++ b/lib/public/Calendar/IManager.php @@ -147,4 +147,15 @@ public function searchForPrincipal(ICalendarQuery $query): array; * @since 23.0.0 */ public function newQuery(string $principalUri) : ICalendarQuery; + + /** + * Get the principal's scheduling inboxes + * + * @param string $principalUri + * + * @return ISchedulingInbox[]] + * + * @since 23.0.0 + */ + public function getSchedulingInboxes(string $principalUri): array; } diff --git a/lib/public/Calendar/ISchedulingInbox.php b/lib/public/Calendar/ISchedulingInbox.php new file mode 100644 index 0000000000000..e54f33ca86bb9 --- /dev/null +++ b/lib/public/Calendar/ISchedulingInbox.php @@ -0,0 +1,35 @@ + + * + * @author 2021 Christoph Wurst + * + * @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 . + */ + +namespace OCP\Calendar; + +/** + * @since 23.0.0 + */ +interface ISchedulingInbox { + + public function getAvailability(): ?string; + +}