mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Apply the same changes to richToParsed in Notification
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
cf8d97c9d3
commit
8a04bf5584
1 changed files with 9 additions and 3 deletions
|
|
@ -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…
Reference in a new issue