diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-17 08:39:06 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-17 08:39:06 +0100 |
commit | 705d208a8aba55cdb509380db19a0b4e2413d1eb (patch) | |
tree | 50a076472947fd7f02e05855d79a3b8151307e55 /lib | |
parent | 56f44a457c74cb5df0d5e950e67deac99cae7b41 (diff) | |
parent | 40d5d5512401673f30ba822ff26b1762c9730da9 (diff) | |
download | nextcloud-server-705d208a8aba55cdb509380db19a0b4e2413d1eb.tar.gz nextcloud-server-705d208a8aba55cdb509380db19a0b4e2413d1eb.zip |
Merge pull request #20539 from owncloud/notification-api-adjustment
Notification api update
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/notification/action.php | 46 | ||||
-rw-r--r-- | lib/private/notification/iaction.php | 27 | ||||
-rw-r--r-- | lib/private/notification/inotification.php | 14 | ||||
-rw-r--r-- | lib/private/notification/notification.php | 46 |
4 files changed, 61 insertions, 72 deletions
diff --git a/lib/private/notification/action.php b/lib/private/notification/action.php index 6de8a1a4bbc..958b085b38e 100644 --- a/lib/private/notification/action.php +++ b/lib/private/notification/action.php @@ -39,6 +39,9 @@ class Action implements IAction { /** @var string */ protected $icon; + /** @var bool */ + protected $primary; + /** * Constructor */ @@ -95,6 +98,27 @@ class Action implements IAction { } /** + * @param $primary bool + * @throws \InvalidArgumentException if $primary is invalid + * @since 9.0.0 + */ + public function setPrimary($primary) { + if (!is_bool($primary)) { + throw new \InvalidArgumentException('The given primary option is invalid'); + } + + $this->primary = $primary; + } + + /** + * @return bool + * @since 9.0.0 + */ + public function isPrimary() { + return $this->primary; + } + + /** * @param string $link * @param string $requestType * @return $this @@ -130,28 +154,6 @@ class Action implements IAction { } /** - * @param string $icon - * @return $this - * @throws \InvalidArgumentException if the icon is invalid - * @since 8.2.0 - */ - public function setIcon($icon) { - if (!is_string($icon) || $icon === '' || isset($icon[64])) { - throw new \InvalidArgumentException('The given icon is invalid'); - } - $this->icon = $icon; - return $this; - } - - /** - * @return string - * @since 8.2.0 - */ - public function getIcon() { - return $this->icon; - } - - /** * @return bool */ public function isValid() { diff --git a/lib/private/notification/iaction.php b/lib/private/notification/iaction.php index da6728f5c52..4aed2e92517 100644 --- a/lib/private/notification/iaction.php +++ b/lib/private/notification/iaction.php @@ -61,6 +61,19 @@ interface IAction { public function getParsedLabel(); /** + * @param $primary bool + * @throws \InvalidArgumentException if $primary is invalid + * @since 9.0.0 + */ + public function setPrimary($primary); + + /** + * @return bool + * @since 9.0.0 + */ + public function isPrimary(); + + /** * @param string $link * @param string $requestType * @return $this @@ -82,20 +95,6 @@ interface IAction { public function getRequestType(); /** - * @param string $icon - * @return $this - * @throws \InvalidArgumentException if the icon is invalid - * @since 8.2.0 - */ - public function setIcon($icon); - - /** - * @return string - * @since 8.2.0 - */ - public function getIcon(); - - /** * @return bool * @since 8.2.0 */ diff --git a/lib/private/notification/inotification.php b/lib/private/notification/inotification.php index faf5db1d24c..a8bf5b110ab 100644 --- a/lib/private/notification/inotification.php +++ b/lib/private/notification/inotification.php @@ -180,20 +180,6 @@ interface INotification { public function getLink(); /** - * @param string $icon - * @return $this - * @throws \InvalidArgumentException if the icon are invalid - * @since 8.2.0 - */ - public function setIcon($icon); - - /** - * @return string - * @since 8.2.0 - */ - public function getIcon(); - - /** * @return IAction * @since 8.2.0 */ diff --git a/lib/private/notification/notification.php b/lib/private/notification/notification.php index 40fe39a956e..01df659d4a1 100644 --- a/lib/private/notification/notification.php +++ b/lib/private/notification/notification.php @@ -68,6 +68,12 @@ class Notification implements INotification { /** @var array */ protected $actionsParsed; + /** @var bool */ + protected $hasPrimaryAction; + + /** @var bool */ + protected $hasPrimaryParsedAction; + /** * Constructor */ @@ -330,28 +336,6 @@ class Notification implements INotification { } /** - * @param string $icon - * @return $this - * @throws \InvalidArgumentException if the icon are invalid - * @since 8.2.0 - */ - public function setIcon($icon) { - if (!is_string($icon) || $icon === '' || isset($icon[64])) { - throw new \InvalidArgumentException('The given icon is invalid'); - } - $this->icon = $icon; - return $this; - } - - /** - * @return string - * @since 8.2.0 - */ - public function getIcon() { - return $this->icon; - } - - /** * @return IAction * @since 8.2.0 */ @@ -369,6 +353,15 @@ class Notification implements INotification { if (!$action->isValid()) { throw new \InvalidArgumentException('The given action is invalid'); } + + if ($action->isPrimary()) { + if ($this->hasPrimaryAction) { + throw new \InvalidArgumentException('The notification already has a primary action'); + } + + $this->hasPrimaryAction = true; + } + $this->actions[] = $action; return $this; } @@ -391,6 +384,15 @@ class Notification implements INotification { if (!$action->isValidParsed()) { throw new \InvalidArgumentException('The given parsed action is invalid'); } + + if ($action->isPrimary()) { + if ($this->hasPrimaryParsedAction) { + throw new \InvalidArgumentException('The notification already has a primary action'); + } + + $this->hasPrimaryParsedAction = true; + } + $this->actionsParsed[] = $action; return $this; } |