Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

use OCA\Calendar\Dashboard\CalendarWidget;
use OCA\Calendar\Events\BeforeAppointmentBookedEvent;
use OCA\Calendar\Listener\AppMenuActionListener;
use OCA\Calendar\Listener\AppointmentBookedListener;
use OCA\Calendar\Listener\CalendarReferenceListener;
use OCA\Calendar\Listener\EditorInitialStateListener;
use OCA\Calendar\Listener\NotifyPushListener;
use OCA\Calendar\Listener\UserDeletedListener;
use OCA\Calendar\Notification\Notifier;
Expand All @@ -22,11 +24,17 @@
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\Calendar\Events\CalendarObjectCreatedEvent;
use OCP\Calendar\Events\CalendarObjectDeletedEvent;
use OCP\Calendar\Events\CalendarObjectUpdatedEvent;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
use OCP\ServerVersion;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
Expand All @@ -35,6 +43,12 @@ class Application extends App implements IBootstrap {
/** @var string */
public const APP_ID = 'calendar';

/**
* Actions in the app menu, and with it the new event dialog,
* are only supported since Nextcloud 35.
*/
private const APP_MENU_ACTION_VERSION = 35;

/**
* @param array $params
*/
Expand All @@ -58,6 +72,12 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeAppointmentBookedEvent::class, AppointmentBookedListener::class);
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
$context->registerEventListener(RenderReferenceEvent::class, CalendarReferenceListener::class);
if ($this->hasAppMenuActions()) {
// The editor of the new event dialog can be opened on any page
$context->registerEventListener(BeforeTemplateRenderedEvent::class, EditorInitialStateListener::class);
// The app navigation action
$context->registerEventListener(LoadAdditionalEntriesEvent::class, AppMenuActionListener::class);
}

$context->registerEventListener(CalendarObjectCreatedEvent::class, NotifyPushListener::class);
$context->registerEventListener(CalendarObjectUpdatedEvent::class, NotifyPushListener::class);
Expand Down Expand Up @@ -89,4 +109,11 @@ private function addContactsMenuScript(ContainerInterface $container): void {
Util::addScript(self::APP_ID, 'calendar-contacts-menu');
Util::addStyle(self::APP_ID, 'calendar-contacts-menu');
}

/**
* Whether the server supports actions in the app menu.
*/
private function hasAppMenuActions(): bool {
return (new ServerVersion())->getMajorVersion() >= self::APP_MENU_ACTION_VERSION;
}
}
58 changes: 58 additions & 0 deletions lib/Listener/AppMenuActionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Calendar\Listener;

use OCA\Calendar\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
use OCP\Util;

/**
* Add the app menu action to create a new event from within any app.
*
* @template-implements IEventListener<Event|LoadAdditionalEntriesEvent>
*/
class AppMenuActionListener implements IEventListener {
public function __construct(
private IL10N $l10n,
private INavigationManager $navigationManager,
private IURLGenerator $urlGenerator,
private IUserSession $userSession,
) {
}

#[\Override]
public function handle(Event $event): void {
if (!$event instanceof LoadAdditionalEntriesEvent) {
return;
}

// Events can only be created for a user
if (!$this->userSession->isLoggedIn()) {
return;
}

$this->navigationManager->add([
'id' => 'calendar:new-event',
'order' => 4,
'icon' => $this->urlGenerator->imagePath(Application::APP_ID, 'calendar.svg'),
'name' => $this->l10n->t('Event'), // TRANSLATORS: This is the label of the action in the app menu to create a new calendar event
'type' => INavigationManager::TYPE_ACTION,

Check failure on line 52 in lib/Listener/AppMenuActionListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable32

UndefinedConstant

lib/Listener/AppMenuActionListener.php:52:14: UndefinedConstant: Constant OCP\INavigationManager::TYPE_ACTION is not defined (see https://psalm.dev/020)

Check failure on line 52 in lib/Listener/AppMenuActionListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable33

UndefinedConstant

lib/Listener/AppMenuActionListener.php:52:14: UndefinedConstant: Constant OCP\INavigationManager::TYPE_ACTION is not defined (see https://psalm.dev/020)

Check failure on line 52 in lib/Listener/AppMenuActionListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable34

UndefinedConstant

lib/Listener/AppMenuActionListener.php:52:14: UndefinedConstant: Constant OCP\INavigationManager::TYPE_ACTION is not defined (see https://psalm.dev/020)

Check failure on line 52 in lib/Listener/AppMenuActionListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedConstant

lib/Listener/AppMenuActionListener.php:52:14: UndefinedConstant: Constant OCP\INavigationManager::TYPE_ACTION is not defined (see https://psalm.dev/020)
]);

// Handles clicks on the action and spawns the editor
Util::addScript(Application::APP_ID, 'calendar-appMenu');
}
}
43 changes: 43 additions & 0 deletions lib/Listener/EditorInitialStateListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Calendar\Listener;

use OCA\Calendar\Service\CalendarInitialStateService;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IUserSession;

/**
* The new event dialog of the app menu can be opened on any page,
* so the state the editor needs has to be available everywhere.
*
* @template-implements IEventListener<Event|BeforeTemplateRenderedEvent>
*/
class EditorInitialStateListener implements IEventListener {
public function __construct(
private IUserSession $userSession,
private CalendarInitialStateService $calendarInitialStateService,
) {
}

#[\Override]
public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent) {
return;
}

if (!$this->userSession->isLoggedIn()) {
return;
}

$this->calendarInitialStateService->runForEditor();
}
}
94 changes: 58 additions & 36 deletions lib/Service/CalendarInitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class CalendarInitialStateService {

private bool $editorStateProvided = false;

public function __construct(
private string $appName,
private IInitialState $initialStateService,
Expand All @@ -41,50 +43,32 @@ public function __construct(
}

public function run(): void {
$this->runForEditor();

$defaultEventLimit = $this->config->getAppValue($this->appName, 'eventLimit', 'yes');
$defaultInitialView = $this->config->getAppValue($this->appName, 'currentView', 'dayGridMonth');
$defaultShowWeekends = $this->config->getAppValue($this->appName, 'showWeekends', 'yes');
$defaultWeekNumbers = $this->config->getAppValue($this->appName, 'showWeekNr', 'no');
$defaultSkipPopover = $this->config->getAppValue($this->appName, 'skipPopover', 'no');
$defaultTimezone = $this->config->getAppValue($this->appName, 'timezone', 'automatic');
$defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultDefaultReminder = $this->config->getAppValue($this->appName, 'defaultReminder', 'none');
$defaultShowTasks = $this->config->getAppValue($this->appName, 'showTasks', 'yes');
$defaultTasksSidebar = $this->config->getAppValue($this->appName, 'tasksSidebar', 'yes');

$appVersion = $this->config->getAppValue($this->appName, 'installed_version', '');
$eventLimit = $this->config->getUserValue($this->userId, $this->appName, 'eventLimit', $defaultEventLimit) === 'yes';
$firstRun = $this->config->getUserValue($this->userId, $this->appName, 'firstRun', 'yes') === 'yes';
$initialView = $this->getView($this->config->getUserValue($this->userId, $this->appName, 'currentView', $defaultInitialView));
$showWeekends = $this->config->getUserValue($this->userId, $this->appName, 'showWeekends', $defaultShowWeekends) === 'yes';
$showWeekNumbers = $this->config->getUserValue($this->userId, $this->appName, 'showWeekNr', $defaultWeekNumbers) === 'yes';
$skipPopover = $this->config->getUserValue($this->userId, $this->appName, 'skipPopover', $defaultSkipPopover) === 'yes';
$timezone = $this->config->getUserValue($this->userId, $this->appName, 'timezone', $defaultTimezone);
$attachmentsFolder = $this->config->getUserValue($this->userId, 'dav', 'attachmentsFolder', '/Calendar');
$slotDuration = $this->config->getUserValue($this->userId, $this->appName, 'slotDuration', $defaultSlotDuration);
$defaultReminder = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminder', $defaultDefaultReminder);
$defaultReminderPartDay = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminderPartDay', $defaultReminder);
$defaultReminderFullDay = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminderFullDay', $defaultReminder);
$showTasks = $this->config->getUserValue($this->userId, $this->appName, 'showTasks', $defaultShowTasks) === 'yes';
$tasksSidebar = $this->config->getUserValue($this->userId, $this->appName, 'tasksSidebar', $defaultTasksSidebar) === 'yes';
$hideEventExport = $this->config->getAppValue($this->appName, 'hideEventExport', 'no') === 'yes';
$disableAppointments = $this->config->getAppValue($this->appName, 'disableAppointments', 'no') === 'yes';
$forceEventAlarmType = $this->config->getAppValue($this->appName, 'forceEventAlarmType', '');
if (!in_array($forceEventAlarmType, ['DISPLAY', 'EMAIL'], true)) {
$forceEventAlarmType = false;
}
$canSubscribeLink = $this->config->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes';
$showResources = $this->config->getAppValue($this->appName, 'showResources', 'yes') === 'yes';
$publicCalendars = $this->config->getAppValue($this->appName, 'publicCalendars', '');

$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';
$tasksEnabled = $this->appManager->isEnabledForUser('tasks');

$circleVersion = $this->appManager->getAppVersion('circles');
$isCirclesEnabled = $this->appManager->isEnabledForUser('circles') === true;
// if circles is not installed, we use 0.0.0
$isCircleVersionCompatible = $this->compareVersion->isCompatible($circleVersion ? $circleVersion : '0.0.0', '22');

$calendarFederationEnabled = $this->appConfig->getValueBool(
'dav',
'enableCalendarFederation',
Expand All @@ -96,46 +80,84 @@ public function run(): void {
true,
);

$enableResourceBooking = !empty($this->resourceManager->getBackends())
|| !empty($this->roomManager->getBackends());

$this->initialStateService->provideInitialState('app_version', $appVersion);
$this->initialStateService->provideInitialState('event_limit', $eventLimit);
$this->initialStateService->provideInitialState('first_run', $firstRun);
$this->initialStateService->provideInitialState('initial_view', $initialView);
$this->initialStateService->provideInitialState('show_weekends', $showWeekends);
$this->initialStateService->provideInitialState('show_week_numbers', $showWeekNumbers);
$this->initialStateService->provideInitialState('skip_popover', $skipPopover);
$this->initialStateService->provideInitialState('talk_enabled', $this->isTalkEnabledForUser());
$this->initialStateService->provideInitialState('talk_api_version', $talkApiVersion);
$this->initialStateService->provideInitialState('timezone', $timezone);
$this->initialStateService->provideInitialState('attachments_folder', $attachmentsFolder);
$this->initialStateService->provideInitialState('slot_duration', $slotDuration);
$this->initialStateService->provideInitialState('default_reminder', $defaultReminder);
$this->initialStateService->provideInitialState('default_reminder_part_day', $defaultReminderPartDay);
$this->initialStateService->provideInitialState('default_reminder_full_day', $defaultReminderFullDay);
$this->initialStateService->provideInitialState('show_tasks', $showTasks);
$this->initialStateService->provideInitialState('tasks_sidebar', $tasksSidebar);
$this->initialStateService->provideInitialState('tasks_enabled', $tasksEnabled);
$this->initialStateService->provideInitialState('hide_event_export', $hideEventExport);
$this->initialStateService->provideInitialState('force_event_alarm_type', $forceEventAlarmType);
if (!is_null($this->userId)) {
$this->initialStateService->provideInitialState('appointmentConfigs', $this->appointmentConfigService->getAllAppointmentConfigurations($this->userId));
}
$this->initialStateService->provideInitialState('disable_appointments', $disableAppointments);
$this->initialStateService->provideInitialState('can_subscribe_link', $canSubscribeLink);
$this->initialStateService->provideInitialState('show_resources', $showResources);
$this->initialStateService->provideInitialState('isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);
$this->initialStateService->provideInitialState('publicCalendars', $publicCalendars);
$this->initialStateService->provideInitialState(
'calendar_federation_enabled',
$calendarFederationEnabled && $remoteSharesEnabled,
);
$this->initialStateService->provideInitialState('has_notify_push', $this->queue !== null);
}

/**
* Provide the state required by the event editor.
*
* This is the subset of {@see self::run()} needed on pages that do not render
* the calendar itself, but can spawn the editor - like the new event dialog of
* the app menu, which is available in every app.
*/
public function runForEditor(): void {
if ($this->editorStateProvided) {
return;
}
$this->editorStateProvided = true;

$defaultTimezone = $this->config->getAppValue($this->appName, 'timezone', 'automatic');
$defaultDefaultReminder = $this->config->getAppValue($this->appName, 'defaultReminder', 'none');

$appVersion = $this->config->getAppValue($this->appName, 'installed_version', '');
$timezone = $this->config->getUserValue($this->userId, $this->appName, 'timezone', $defaultTimezone);
$attachmentsFolder = $this->config->getUserValue($this->userId, 'dav', 'attachmentsFolder', '/Calendar');
$defaultReminder = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminder', $defaultDefaultReminder);
$defaultReminderPartDay = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminderPartDay', $defaultReminder);
$defaultReminderFullDay = $this->config->getUserValue($this->userId, $this->appName, 'defaultReminderFullDay', $defaultReminder);
$hideEventExport = $this->config->getAppValue($this->appName, 'hideEventExport', 'no') === 'yes';
$showResources = $this->config->getAppValue($this->appName, 'showResources', 'yes') === 'yes';
$forceEventAlarmType = $this->config->getAppValue($this->appName, 'forceEventAlarmType', '');
if (!in_array($forceEventAlarmType, ['DISPLAY', 'EMAIL'], true)) {
$forceEventAlarmType = false;
}

$talkApiVersion = version_compare($this->appManager->getAppVersion('spreed'), '12.0.0', '>=') ? 'v4' : 'v1';

$circleVersion = $this->appManager->getAppVersion('circles');
$isCirclesEnabled = $this->appManager->isEnabledForUser('circles') === true;
// if circles is not installed, we use 0.0.0
$isCircleVersionCompatible = $this->compareVersion->isCompatible($circleVersion ? $circleVersion : '0.0.0', '22');

$enableResourceBooking = !empty($this->resourceManager->getBackends())
|| !empty($this->roomManager->getBackends());

$this->initialStateService->provideInitialState('app_version', $appVersion);
$this->initialStateService->provideInitialState('timezone', $timezone);
$this->initialStateService->provideInitialState('attachments_folder', $attachmentsFolder);
$this->initialStateService->provideInitialState('default_reminder', $defaultReminder);
$this->initialStateService->provideInitialState('default_reminder_part_day', $defaultReminderPartDay);
$this->initialStateService->provideInitialState('default_reminder_full_day', $defaultReminderFullDay);
$this->initialStateService->provideInitialState('hide_event_export', $hideEventExport);
$this->initialStateService->provideInitialState('show_resources', $showResources);
$this->initialStateService->provideInitialState('force_event_alarm_type', $forceEventAlarmType);
$this->initialStateService->provideInitialState('talk_enabled', $this->isTalkEnabledForUser());
$this->initialStateService->provideInitialState('talk_api_version', $talkApiVersion);
$this->initialStateService->provideInitialState('isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);
$this->initialStateService->provideInitialState(
'resource_booking_enabled',
$enableResourceBooking,
);
$this->initialStateService->provideInitialState('has_notify_push', $this->queue !== null);
}

/**
Expand Down
1 change: 1 addition & 0 deletions rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = defineConfig((env) => {

entry: {
main: path.join(__dirname, 'src', 'main.js'),
appMenu: path.join(__dirname, 'src', 'app-menu.ts'),
reference: path.join(__dirname, 'src', 'reference.js'),
'contacts-menu': path.join(__dirname, 'src', 'contactsMenu.js'),
'appointments-booking': path.join(__dirname, 'src', 'appointments', 'main-booking.js'),
Expand Down
Loading
Loading