Apply the same changes to richToParsed in Notification

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/34807/head
Côme Chilliet 3 years ago committed by Côme Chilliet (Rebase PR Action)
parent cf8d97c9d3
commit 8a04bf5584
  1. 12
      lib/private/Notification/Notification.php

@ -302,17 +302,23 @@ class Notification implements INotification {
return $this;
}
/**
* @throws \InvalidArgumentException if a parameter has no name
*/
private function richToParsed(string $message, array $parameters): string {
$placeholders = [];
$replacements = [];
foreach ($parameters as $placeholder => $parameter) {
$placeholders[] = '{' . $placeholder . '}';
if (!isset($parameter['name']) || !is_string($parameter['name'])) {
throw new \InvalidArgumentException('Invalid rich object, name field is missing');
}
if (($parameter['type'] ?? '') === 'user') {
$replacements[] = '@' . $parameter['name'] ?? 'invalid-user';
$replacements[] = '@' . $parameter['name'];
} elseif (($parameter['type'] ?? '') === 'file') {
$replacements[] = $parameter['path'] ?? $parameter['name'] ?? 'invalid-file';
$replacements[] = $parameter['path'] ?? $parameter['name'];
} else {
$replacements[] = $parameter['name'] ?? 'invalid-object';
$replacements[] = $parameter['name'];
}
}
return str_replace($placeholders, $replacements, $message);

Loading…
Cancel
Save