aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-11-16 16:14:52 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-11-16 16:14:52 +0100
commit1666af89c2db24e05dfc8480e087fc73bb32e831 (patch)
tree3782d30e37e79c64ef13a541c07dfde9591c9935 /lib
parenta03b1f1ee9a5b641544847d0efd22b29e2e41b30 (diff)
downloadnextcloud-server-1666af89c2db24e05dfc8480e087fc73bb32e831.tar.gz
nextcloud-server-1666af89c2db24e05dfc8480e087fc73bb32e831.zip
Add "is primary action" to actions
Diffstat (limited to 'lib')
-rw-r--r--lib/private/notification/action.php24
-rw-r--r--lib/private/notification/iaction.php13
-rw-r--r--lib/private/notification/notification.php24
3 files changed, 61 insertions, 0 deletions
diff --git a/lib/private/notification/action.php b/lib/private/notification/action.php
index 6de8a1a4bbc..e1171531716 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
diff --git a/lib/private/notification/iaction.php b/lib/private/notification/iaction.php
index da6728f5c52..9fd964e3dcf 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
diff --git a/lib/private/notification/notification.php b/lib/private/notification/notification.php
index 40fe39a956e..15ca0fee5d2 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
*/
@@ -369,6 +375,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 +406,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;
}