commit 7aac2718b5531911bbd1ade02c17c36a8f52cfa6 Author: Stefan Tollkühn Date: Wed Oct 7 21:57:34 2026 +0200 initial commit diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..b04be54 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,41 @@ +# AGENT.MD + +- When writing something intended for human consumption, (comment, commit message, reply to prompt) use as few words as possible. Pick every word meticulously to reduce the volume to a strict minimum. Be down to the point. Less is more. + +- Avoid superlatives and praise. Stop telling me I am absolutely right. Give me the cold hard truth. + +- Avoid magic numbers and strings by extracting recurring or meaningful values into descriptive constants (const) or enums. Keep self-explanatory, one-off values inline to avoid clutter. If a value comes from a spec (e.g. HTTP 200 OK), use a constant regardless. + +- Reduce code indentation. Avoid Arrow Anti-Pattern. Leverage early return and continue. + +- Keep function names short. Less than 30 characters. + +- Use enums instead of booleans for function parameters. + +- Let the reader of the code breathe. Add empty lines between logical blocks of code. + +- Add a small, to the point, comment to explain *what* the block does and *why*. Use examples when possible. Propose ASCII drawings to explain complete systems. + +- Treat member visibility changes as a breaking design shift. Keep all fields and functions private unless external access is strictly required by the design. Prompt the user for explicit approval before changing any access modifier from private to internal or public. + +- Program to levels of abstraction. Lower-level mechanics (e.g., raw hardware I/O, sector parsing, direct socket streams) must be encapsulated in a dedicated driver/abstraction layer. Expose clean, high-level APIs to the rest of the application so calling code works with domain concepts, not raw implementation details. + +- Don't touch blocks of code unrelated to the feature you implement. e.g. Don't add comments to a block of code if you did not create it or modify it. As much as possible try to minimize the number of changed lines when implementing a feature. + +- Strictly adhere to the layered boundary hierarchy: each layer may only communicate with its immediate neighbor directly below it. Never "punch holes" through layers (e.g., controllers or UI components must never directly call database queries, raw hardware drivers, or low-level network clients; always route through the intermediate service/abstraction layer). + +- Always use {}, even on a one-line "if" statement. + +When you write a commit message, follow these 7 rules: +Rule 1: Separate the subject line from the body with a single blank line. +Rule 2: Limit the subject line to 50 characters (72 is the absolute hard limit). +Rule 3: Capitalize the first letter of the subject line. +Rule 4: Do not end the subject line with a period. +Rule 5: Use the imperative mood in the subject line (e.g., "Fix bug," "Add feature," + not "Fixed" or "Adds"). Test formula: It must complete the sentence: "If applied, + this commit will [your subject line here]". +Rule 6: Wrap the body text manually at 72 characters to prevent Git formatting issues. +Rule 7: Use the body to explain what and why vs. how. Assume the code explains the how; + the message must explain the context and reasoning. + +- If the prompt indicates that a bug is being fixed, don't write the fix right away. First write the test. Observe it failing. Then write the fix. And observe the test passing. \ No newline at end of file diff --git a/appinfo/info.xml b/appinfo/info.xml new file mode 100644 index 0000000..3f09a54 --- /dev/null +++ b/appinfo/info.xml @@ -0,0 +1,18 @@ + + + jitsi_calendar + Jitsi Calendar + Create Jitsi meetings in the user's Nextcloud Calendar + + Allows the Jitsi meeting launcher to create calendar events in the authenticated user's Nextcloud Calendar. + + 1.0.0 + AGPL + Stefan Tollkühn s.tollkuehn@bnvb-ingenieure.de + JitsiCalendar + integration + + + + + \ No newline at end of file diff --git a/appinfo/routes.php b/appinfo/routes.php new file mode 100644 index 0000000..a7a6be5 --- /dev/null +++ b/appinfo/routes.php @@ -0,0 +1,18 @@ + [ + [ + 'name' => 'calendar#confirm', + 'url' => '/confirm', + 'verb' => 'GET', + ], + [ + 'name' => 'calendar#create', + 'url' => '/create', + 'verb' => 'POST', + ], + ], +]; \ No newline at end of file diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php new file mode 100644 index 0000000..764af8c --- /dev/null +++ b/lib/AppInfo/Application.php @@ -0,0 +1,34 @@ +getContainer(); + + $container->registerService( + CalendarController::class, + function (IAppContainer $c): CalendarController { + return new CalendarController( + self::APP_ID, + $c->get('Request'), + $c->get(\OCP\Calendar\IManager::class), + $c->get(\OCP\IUserSession::class), + $c->get(\OCP\IURLGenerator::class) + ); + } + ); + } +} \ No newline at end of file diff --git a/lib/Controller/CalendarController.php b/lib/Controller/CalendarController.php new file mode 100644 index 0000000..e6acd40 --- /dev/null +++ b/lib/Controller/CalendarController.php @@ -0,0 +1,394 @@ +calendarManager = $calendarManager; + $this->userSession = $userSession; + $this->urlGenerator = $urlGenerator; + } + + /** + * Show event confirmation. + * + * The route itself requires an authenticated Nextcloud user. + * If the user is not authenticated, Nextcloud's normal + * authentication flow takes over before the controller executes. + */ + public function confirm( + string $summary = '', + string $description = '', + string $start = '', + string $end = '', + string $organizer = '', + string $location = '', + string $url = '' + ): TemplateResponse { + $data = $this->validateEventData( + $summary, + $description, + $start, + $end, + $organizer, + $location, + $url + ); + + return new TemplateResponse( + self::APP_ID, + 'confirm', + [ + 'summary' => $data['summary'], + 'description' => $data['description'], + 'start' => $data['start'], + 'end' => $data['end'], + 'organizer' => $data['organizer'], + 'location' => $data['location'], + 'url' => $data['url'], + 'createUrl' => $this->urlGenerator->linkToRoute( + self::APP_ID . '.calendar.create' + ), + ] + ); + } + + /** + * Create the calendar event. + */ + public function create( + string $summary = '', + string $description = '', + string $start = '', + string $end = '', + string $organizer = '', + string $location = '', + string $url = '' + ): RedirectResponse { + $data = $this->validateEventData( + $summary, + $description, + $start, + $end, + $organizer, + $location, + $url + ); + + $user = $this->userSession->getUser(); + + if ($user === null) { + throw new \RuntimeException('No authenticated Nextcloud user.'); + } + + $calendars = $this->calendarManager->getCalendarsForUser( + $user->getUID() + ); + + $writableCalendar = null; + + foreach ($calendars as $calendar) { + /* + * getCalendarsForUser() returns ICalendar objects. + * Only calendars implementing ICreateFromString are writable. + */ + if ($calendar instanceof \OCP\Calendar\ICreateFromString) { + $writableCalendar = $calendar; + break; + } + } + + if ($writableCalendar === null) { + throw new \RuntimeException( + 'No writable calendar is available for this user.' + ); + } + + $uid = 'jitsi-' . bin2hex(random_bytes(16)) + . '@meet.bnvb.eu'; + + $ics = $this->buildIcs( + $uid, + $data['summary'], + $data['description'], + $data['start'], + $data['end'], + $data['organizer'], + $data['location'], + $data['url'] + ); + + $filename = $uid . '.ics'; + + $writableCalendar->createFromString( + $filename, + $ics + ); + + /* + * Open the Nextcloud Calendar application. + */ + $calendarUrl = $this->urlGenerator->linkToRoute( + 'calendar.view.index' + ); + + return new RedirectResponse($calendarUrl); + } + + /** + * Validate and normalize all event input. + */ + private function validateEventData( + string $summary, + string $description, + string $start, + string $end, + string $organizer, + string $location, + string $url + ): array { + $summary = trim($summary); + $description = trim($description); + $start = trim($start); + $end = trim($end); + $organizer = trim($organizer); + $location = trim($location); + $url = trim($url); + + if ($summary === '') { + throw new \InvalidArgumentException( + 'Meeting title is required.' + ); + } + + if (mb_strlen($summary) > 255) { + throw new \InvalidArgumentException( + 'Meeting title is too long.' + ); + } + + if ($description !== '' && mb_strlen($description) > 10000) { + throw new \InvalidArgumentException( + 'Meeting description is too long.' + ); + } + + $startDate = $this->parseLocalDateTime($start); + $endDate = $this->parseLocalDateTime($end); + + if ($endDate <= $startDate) { + throw new \InvalidArgumentException( + 'End time must be after start time.' + ); + } + + if ($location !== '') { + $locationParts = parse_url($location); + + if ( + $locationParts === false || + !isset($locationParts['scheme']) || + !in_array( + strtolower($locationParts['scheme']), + ['https'], + true + ) + ) { + throw new \InvalidArgumentException( + 'Location must be an HTTPS URL.' + ); + } + } + + if ($url !== '') { + $urlParts = parse_url($url); + + if ( + $urlParts === false || + !isset($urlParts['scheme']) || + !in_array( + strtolower($urlParts['scheme']), + ['https'], + true + ) + ) { + throw new \InvalidArgumentException( + 'Meeting URL must be an HTTPS URL.' + ); + } + } + + if ($organizer !== '' && !filter_var( + $organizer, + FILTER_VALIDATE_EMAIL + )) { + throw new \InvalidArgumentException( + 'Invalid organizer email address.' + ); + } + + return [ + 'summary' => $summary, + 'description' => $description, + 'start' => $startDate, + 'end' => $endDate, + 'organizer' => $organizer, + 'location' => $location, + 'url' => $url, + ]; + } + + /** + * Parse datetime-local values. + * + * datetime-local has no timezone information, so we intentionally + * interpret the value in the Nextcloud server's configured timezone. + */ + private function parseLocalDateTime(string $value): \DateTimeImmutable + { + $date = \DateTimeImmutable::createFromFormat( + 'Y-m-d\TH:i', + $value + ); + + if ($date === false) { + $date = \DateTimeImmutable::createFromFormat( + 'Y-m-d\TH:i:s', + $value + ); + } + + if ($date === false) { + throw new \InvalidArgumentException( + 'Invalid date/time.' + ); + } + + return $date; + } + + /** + * Build an RFC 5545 iCalendar event. + */ + private function buildIcs( + string $uid, + string $summary, + string $description, + \DateTimeImmutable $start, + \DateTimeImmutable $end, + string $organizer, + string $location, + string $url + ): string { + $now = new \DateTimeImmutable('now'); + + $dtStamp = $now->setTimezone( + new \DateTimeZone('UTC') + )->format('Ymd\THis\Z'); + + $dtStart = $start->format('Ymd\THis'); + $dtEnd = $end->format('Ymd\THis'); + + $lines = [ + 'BEGIN:VCALENDAR', + 'VERSION:2.0', + 'PRODID:-//BNVB//Jitsi Calendar//EN', + 'CALSCALE:GREGORIAN', + 'METHOD:PUBLISH', + 'BEGIN:VEVENT', + 'UID:' . $this->escapeIcsText($uid), + 'DTSTAMP:' . $dtStamp, + 'DTSTART:' . $dtStart, + 'DTEND:' . $dtEnd, + 'SUMMARY:' . $this->escapeIcsText($summary), + ]; + + if ($description !== '') { + $lines[] = + 'DESCRIPTION:' . + $this->escapeIcsText($description); + } + + if ($location !== '') { + $lines[] = + 'LOCATION:' . + $this->escapeIcsText($location); + } + + if ($organizer !== '') { + $lines[] = + 'ORGANIZER:MAILTO:' . + $this->escapeIcsText($organizer); + } + + if ($url !== '') { + $lines[] = + 'URL:' . + $this->escapeIcsText($url); + } + + $lines[] = 'STATUS:CONFIRMED'; + $lines[] = 'SEQUENCE:0'; + $lines[] = 'TRANSP:OPAQUE'; + + $lines[] = 'BEGIN:VALARM'; + $lines[] = 'ACTION:DISPLAY'; + $lines[] = 'DESCRIPTION:Reminder'; + $lines[] = 'TRIGGER:-PT15M'; + $lines[] = 'END:VALARM'; + + $lines[] = 'END:VEVENT'; + $lines[] = 'END:VCALENDAR'; + + return implode("\r\n", $lines) . "\r\n"; + } + + private function escapeIcsText(string $value): string + { + return str_replace( + [ + '\\', + ';', + ',', + "\r\n", + "\r", + "\n", + ], + [ + '\\\\', + '\;', + '\,', + '\n', + '\n', + '\n', + ], + $value + ); + } +} \ No newline at end of file diff --git a/templates/confirm.php b/templates/confirm.php new file mode 100644 index 0000000..e517c1a --- /dev/null +++ b/templates/confirm.php @@ -0,0 +1,147 @@ + + +
+
+ +
+ +

+ Add Jitsi Meeting to Calendar +

+ +

+ The following meeting will be added to your + Nextcloud Calendar. +

+ +
+ +
+ Title + +
+ + +
+ Description + + + +
+ + +
+ Start + +
+ +
+ End + +
+ + +
+ Organizer + +
+ + + +
+ Location + + + + + +
+ + +
+ +
+ + + + + + + + + + + + + + +
+ + + + + Cancel + + +
+ +
+ +
+ +
+
\ No newline at end of file diff --git a/templates/style.css b/templates/style.css new file mode 100644 index 0000000..afa02e4 --- /dev/null +++ b/templates/style.css @@ -0,0 +1,75 @@ +.jitsi-calendar-container { + max-width: 760px; + margin: 60px auto; + padding: 20px; +} + +.jitsi-calendar-card { + background: var(--color-main-background); + border: 1px solid var(--color-border); + border-radius: 12px; + padding: 32px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); +} + +.jitsi-calendar-card h1 { + margin-top: 0; + margin-bottom: 12px; +} + +.jitsi-calendar-intro { + color: var(--color-text-maxcontrast); + margin-bottom: 28px; +} + +.jitsi-calendar-details { + border-top: 1px solid var(--color-border); + border-bottom: 1px solid var(--color-border); + margin-bottom: 28px; +} + +.jitsi-calendar-row { + display: grid; + grid-template-columns: 150px 1fr; + gap: 16px; + padding: 14px 0; + border-bottom: 1px solid var(--color-border); +} + +.jitsi-calendar-row:last-child { + border-bottom: 0; +} + +.jitsi-calendar-row span { + overflow-wrap: anywhere; +} + +.jitsi-calendar-row .description { + white-space: normal; +} + +.jitsi-calendar-actions { + display: flex; + gap: 12px; + flex-wrap: wrap; +} + +.jitsi-calendar-actions button, +.jitsi-calendar-actions a { + display: inline-block; + padding: 10px 18px; + border-radius: 6px; + text-decoration: none; + cursor: pointer; +} + +.jitsi-calendar-actions button.primary { + background: var(--color-primary-element); + color: var(--color-primary-element-text); + border: 0; +} + +.jitsi-calendar-actions a.secondary { + border: 1px solid var(--color-border); + color: var(--color-main-text); +} \ No newline at end of file