]> source.dussan.org Git - nextcloud-server.git/commitdiff
Handle reminders where calendar name is null 36217/head
authorThomas Citharel <tcit@tcit.fr>
Wed, 18 Jan 2023 13:22:15 +0000 (14:22 +0100)
committerThomas Citharel <tcit@tcit.fr>
Wed, 18 Jan 2023 13:30:43 +0000 (14:30 +0100)
This adds an interface change, but that's not a public API.

We're handling this in the providers and not in ReminderService because
the fallback is translated with the user's language.

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
apps/dav/lib/CalDAV/Reminder/INotificationProvider.php
apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php

index 505960ed66208d1301cb21ab08e97806863a9911..e8cbfdd0ab3687c251a4e9e4a301a3c46b503bdd 100644 (file)
@@ -42,13 +42,13 @@ interface INotificationProvider {
         * Send notification
         *
         * @param VEvent $vevent
-        * @param string $calendarDisplayName
+        * @param string|null $calendarDisplayName
         * @param string[] $principalEmailAddresses All email addresses associated to the principal owning the calendar object
         * @param IUser[] $users
         * @return void
         */
        public function send(VEvent $vevent,
-                                                string $calendarDisplayName,
+                                                ?string $calendarDisplayName,
                                                 array  $principalEmailAddresses,
                                                 array $users = []): void;
 }
index 6986328facd30f5d322da6ac222fc3cc6cae29ad..bccbec5fe3caa4656ff7269785514179fd7021c0 100644 (file)
@@ -82,13 +82,13 @@ abstract class AbstractProvider implements INotificationProvider {
         * Send notification
         *
         * @param VEvent $vevent
-        * @param string $calendarDisplayName
+        * @param string|null $calendarDisplayName
         * @param string[] $principalEmailAddresses
         * @param IUser[] $users
         * @return void
         */
        abstract public function send(VEvent $vevent,
-                                                  string $calendarDisplayName,
+                                                  ?string $calendarDisplayName,
                                                   array $principalEmailAddresses,
                                                   array $users = []): void;
 
@@ -185,4 +185,8 @@ abstract class AbstractProvider implements INotificationProvider {
 
                return clone $vevent->DTSTART;
        }
+
+       protected function getCalendarDisplayNameFallback(string $lang): string {
+               return $this->getL10NForLang($lang)->t('Untitled calendar');
+       }
 }
index 3207268896779f282ace6f6763a670227f8a0e4d..da275efdcf19f38d0ad2d77893ce92ef0ead5c5d 100644 (file)
@@ -70,13 +70,13 @@ class EmailProvider extends AbstractProvider {
         * Send out notification via email
         *
         * @param VEvent $vevent
-        * @param string $calendarDisplayName
+        * @param string|null $calendarDisplayName
         * @param string[] $principalEmailAddresses
         * @param array $users
         * @throws \Exception
         */
        public function send(VEvent $vevent,
-                                                string $calendarDisplayName,
+                                                ?string $calendarDisplayName,
                                                 array $principalEmailAddresses,
                                                 array $users = []):void {
                $fallbackLanguage = $this->getFallbackLanguage();
@@ -115,7 +115,7 @@ class EmailProvider extends AbstractProvider {
                        $template = $this->mailer->createEMailTemplate('dav.calendarReminder');
                        $template->addHeader();
                        $this->addSubjectAndHeading($template, $l10n, $vevent);
-                       $this->addBulletList($template, $l10n, $calendarDisplayName, $vevent);
+                       $this->addBulletList($template, $l10n, $calendarDisplayName ?? $this->getCalendarDisplayNameFallback($lang), $vevent);
                        $template->addFooter();
 
                        foreach ($emailAddresses as $emailAddress) {
index 833d74079aa8acfb51a8ac0f9c6144d0bac173b7..be8bafd2f3569c5b04dbb0d75172d6a3a47125ec 100644 (file)
@@ -73,13 +73,13 @@ class PushProvider extends AbstractProvider {
         * Send push notification to all users.
         *
         * @param VEvent $vevent
-        * @param string $calendarDisplayName
+        * @param string|null $calendarDisplayName
         * @param string[] $principalEmailAddresses
         * @param IUser[] $users
         * @throws \Exception
         */
        public function send(VEvent $vevent,
-                                                string $calendarDisplayName,
+                                                ?string $calendarDisplayName,
                                                 array $principalEmailAddresses,
                                                 array $users = []):void {
                if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') {
@@ -87,7 +87,6 @@ class PushProvider extends AbstractProvider {
                }
 
                $eventDetails = $this->extractEventDetails($vevent);
-               $eventDetails['calendar_displayname'] = $calendarDisplayName;
                $eventUUID = (string) $vevent->UID;
                if (!$eventUUID) {
                        return;
@@ -95,6 +94,8 @@ class PushProvider extends AbstractProvider {
                $eventUUIDHash = hash('sha256', $eventUUID, false);
 
                foreach ($users as $user) {
+                       $eventDetails['calendar_displayname'] = $calendarDisplayName ?? $this->getCalendarDisplayNameFallback($this->l10nFactory->getUserLanguage($user));
+
                        /** @var INotification $notification */
                        $notification = $this->manager->createNotification();
                        $notification->setApp(Application::APP_ID)