Merge pull request #36217 from nextcloud/handle-push-notification-with-no-calendar-name

Handle reminders where calendar name is null
This commit is contained in:
Simon L 2023-04-17 15:43:21 +02:00 committed by GitHub
commit e63720b714
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View 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;
}

View 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');
}
}

View 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) {

View 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)