From c8f982994d07a7118c13b2877d436895f50b12fc Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Wed, 20 Sep 2023 17:54:55 +0200 Subject: [PATCH] fix(dashboard): properly handle recurring events Signed-off-by: Richard Steinmetz --- lib/Dashboard/CalendarWidget.php | 24 +++++++++++++++++++++--- lib/Dashboard/CalendarWidgetV2.php | 6 ++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/Dashboard/CalendarWidget.php b/lib/Dashboard/CalendarWidget.php index d0b6f3c31a..e5dddaa156 100644 --- a/lib/Dashboard/CalendarWidget.php +++ b/lib/Dashboard/CalendarWidget.php @@ -155,10 +155,23 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): foreach ($calendars as $calendar) { $searchResult = $calendar->search('', [], $options, $limit); foreach ($searchResult as $calendarEvent) { - /** @var DateTimeImmutable $startDate */ - $startDate = $calendarEvent['objects'][0]['DTSTART'][0]; + // Find first recurrence in the future + $recurrence = null; + foreach ($calendarEvent['objects'] as $object) { + /** @var DateTimeImmutable $startDate */ + $startDate = $object['DTSTART'][0]; + if ($startDate->getTimestamp() >= $dateTime->getTimestamp()) { + $recurrence = $object; + break; + } + } + + if ($recurrence === null) { + continue; + } + $widget = new WidgetItem( - $calendarEvent['objects'][0]['SUMMARY'][0] ?? 'New Event', + $recurrence['SUMMARY'][0] ?? 'New Event', $this->dateTimeFormatter->formatTimeSpan(DateTime::createFromImmutable($startDate)), $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('calendar.view.index', ['objectId' => $calendarEvent['uid']])), $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('calendar.view.getCalendarDotSvg', ['color' => $calendar->getDisplayColor() ?? '#0082c9'])), // default NC blue fallback @@ -167,6 +180,11 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): $widgetItems[] = $widget; } } + + usort($widgetItems, static function (WidgetItem $item) { + return $item->getSinceId(); + }); + return $widgetItems; } diff --git a/lib/Dashboard/CalendarWidgetV2.php b/lib/Dashboard/CalendarWidgetV2.php index f6e84f8da5..7e1c9f7fb8 100644 --- a/lib/Dashboard/CalendarWidgetV2.php +++ b/lib/Dashboard/CalendarWidgetV2.php @@ -43,10 +43,8 @@ public function getItemsV2(string $userId, ?string $since = null, int $limit = 7 $halfEmptyContentMessage = ''; if (!empty($widgetItems)) { $startOfTomorrow = $this->timeFactory->getDateTime('tomorrow')->getTimestamp(); - foreach ($widgetItems as $item) { - if ((int)$item->getSinceId() >= $startOfTomorrow) { - $halfEmptyContentMessage = $this->l10n->t('No more events today'); - } + if ($widgetItems[0]->getSinceId() >= $startOfTomorrow) { + $halfEmptyContentMessage = $this->l10n->t('No more events today'); } }