Skip to content

Commit

Permalink
Merge pull request #5486 from nextcloud/fix/dashboard/properly-handle…
Browse files Browse the repository at this point in the history
…-recurrences
  • Loading branch information
st3iny authored Sep 27, 2023
2 parents 940bafa + babc444 commit ac9a9d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
24 changes: 21 additions & 3 deletions lib/Dashboard/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Dashboard/CalendarWidgetV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down

0 comments on commit ac9a9d9

Please sign in to comment.