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 /lib/private/Activity | |
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>
Diffstat (limited to 'lib/private/Activity')
-rw-r--r-- | lib/private/Activity/Event.php | 25 |
1 files changed, 24 insertions, 1 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; } |