2323
2424class CalendarInitialStateService {
2525
26+ private bool $ editorStateProvided = false ;
27+
2628 public function __construct (
2729 private string $ appName ,
2830 private IInitialState $ initialStateService ,
@@ -41,50 +43,32 @@ public function __construct(
4143 }
4244
4345 public function run (): void {
46+ $ this ->runForEditor ();
47+
4448 $ defaultEventLimit = $ this ->config ->getAppValue ($ this ->appName , 'eventLimit ' , 'yes ' );
4549 $ defaultInitialView = $ this ->config ->getAppValue ($ this ->appName , 'currentView ' , 'dayGridMonth ' );
4650 $ defaultShowWeekends = $ this ->config ->getAppValue ($ this ->appName , 'showWeekends ' , 'yes ' );
4751 $ defaultWeekNumbers = $ this ->config ->getAppValue ($ this ->appName , 'showWeekNr ' , 'no ' );
4852 $ defaultSkipPopover = $ this ->config ->getAppValue ($ this ->appName , 'skipPopover ' , 'no ' );
49- $ defaultTimezone = $ this ->config ->getAppValue ($ this ->appName , 'timezone ' , 'automatic ' );
5053 $ defaultSlotDuration = $ this ->config ->getAppValue ($ this ->appName , 'slotDuration ' , '00:30:00 ' );
51- $ defaultDefaultReminder = $ this ->config ->getAppValue ($ this ->appName , 'defaultReminder ' , 'none ' );
5254 $ defaultShowTasks = $ this ->config ->getAppValue ($ this ->appName , 'showTasks ' , 'yes ' );
5355 $ defaultTasksSidebar = $ this ->config ->getAppValue ($ this ->appName , 'tasksSidebar ' , 'yes ' );
5456
55- $ appVersion = $ this ->config ->getAppValue ($ this ->appName , 'installed_version ' , '' );
5657 $ eventLimit = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'eventLimit ' , $ defaultEventLimit ) === 'yes ' ;
5758 $ firstRun = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'firstRun ' , 'yes ' ) === 'yes ' ;
5859 $ initialView = $ this ->getView ($ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'currentView ' , $ defaultInitialView ));
5960 $ showWeekends = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'showWeekends ' , $ defaultShowWeekends ) === 'yes ' ;
6061 $ showWeekNumbers = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'showWeekNr ' , $ defaultWeekNumbers ) === 'yes ' ;
6162 $ skipPopover = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'skipPopover ' , $ defaultSkipPopover ) === 'yes ' ;
62- $ timezone = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'timezone ' , $ defaultTimezone );
63- $ attachmentsFolder = $ this ->config ->getUserValue ($ this ->userId , 'dav ' , 'attachmentsFolder ' , '/Calendar ' );
6463 $ slotDuration = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'slotDuration ' , $ defaultSlotDuration );
65- $ defaultReminder = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminder ' , $ defaultDefaultReminder );
66- $ defaultReminderPartDay = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminderPartDay ' , $ defaultReminder );
67- $ defaultReminderFullDay = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminderFullDay ' , $ defaultReminder );
6864 $ showTasks = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'showTasks ' , $ defaultShowTasks ) === 'yes ' ;
6965 $ tasksSidebar = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'tasksSidebar ' , $ defaultTasksSidebar ) === 'yes ' ;
70- $ hideEventExport = $ this ->config ->getAppValue ($ this ->appName , 'hideEventExport ' , 'no ' ) === 'yes ' ;
7166 $ disableAppointments = $ this ->config ->getAppValue ($ this ->appName , 'disableAppointments ' , 'no ' ) === 'yes ' ;
72- $ forceEventAlarmType = $ this ->config ->getAppValue ($ this ->appName , 'forceEventAlarmType ' , '' );
73- if (!in_array ($ forceEventAlarmType , ['DISPLAY ' , 'EMAIL ' ], true )) {
74- $ forceEventAlarmType = false ;
75- }
7667 $ canSubscribeLink = $ this ->config ->getAppValue ('dav ' , 'allow_calendar_link_subscriptions ' , 'yes ' ) === 'yes ' ;
77- $ showResources = $ this ->config ->getAppValue ($ this ->appName , 'showResources ' , 'yes ' ) === 'yes ' ;
7868 $ publicCalendars = $ this ->config ->getAppValue ($ this ->appName , 'publicCalendars ' , '' );
7969
80- $ talkApiVersion = version_compare ($ this ->appManager ->getAppVersion ('spreed ' ), '12.0.0 ' , '>= ' ) ? 'v4 ' : 'v1 ' ;
8170 $ tasksEnabled = $ this ->appManager ->isEnabledForUser ('tasks ' );
8271
83- $ circleVersion = $ this ->appManager ->getAppVersion ('circles ' );
84- $ isCirclesEnabled = $ this ->appManager ->isEnabledForUser ('circles ' ) === true ;
85- // if circles is not installed, we use 0.0.0
86- $ isCircleVersionCompatible = $ this ->compareVersion ->isCompatible ($ circleVersion ? $ circleVersion : '0.0.0 ' , '22 ' );
87-
8872 $ calendarFederationEnabled = $ this ->appConfig ->getValueBool (
8973 'dav ' ,
9074 'enableCalendarFederation ' ,
@@ -96,46 +80,84 @@ public function run(): void {
9680 true ,
9781 );
9882
99- $ enableResourceBooking = !empty ($ this ->resourceManager ->getBackends ())
100- || !empty ($ this ->roomManager ->getBackends ());
101-
102- $ this ->initialStateService ->provideInitialState ('app_version ' , $ appVersion );
10383 $ this ->initialStateService ->provideInitialState ('event_limit ' , $ eventLimit );
10484 $ this ->initialStateService ->provideInitialState ('first_run ' , $ firstRun );
10585 $ this ->initialStateService ->provideInitialState ('initial_view ' , $ initialView );
10686 $ this ->initialStateService ->provideInitialState ('show_weekends ' , $ showWeekends );
10787 $ this ->initialStateService ->provideInitialState ('show_week_numbers ' , $ showWeekNumbers );
10888 $ this ->initialStateService ->provideInitialState ('skip_popover ' , $ skipPopover );
109- $ this ->initialStateService ->provideInitialState ('talk_enabled ' , $ this ->isTalkEnabledForUser ());
110- $ this ->initialStateService ->provideInitialState ('talk_api_version ' , $ talkApiVersion );
111- $ this ->initialStateService ->provideInitialState ('timezone ' , $ timezone );
112- $ this ->initialStateService ->provideInitialState ('attachments_folder ' , $ attachmentsFolder );
11389 $ this ->initialStateService ->provideInitialState ('slot_duration ' , $ slotDuration );
114- $ this ->initialStateService ->provideInitialState ('default_reminder ' , $ defaultReminder );
115- $ this ->initialStateService ->provideInitialState ('default_reminder_part_day ' , $ defaultReminderPartDay );
116- $ this ->initialStateService ->provideInitialState ('default_reminder_full_day ' , $ defaultReminderFullDay );
11790 $ this ->initialStateService ->provideInitialState ('show_tasks ' , $ showTasks );
11891 $ this ->initialStateService ->provideInitialState ('tasks_sidebar ' , $ tasksSidebar );
11992 $ this ->initialStateService ->provideInitialState ('tasks_enabled ' , $ tasksEnabled );
120- $ this ->initialStateService ->provideInitialState ('hide_event_export ' , $ hideEventExport );
121- $ this ->initialStateService ->provideInitialState ('force_event_alarm_type ' , $ forceEventAlarmType );
12293 if (!is_null ($ this ->userId )) {
12394 $ this ->initialStateService ->provideInitialState ('appointmentConfigs ' , $ this ->appointmentConfigService ->getAllAppointmentConfigurations ($ this ->userId ));
12495 }
12596 $ this ->initialStateService ->provideInitialState ('disable_appointments ' , $ disableAppointments );
12697 $ this ->initialStateService ->provideInitialState ('can_subscribe_link ' , $ canSubscribeLink );
127- $ this ->initialStateService ->provideInitialState ('show_resources ' , $ showResources );
128- $ this ->initialStateService ->provideInitialState ('isCirclesEnabled ' , $ isCirclesEnabled && $ isCircleVersionCompatible );
12998 $ this ->initialStateService ->provideInitialState ('publicCalendars ' , $ publicCalendars );
13099 $ this ->initialStateService ->provideInitialState (
131100 'calendar_federation_enabled ' ,
132101 $ calendarFederationEnabled && $ remoteSharesEnabled ,
133102 );
103+ $ this ->initialStateService ->provideInitialState ('has_notify_push ' , $ this ->queue !== null );
104+ }
105+
106+ /**
107+ * Provide the state required by the event editor.
108+ *
109+ * This is the subset of {@see self::run()} needed on pages that do not render
110+ * the calendar itself, but can spawn the editor - like the new event dialog of
111+ * the app menu, which is available in every app.
112+ */
113+ public function runForEditor (): void {
114+ if ($ this ->editorStateProvided ) {
115+ return ;
116+ }
117+ $ this ->editorStateProvided = true ;
118+
119+ $ defaultTimezone = $ this ->config ->getAppValue ($ this ->appName , 'timezone ' , 'automatic ' );
120+ $ defaultDefaultReminder = $ this ->config ->getAppValue ($ this ->appName , 'defaultReminder ' , 'none ' );
121+
122+ $ appVersion = $ this ->config ->getAppValue ($ this ->appName , 'installed_version ' , '' );
123+ $ timezone = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'timezone ' , $ defaultTimezone );
124+ $ attachmentsFolder = $ this ->config ->getUserValue ($ this ->userId , 'dav ' , 'attachmentsFolder ' , '/Calendar ' );
125+ $ defaultReminder = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminder ' , $ defaultDefaultReminder );
126+ $ defaultReminderPartDay = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminderPartDay ' , $ defaultReminder );
127+ $ defaultReminderFullDay = $ this ->config ->getUserValue ($ this ->userId , $ this ->appName , 'defaultReminderFullDay ' , $ defaultReminder );
128+ $ hideEventExport = $ this ->config ->getAppValue ($ this ->appName , 'hideEventExport ' , 'no ' ) === 'yes ' ;
129+ $ showResources = $ this ->config ->getAppValue ($ this ->appName , 'showResources ' , 'yes ' ) === 'yes ' ;
130+ $ forceEventAlarmType = $ this ->config ->getAppValue ($ this ->appName , 'forceEventAlarmType ' , '' );
131+ if (!in_array ($ forceEventAlarmType , ['DISPLAY ' , 'EMAIL ' ], true )) {
132+ $ forceEventAlarmType = false ;
133+ }
134+
135+ $ talkApiVersion = version_compare ($ this ->appManager ->getAppVersion ('spreed ' ), '12.0.0 ' , '>= ' ) ? 'v4 ' : 'v1 ' ;
136+
137+ $ circleVersion = $ this ->appManager ->getAppVersion ('circles ' );
138+ $ isCirclesEnabled = $ this ->appManager ->isEnabledForUser ('circles ' ) === true ;
139+ // if circles is not installed, we use 0.0.0
140+ $ isCircleVersionCompatible = $ this ->compareVersion ->isCompatible ($ circleVersion ? $ circleVersion : '0.0.0 ' , '22 ' );
141+
142+ $ enableResourceBooking = !empty ($ this ->resourceManager ->getBackends ())
143+ || !empty ($ this ->roomManager ->getBackends ());
144+
145+ $ this ->initialStateService ->provideInitialState ('app_version ' , $ appVersion );
146+ $ this ->initialStateService ->provideInitialState ('timezone ' , $ timezone );
147+ $ this ->initialStateService ->provideInitialState ('attachments_folder ' , $ attachmentsFolder );
148+ $ this ->initialStateService ->provideInitialState ('default_reminder ' , $ defaultReminder );
149+ $ this ->initialStateService ->provideInitialState ('default_reminder_part_day ' , $ defaultReminderPartDay );
150+ $ this ->initialStateService ->provideInitialState ('default_reminder_full_day ' , $ defaultReminderFullDay );
151+ $ this ->initialStateService ->provideInitialState ('hide_event_export ' , $ hideEventExport );
152+ $ this ->initialStateService ->provideInitialState ('show_resources ' , $ showResources );
153+ $ this ->initialStateService ->provideInitialState ('force_event_alarm_type ' , $ forceEventAlarmType );
154+ $ this ->initialStateService ->provideInitialState ('talk_enabled ' , $ this ->isTalkEnabledForUser ());
155+ $ this ->initialStateService ->provideInitialState ('talk_api_version ' , $ talkApiVersion );
156+ $ this ->initialStateService ->provideInitialState ('isCirclesEnabled ' , $ isCirclesEnabled && $ isCircleVersionCompatible );
134157 $ this ->initialStateService ->provideInitialState (
135158 'resource_booking_enabled ' ,
136159 $ enableResourceBooking ,
137160 );
138- $ this ->initialStateService ->provideInitialState ('has_notify_push ' , $ this ->queue !== null );
139161 }
140162
141163 /**
0 commit comments