diff --git a/lib/Dashboard/CalendarWidget.php b/lib/Dashboard/CalendarWidget.php index d0b6f3c31a..f1bbd231e4 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 $a, WidgetItem $b) { + return (int)$a->getSinceId() - (int)$b->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'); } }