diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-28 14:55:53 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-16 09:25:45 +0100 |
commit | 72f0d9981eca7b1be5832ea2d1a0cbd9526e85a4 (patch) | |
tree | 993ef2a9915bcdd8b9ebb8e3ecbc8015abccb918 /lib/private | |
parent | a366602961769f2b7a5d3947a61713efde38cc2f (diff) | |
download | nextcloud-server-72f0d9981eca7b1be5832ea2d1a0cbd9526e85a4.tar.gz nextcloud-server-72f0d9981eca7b1be5832ea2d1a0cbd9526e85a4.zip |
Add ROS and icon support to the events
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Activity/Event.php | 197 | ||||
-rw-r--r-- | lib/private/Activity/Manager.php | 21 |
2 files changed, 194 insertions, 24 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index 299199766ce..a830cc4857e 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -24,6 +24,8 @@ namespace OC\Activity; use OCP\Activity\IEvent; +use OCP\RichObjectStrings\InvalidObjectExeption; +use OCP\RichObjectStrings\IValidator; class Event implements IEvent { @@ -42,10 +44,22 @@ class Event implements IEvent { /** @var array */ protected $subjectParameters = []; /** @var string */ + protected $subjectParsed; + /** @var string */ + protected $subjectRich; + /** @var array */ + protected $subjectRichParameters; + /** @var string */ protected $message = ''; /** @var array */ protected $messageParameters = []; /** @var string */ + protected $messageParsed; + /** @var string */ + protected $messageRich; + /** @var array */ + protected $messageRichParameters; + /** @var string */ protected $objectType = ''; /** @var int */ protected $objectId = 0; @@ -53,6 +67,18 @@ class Event implements IEvent { protected $objectName = ''; /** @var string */ protected $link = ''; + /** @var string */ + protected $icon = ''; + + /** @var IValidator */ + protected $richValidator; + + /** + * @param IValidator $richValidator + */ + public function __construct(IValidator $richValidator) { + $this->richValidator = $richValidator; + } /** * Set the app of the activity @@ -202,6 +228,65 @@ class Event implements IEvent { } /** + * @param string $subject + * @return $this + * @throws \InvalidArgumentException if the subject is invalid + * @since 9.2.0 + */ + public function setParsedSubject($subject) { + if (!is_string($subject) || $subject === '') { + throw new \InvalidArgumentException('The given parsed subject is invalid'); + } + $this->subjectParsed = $subject; + return $this; + } + + /** + * @return string + * @since 9.2.0 + */ + public function getParsedSubject() { + return $this->subjectParsed; + } + + /** + * @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; + } + + /** * Set the message of the activity * * @param string $message @@ -211,7 +296,7 @@ class Event implements IEvent { * @since 8.2.0 */ public function setMessage($message, array $parameters = []) { - if (!is_string($message) || $message === '' || isset($message[255])) { + if (!is_string($message) || isset($message[255])) { throw new \InvalidArgumentException('The given message is invalid'); } $this->message = (string) $message; @@ -234,6 +319,65 @@ class Event implements IEvent { } /** + * @param string $message + * @return $this + * @throws \InvalidArgumentException if the message is invalid + * @since 9.2.0 + */ + public function setParsedMessage($message) { + if (!is_string($message) || $message === '') { + throw new \InvalidArgumentException('The given parsed message is invalid'); + } + $this->messageParsed = $message; + return $this; + } + + /** + * @return string + * @since 9.2.0 + */ + public function getParsedMessage() { + return $this->messageParsed; + } + + /** + * @param string $message + * @param array $parameters + * @return $this + * @throws \InvalidArgumentException if the subject 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; + } + + /** * Set the object of the activity * * @param string $objectType @@ -289,7 +433,7 @@ class Event implements IEvent { * @since 8.2.0 */ public function setLink($link) { - if (!is_string($link) || $link === '' || isset($link[4000])) { + if (!is_string($link) || isset($link[4000])) { throw new \InvalidArgumentException('The given link is invalid'); } $this->link = (string) $link; @@ -302,6 +446,29 @@ class Event implements IEvent { public function getLink() { return $this->link; } + + /** + * @param string $icon + * @return $this + * @throws \InvalidArgumentException if the icon is invalid + * @since 9.2.0 + */ + public function setIcon($icon) { + if (!is_string($icon) || isset($icon[4000])) { + throw new \InvalidArgumentException('The given icon is invalid'); + } + $this->icon = $icon; + return $this; + } + + /** + * @return string + * @since 9.2.0 + */ + public function getIcon() { + return $this->icon; + } + /** * @return bool * @since 8.2.0 @@ -319,18 +486,26 @@ class Event implements IEvent { * @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; -// } -// } + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { + try { + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); + } catch (InvalidObjectExeption $e) { + return false; + } + } + + if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { + try { + $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); + } catch (InvalidObjectExeption $e) { + return false; + } + } return $this->isValidCommon() -// && -// $this->getParsedSubject() !== '' + && + $this->getParsedSubject() !== '' ; } diff --git a/lib/private/Activity/Manager.php b/lib/private/Activity/Manager.php index 60a4a935898..c0e75b12091 100644 --- a/lib/private/Activity/Manager.php +++ b/lib/private/Activity/Manager.php @@ -24,6 +24,7 @@ namespace OC\Activity; +use OC\RichObjectStrings\Validator; use OCP\Activity\IConsumer; use OCP\Activity\IEvent; use OCP\Activity\IExtension; @@ -149,7 +150,9 @@ class Manager implements IManager { * @return IEvent */ public function generateEvent() { - return new Event(); + return new Event( + new Validator() + ); } /** @@ -166,18 +169,6 @@ class Manager implements IManager { * @throws \BadMethodCallException if required values have not been set */ public function publish(IEvent $event) { - if (!$event->getApp()) { - throw new \BadMethodCallException('App not set', 10); - } - if (!$event->getType()) { - throw new \BadMethodCallException('Type not set', 11); - } - if ($event->getAffectedUser() === null) { - throw new \BadMethodCallException('Affected user not set', 12); - } - if ($event->getSubject() === null || $event->getSubjectParameters() === null) { - throw new \BadMethodCallException('Subject not set', 13); - } if ($event->getAuthor() === null) { if ($this->session->getUser() instanceof IUser) { @@ -189,6 +180,10 @@ class Manager implements IManager { $event->setTimestamp(time()); } + if (!$event->isValid()) { + throw new \BadMethodCallException('The given event is invalid'); + } + foreach ($this->getConsumers() as $c) { $c->receive($event); } |