diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-14 16:55:20 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-10-20 12:14:59 +0200 |
commit | b35d2fd8f2e96f56951e33d27d07cb213375e46b (patch) | |
tree | 53759a73e85ec2b582872fd0ba6d3a81e1fb5218 /lib/private/Notification | |
parent | 20986488505616654177da1f861238f0232656fa (diff) | |
download | nextcloud-server-b35d2fd8f2e96f56951e33d27d07cb213375e46b.tar.gz nextcloud-server-b35d2fd8f2e96f56951e33d27d07cb213375e46b.zip |
Allow rich object subjects for Notifications
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Notification')
-rw-r--r-- | lib/private/Notification/Manager.php | 5 | ||||
-rw-r--r-- | lib/private/Notification/Notification.php | 64 |
2 files changed, 67 insertions, 2 deletions
diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index ec831cf9793..4b57db4bac9 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -24,6 +24,7 @@ namespace OC\Notification; +use OC\RichObjectStrings\Validator; use OCP\Notification\IApp; use OCP\Notification\IManager; use OCP\Notification\INotification; @@ -149,7 +150,9 @@ class Manager implements IManager { * @since 8.2.0 */ public function createNotification() { - return new Notification(); + return new Notification( + new Validator() + ); } /** diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 7bf4b9a74cf..7346f35f966 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -26,8 +26,14 @@ namespace OC\Notification; use OCP\Notification\IAction; use OCP\Notification\INotification; +use OCP\RichObjectStrings\InvalidObjectExeption; +use OCP\RichObjectStrings\IValidator; class Notification implements INotification { + + /** @var IValidator */ + protected $richValidator; + /** @var string */ protected $app; @@ -53,6 +59,12 @@ class Notification implements INotification { protected $subjectParsed; /** @var string */ + protected $subjectRich; + + /** @var array */ + protected $subjectRichParameters; + + /** @var string */ protected $message; /** @var array */ @@ -81,8 +93,11 @@ class Notification implements INotification { /** * Constructor + * + * @param IValidator $richValidator */ - public function __construct() { + public function __construct(IValidator $richValidator) { + $this->richValidator = $richValidator; $this->app = ''; $this->user = ''; $this->dateTime = new \DateTime(); @@ -92,6 +107,8 @@ class Notification implements INotification { $this->subject = ''; $this->subjectParameters = []; $this->subjectParsed = ''; + $this->subjectRich = ''; + $this->subjectRichParameters = []; $this->message = ''; $this->messageParameters = []; $this->messageParsed = ''; @@ -262,6 +279,43 @@ class Notification implements INotification { } /** + * @param string $subject + * @param array $parameters + * @return $this + * @throws \InvalidArgumentException if the subject or parameters are invalid + * @since 9.2.0 + */ + public function setRichSubject($subject, array $parameters = []) { + if (!is_string($subject) || $subject === '') { + throw new \InvalidArgumentException('The given parsed subject is invalid'); + } + $this->subjectRich = $subject; + + if (!is_array($parameters)) { + throw new \InvalidArgumentException('The given subject parameters are invalid'); + } + $this->subjectRichParameters = $parameters; + + return $this; + } + + /** + * @return string + * @since 9.2.0 + */ + public function getRichSubject() { + return $this->subjectRich; + } + + /** + * @return array[] + * @since 9.2.0 + */ + public function getRichSubjectParameters() { + return $this->subjectRichParameters; + } + + /** * @param string $message * @param array $parameters * @return $this @@ -454,6 +508,14 @@ class Notification implements INotification { * @since 8.2.0 */ public function isValidParsed() { + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { + try { + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); + } catch (InvalidObjectExeption $e) { + return false; + } + } + return $this->isValidCommon() && |