diff options
author | Joas Schilling <coding@schilljs.com> | 2022-10-13 23:23:09 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-10-13 23:32:27 +0300 |
commit | 1a04bc57051126eaeb12f5523cd65c694da4a5da (patch) | |
tree | 397a429801c4921289eca9ff8ed06123754d65d9 | |
parent | adf13b1e4f75a129bdcc5ee985b0ce58ef16a247 (diff) |
🌏 Make events clickable if calendar is installed
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | lib/EventListener.php | 5 | ||||
-rw-r--r-- | lib/Notifier.php | 28 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 3 |
4 files changed, 39 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a59caad..df9e960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ All notable changes to this project will be documented in this file. ## 2.0.0 – 2022-10-13 +### Added +- 🌏 Make events clickable if calendar is installed + ### Changed -- Add support for Nextcloud 25 -- Drop support for Nextcloud 22 +- ✨ Add support for Nextcloud 25 +- 🏚️ Drop support for Nextcloud 22 ## 1.5.0 – 2022-04-08 ### Changed diff --git a/lib/EventListener.php b/lib/EventListener.php index bd1f354..c22defa 100644 --- a/lib/EventListener.php +++ b/lib/EventListener.php @@ -163,6 +163,11 @@ class EventListener implements IEventListener { 'id' => $object['id'], 'name' => $isClassified ? 'Busy' : $object['name'], 'classified' => $isClassified, + 'link' => [ + 'owner' => $owner, + 'calendar_uri' => $calendarData['uri'], + 'object_uri' => $objectData['uri'], + ], ], ] ); diff --git a/lib/Notifier.php b/lib/Notifier.php index 0cea996..01d87fb 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\EventUpdateNotification; use OCA\DAV\CalDAV\CalDavBackend; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDateTimeFormatter; use OCP\IL10N; @@ -55,6 +56,8 @@ class Notifier implements INotifier { protected $userManager; /** @var INotificationManager */ protected $notificationManager; + /** @var IAppManager */ + protected $appManager; /** @var IDateTimeFormatter */ protected $dateTimeFormatter; @@ -66,12 +69,14 @@ class Notifier implements INotifier { IURLGenerator $url, IUserManager $userManager, INotificationManager $notificationManager, + IAppManager $appManager, IDateTimeFormatter $dateTimeFormatter) { $this->languageFactory = $languageFactory; $this->timeFactory = $timeFactory; $this->url = $url; $this->userManager = $userManager; $this->notificationManager = $notificationManager; + $this->appManager = $appManager; $this->dateTimeFormatter = $dateTimeFormatter; } @@ -191,11 +196,32 @@ class Notifier implements INotifier { $eventData['name'] = $this->l->t('Busy'); } - return [ + $params = [ 'type' => 'calendar-event', 'id' => $eventData['id'], 'name' => $eventData['name'], ]; + + if (isset($eventData['link']) && is_array($eventData['link']) && $this->appManager->isEnabledForUser('calendar')) { + try { + // The calendar app needs to be manually loaded for the routes to be loaded + \OC_App::loadApp('calendar'); + $linkData = $eventData['link']; + $objectId = base64_encode('/remote.php/dav/calendars/' . $linkData['owner'] . '/' . $linkData['calendar_uri'] . '/' . $linkData['object_uri']); + $link = [ + 'view' => 'dayGridMonth', + 'timeRange' => 'now', + 'mode' => 'sidebar', + 'objectId' => $objectId, + 'recurrenceId' => 'next' + ]; + $params['link'] = $this->url->linkToRouteAbsolute('calendar.view.indexview.timerange.edit', $link); + } catch (\Exception $error) { + // Do nothing + } + } + + return $params; } protected function generateCalendarParameter(array $data): array { diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 14412a9..5926dfe 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -27,9 +27,10 @@ </UndefinedDocblockClass> </file> <file src="lib/Notifier.php"> - <UndefinedClass occurrences="2"> + <UndefinedClass occurrences="3"> <code>CalDavBackend</code> <code>CalDavBackend</code> + <code>\OC_App</code> </UndefinedClass> </file> </files> |