diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-10-25 17:01:58 +0200 |
---|---|---|
committer | Côme Chilliet (Rebase PR Action) <come-nc@users.noreply.github.com> | 2022-11-29 14:36:29 +0000 |
commit | db995d464d06ace8231c41633287ce689b7d33b1 (patch) | |
tree | d1a4e2eedf857be31ced8917359e5721bad9a46b | |
parent | 323963e540c4650dcb0a3a8996dce81129fb5925 (diff) | |
download | nextcloud-server-db995d464d06ace8231c41633287ce689b7d33b1.tar.gz nextcloud-server-db995d464d06ace8231c41633287ce689b7d33b1.zip |
Same thing for Activity
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | lib/private/Activity/Event.php | 25 | ||||
-rw-r--r-- | lib/public/Activity/IEvent.php | 12 |
2 files changed, 26 insertions, 11 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index fd0c0afd9d8..b600a2c2249 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -33,7 +33,6 @@ use OCP\RichObjectStrings\InvalidObjectExeption; use OCP\RichObjectStrings\IValidator; class Event implements IEvent { - /** @var string */ protected $app = ''; /** @var string */ @@ -269,9 +268,29 @@ class Event implements IEvent { $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 @@ -350,6 +369,10 @@ class Event implements IEvent { $this->messageRich = $message; $this->messageRichParameters = $parameters; + if ($this->messageParsed === '') { + $this->messageParsed = $this->richToParsed($message, $parameters); + } + return $this; } diff --git a/lib/public/Activity/IEvent.php b/lib/public/Activity/IEvent.php index 1e3c1deef26..4c47cc47a3f 100644 --- a/lib/public/Activity/IEvent.php +++ b/lib/public/Activity/IEvent.php @@ -103,9 +103,7 @@ interface IEvent { * 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. * @@ -128,8 +126,6 @@ interface IEvent { * 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. * @@ -170,9 +166,7 @@ interface IEvent { * 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. * @@ -195,8 +189,6 @@ interface IEvent { * 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. * |