Same thing for Activity

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 323963e540
commit db995d464d
  1. 25
      lib/private/Activity/Event.php
  2. 12
      lib/public/Activity/IEvent.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;
}

@ -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.
*

Loading…
Cancel
Save