diff options
-rw-r--r-- | lib/private/Notification/Notification.php | 25 | ||||
-rw-r--r-- | lib/public/Notification/INotification.php | 12 |
2 files changed, 26 insertions, 11 deletions
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 3e5cf1d6934..9610a2d2a12 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -32,7 +32,6 @@ use OCP\RichObjectStrings\InvalidObjectExeption; use OCP\RichObjectStrings\IValidator; class Notification implements INotification { - /** @var IValidator */ protected $richValidator; @@ -296,9 +295,29 @@ class Notification implements INotification { $this->subjectRich = $subject; $this->subjectRichParameters = $parameters; + if ($this->subjectParsed === '') { + $this->subjectParsed = $this->richToParsed($subject, $parameters); + } + return $this; } + private function richToParsed(string $message, array $parameters): string { + $placeholders = []; + $replacements = []; + foreach ($parameters as $placeholder => $parameter) { + $placeholders[] = '{' . $placeholder . '}'; + if (($parameter['type'] ?? '') === 'user') { + $replacements[] = '@' . $parameter['name'] ?? 'invalid-user'; + } elseif (($parameter['type'] ?? '') === 'file') { + $replacements[] = $parameter['path'] ?? $parameter['name'] ?? 'invalid-file'; + } else { + $replacements[] = $parameter['name'] ?? 'invalid-object'; + } + } + return str_replace($placeholders, $replacements, $message); + } + /** * @return string * @since 11.0.0 @@ -386,6 +405,10 @@ class Notification implements INotification { $this->messageRich = $message; $this->messageRichParameters = $parameters; + if ($this->messageParsed === '') { + $this->messageParsed = $this->richToParsed($message, $parameters); + } + return $this; } diff --git a/lib/public/Notification/INotification.php b/lib/public/Notification/INotification.php index 511f65955f5..0c6625e346d 100644 --- a/lib/public/Notification/INotification.php +++ b/lib/public/Notification/INotification.php @@ -121,9 +121,7 @@ interface INotification { * HTML is not allowed in the parsed subject and will be escaped * automatically by the clients. You can use the RichObjectString system * provided by the Nextcloud server to highlight important parameters via - * the setRichSubject method, but make sure, that a plain text message is - * always set via setParsedSubject, to support clients which can not handle - * rich strings. + * the setRichSubject method. * * See https://github.com/nextcloud/server/issues/1706 for more information. * @@ -146,8 +144,6 @@ interface INotification { * HTML is not allowed in the rich subject and will be escaped automatically * by the clients, but you can use the RichObjectString system provided by * the Nextcloud server to highlight important parameters. - * Also make sure, that a plain text subject is always set via - * setParsedSubject, to support clients which can not handle rich strings. * * See https://github.com/nextcloud/server/issues/1706 for more information. * @@ -198,9 +194,7 @@ interface INotification { * HTML is not allowed in the parsed message and will be escaped * automatically by the clients. You can use the RichObjectString system * provided by the Nextcloud server to highlight important parameters via - * the setRichMessage method, but make sure, that a plain text message is - * always set via setParsedMessage, to support clients which can not handle - * rich strings. + * the setRichMessage method. * * See https://github.com/nextcloud/server/issues/1706 for more information. * @@ -223,8 +217,6 @@ interface INotification { * HTML is not allowed in the rich message and will be escaped automatically * by the clients, but you can use the RichObjectString system provided by * the Nextcloud server to highlight important parameters. - * Also make sure, that a plain text message is always set via - * setParsedMessage, to support clients which can not handle rich strings. * * See https://github.com/nextcloud/server/issues/1706 for more information. * |