Merge pull request #1937 from nextcloud/ros-for-notification-message
Allow rich object strings in messages as well
This commit is contained in:
commit
e416ee7b74
|
@ -73,6 +73,12 @@ class Notification implements INotification {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $messageParsed;
|
protected $messageParsed;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $messageRich;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $messageRichParameters;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $link;
|
protected $link;
|
||||||
|
|
||||||
|
@ -112,6 +118,8 @@ class Notification implements INotification {
|
||||||
$this->message = '';
|
$this->message = '';
|
||||||
$this->messageParameters = [];
|
$this->messageParameters = [];
|
||||||
$this->messageParsed = '';
|
$this->messageParsed = '';
|
||||||
|
$this->messageRich = '';
|
||||||
|
$this->messageRichParameters = [];
|
||||||
$this->link = '';
|
$this->link = '';
|
||||||
$this->icon = '';
|
$this->icon = '';
|
||||||
$this->actions = [];
|
$this->actions = [];
|
||||||
|
@ -231,12 +239,10 @@ class Notification implements INotification {
|
||||||
if (!is_string($subject) || $subject === '' || isset($subject[64])) {
|
if (!is_string($subject) || $subject === '' || isset($subject[64])) {
|
||||||
throw new \InvalidArgumentException('The given subject is invalid');
|
throw new \InvalidArgumentException('The given subject is invalid');
|
||||||
}
|
}
|
||||||
$this->subject = $subject;
|
|
||||||
|
|
||||||
if (!is_array($parameters)) {
|
$this->subject = $subject;
|
||||||
throw new \InvalidArgumentException('The given subject parameters are invalid');
|
|
||||||
}
|
|
||||||
$this->subjectParameters = $parameters;
|
$this->subjectParameters = $parameters;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,11 +295,8 @@ class Notification implements INotification {
|
||||||
if (!is_string($subject) || $subject === '') {
|
if (!is_string($subject) || $subject === '') {
|
||||||
throw new \InvalidArgumentException('The given parsed subject is invalid');
|
throw new \InvalidArgumentException('The given parsed subject is invalid');
|
||||||
}
|
}
|
||||||
$this->subjectRich = $subject;
|
|
||||||
|
|
||||||
if (!is_array($parameters)) {
|
$this->subjectRich = $subject;
|
||||||
throw new \InvalidArgumentException('The given subject parameters are invalid');
|
|
||||||
}
|
|
||||||
$this->subjectRichParameters = $parameters;
|
$this->subjectRichParameters = $parameters;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -326,12 +329,10 @@ class Notification implements INotification {
|
||||||
if (!is_string($message) || $message === '' || isset($message[64])) {
|
if (!is_string($message) || $message === '' || isset($message[64])) {
|
||||||
throw new \InvalidArgumentException('The given message is invalid');
|
throw new \InvalidArgumentException('The given message is invalid');
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
|
||||||
|
|
||||||
if (!is_array($parameters)) {
|
$this->message = $message;
|
||||||
throw new \InvalidArgumentException('The given message parameters are invalid');
|
|
||||||
}
|
|
||||||
$this->messageParameters = $parameters;
|
$this->messageParameters = $parameters;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +374,40 @@ class Notification implements INotification {
|
||||||
return $this->messageParsed;
|
return $this->messageParsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param array $parameters
|
||||||
|
* @return $this
|
||||||
|
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function setRichMessage($message, array $parameters = []) {
|
||||||
|
if (!is_string($message) || $message === '') {
|
||||||
|
throw new \InvalidArgumentException('The given parsed message is invalid');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->messageRich = $message;
|
||||||
|
$this->messageRichParameters = $parameters;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function getRichMessage() {
|
||||||
|
return $this->messageRich;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function getRichMessageParameters() {
|
||||||
|
return $this->messageRichParameters;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $link
|
* @param string $link
|
||||||
* @return $this
|
* @return $this
|
||||||
|
@ -516,6 +551,14 @@ class Notification implements INotification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) {
|
||||||
|
try {
|
||||||
|
$this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters());
|
||||||
|
} catch (InvalidObjectExeption $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
$this->isValidCommon()
|
$this->isValidCommon()
|
||||||
&&
|
&&
|
||||||
|
|
|
@ -183,6 +183,27 @@ interface INotification {
|
||||||
*/
|
*/
|
||||||
public function getParsedMessage();
|
public function getParsedMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param array $parameters
|
||||||
|
* @return $this
|
||||||
|
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function setRichMessage($message, array $parameters = []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function getRichMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
* @since 9.2.0
|
||||||
|
*/
|
||||||
|
public function getRichMessageParameters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $link
|
* @param string $link
|
||||||
* @return $this
|
* @return $this
|
||||||
|
|
Loading…
Reference in New Issue