Skip to content

Commit f1e8058

Browse files
committed
feat: link upcoming event to calendar app modal
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 080473c commit f1e8058

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

apps/dav/lib/CalDAV/UpcomingEventsService.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,32 @@ public function getEvents(string $userId, ?string $location = null): array {
4747
$this->userManager->get($userId),
4848
);
4949

50-
return array_map(fn (array $event) => new UpcomingEvent(
51-
$event['uri'],
52-
($event['objects'][0]['RECURRENCE-ID'][0] ?? null)?->getTimeStamp(),
53-
$event['calendar-uri'],
54-
$event['objects'][0]['DTSTART'][0]?->getTimestamp(),
55-
$event['objects'][0]['SUMMARY'][0] ?? null,
56-
$event['objects'][0]['LOCATION'][0] ?? null,
57-
match ($calendarAppEnabled) {
50+
return array_map(function (array $event) use ($userId, $calendarAppEnabled) {
51+
$calendarAppUrl = null;
52+
53+
if ($calendarAppEnabled) {
54+
$arguments = [
55+
'objectId' => base64_encode($this->urlGenerator->getWebroot() . '/remote.php/dav/calendars/' . $userId . '/' . $event['calendar-uri'] . '/' . $event['uri']),
56+
];
57+
58+
if (isset($event['RECURRENCE-ID'])) {
59+
$arguments['recurrenceId'] = $event['RECURRENCE-ID'][0];
60+
}
61+
$calendarAppUrl = $this->urlGenerator->linkToRouteAbsolute('calendar.view.indexdirect.edit', $arguments);
62+
}
63+
64+
return new UpcomingEvent(
65+
$event['uri'],
66+
($event['objects'][0]['RECURRENCE-ID'][0] ?? null)?->getTimeStamp(),
67+
$event['calendar-uri'],
68+
$event['objects'][0]['DTSTART'][0]?->getTimestamp(),
69+
$event['objects'][0]['SUMMARY'][0] ?? null,
70+
$event['objects'][0]['LOCATION'][0] ?? null,
5871
// TODO: create a named, deep route in calendar
5972
// TODO: it's a code smell to just assume this route exists, find an abstraction
60-
true => $this->urlGenerator->linkToRouteAbsolute('calendar.view.index'),
61-
false => null,
62-
},
63-
), $events);
73+
$calendarAppUrl,
74+
);
75+
}, $events);
6476
}
6577

6678
}

0 commit comments

Comments
 (0)