]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow rich object strings in messages as well
authorJoas Schilling <coding@schilljs.com>
Thu, 27 Oct 2016 13:43:34 +0000 (15:43 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 31 Oct 2016 09:37:37 +0000 (10:37 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Notification/Notification.php
lib/public/Notification/INotification.php

index 7346f35f966a11b8aa4d0442ea63089d3017819a..39fc6ab9465237c3b5c4392d37c3027c2ca1bae5 100644 (file)
@@ -73,6 +73,12 @@ class Notification implements INotification {
        /** @var string */
        protected $messageParsed;
 
+       /** @var string */
+       protected $messageRich;
+
+       /** @var array */
+       protected $messageRichParameters;
+
        /** @var string */
        protected $link;
 
@@ -112,6 +118,8 @@ class Notification implements INotification {
                $this->message = '';
                $this->messageParameters = [];
                $this->messageParsed = '';
+               $this->messageRich = '';
+               $this->messageRichParameters = [];
                $this->link = '';
                $this->icon = '';
                $this->actions = [];
@@ -373,6 +381,43 @@ class Notification implements INotification {
                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;
+
+               if (!is_array($parameters)) {
+                       throw new \InvalidArgumentException('The given message parameters are invalid');
+               }
+               $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
         * @return $this
@@ -516,6 +561,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
                        $this->isValidCommon()
                        &&
index 3a8bde0a375122f433de35b6138921781e4a58e6..55109a5ee2e4d58281769428f744cd28e2077d09 100644 (file)
@@ -183,6 +183,27 @@ interface INotification {
         */
        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
         * @return $this