Skip to content

Commit

Permalink
fix(dashboard): properly handle recurring events
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Sep 20, 2023
1 parent e65ffbf commit c8f9829
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 $item) {

Check failure on line 184 in lib/Dashboard/CalendarWidget.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

InvalidArgument

lib/Dashboard/CalendarWidget.php:184:23: InvalidArgument: Argument 2 of usort expects callable(OCP\Dashboard\Model\WidgetItem, mixed):int, but pure-Closure(OCP\Dashboard\Model\WidgetItem):string provided (see https://psalm.dev/004)

Check failure on line 184 in lib/Dashboard/CalendarWidget.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

InvalidArgument

lib/Dashboard/CalendarWidget.php:184:23: InvalidArgument: Argument 2 of usort expects callable(OCP\Dashboard\Model\WidgetItem, mixed):int, but pure-Closure(OCP\Dashboard\Model\WidgetItem):string provided (see https://psalm.dev/004)

Check failure on line 184 in lib/Dashboard/CalendarWidget.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

InvalidArgument

lib/Dashboard/CalendarWidget.php:184:23: InvalidArgument: Argument 2 of usort expects callable(OCP\Dashboard\Model\WidgetItem, mixed):int, but pure-Closure(OCP\Dashboard\Model\WidgetItem):string provided (see https://psalm.dev/004)

Check failure on line 184 in lib/Dashboard/CalendarWidget.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable25

InvalidArgument

lib/Dashboard/CalendarWidget.php:184:23: InvalidArgument: Argument 2 of usort expects callable(OCP\Dashboard\Model\WidgetItem, mixed):int, but pure-Closure(OCP\Dashboard\Model\WidgetItem):string provided (see https://psalm.dev/004)
return $item->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 c8f9829

Please sign in to comment.