summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2015-08-20 15:53:36 +0200
committerJoas Schilling <nickvergessen@gmx.de>2015-08-20 15:53:36 +0200
commit9573d7d60d2d2c38ad82c8ca9befeb7ed7fa817f (patch)
tree53354456a337b3d556a33a9944409e01de8045a2 /lib
parent337898343c7dee2ca23ebdbb9f0ed7391dc33fb1 (diff)
parentc58316b1ae2657fca041d8ff40499bd4e19ba79a (diff)
downloadnextcloud-server-9573d7d60d2d2c38ad82c8ca9befeb7ed7fa817f.tar.gz
nextcloud-server-9573d7d60d2d2c38ad82c8ca9befeb7ed7fa817f.zip
Merge pull request #18372 from owncloud/issue-18358-object-type-and-id-for-activities
Issue 18358 object type and id for activities
Diffstat (limited to 'lib')
-rw-r--r--lib/private/activity/event.php250
-rw-r--r--lib/private/activitymanager.php132
-rw-r--r--lib/public/activity/iconsumer.php16
-rw-r--r--lib/public/activity/ievent.php200
-rw-r--r--lib/public/activity/imanager.php78
5 files changed, 601 insertions, 75 deletions
diff --git a/lib/private/activity/event.php b/lib/private/activity/event.php
new file mode 100644
index 00000000000..fe6fc485b7b
--- /dev/null
+++ b/lib/private/activity/event.php
@@ -0,0 +1,250 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Activity;
+
+use OCP\Activity\IEvent;
+
+class Event implements IEvent {
+ /** @var array */
+ protected $data = [
+ 'app' => null,
+ 'type' => null,
+ 'affected_user' => null,
+ 'author' => null,
+ 'timestamp' => null,
+ 'subject' => null,
+ 'subject_parameters' => null,
+ 'message' => '',
+ 'message_parameters' => [],
+ 'object_type' => '',
+ 'object_id' => 0,
+ 'object_name' => '',
+ 'link' => '',
+ ];
+
+ /**
+ * Set the app of the activity
+ *
+ * @param string $app
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setApp($app) {
+ $this->data['app'] = (string) $app;
+ return $this;
+ }
+
+ /**
+ * Set the type of the activity
+ *
+ * @param string $type
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setType($type) {
+ $this->data['type'] = (string) $type;
+ return $this;
+ }
+
+ /**
+ * Set the affected user of the activity
+ *
+ * @param string $affectedUser
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setAffectedUser($affectedUser) {
+ $this->data['affected_user'] = (string) $affectedUser;
+ return $this;
+ }
+
+ /**
+ * Set the author of the activity
+ *
+ * @param string $author
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setAuthor($author) {
+ $this->data['author'] = (string) $author;
+ return $this;
+ }
+
+ /**
+ * Set the author of the activity
+ *
+ * @param int $timestamp
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setTimestamp($timestamp) {
+ $this->data['timestamp'] = (int) $timestamp;
+ return $this;
+ }
+
+ /**
+ * Set the subject of the activity
+ *
+ * @param string $subject
+ * @param array $parameters
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setSubject($subject, array $parameters = []) {
+ $this->data['subject'] = (string) $subject;
+ $this->data['subject_parameters'] = $parameters;
+ return $this;
+ }
+
+ /**
+ * Set the message of the activity
+ *
+ * @param string $message
+ * @param array $parameters
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setMessage($message, array $parameters = []) {
+ $this->data['message'] = (string) $message;
+ $this->data['message_parameters'] = $parameters;
+ return $this;
+ }
+
+ /**
+ * Set the object of the activity
+ *
+ * @param string $objectType
+ * @param int $objectId
+ * @param string $objectName
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setObject($objectType, $objectId, $objectName = '') {
+ $this->data['object_type'] = (string) $objectType;
+ $this->data['object_id'] = (int) $objectId;
+ $this->data['object_name'] = (string) $objectName;
+ return $this;
+ }
+
+ /**
+ * Set the link of the activity
+ *
+ * @param string $link
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setLink($link) {
+ $this->data['link'] = (string) $link;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getApp() {
+ return $this->data['app'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getType() {
+ return $this->data['type'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getAffectedUser() {
+ return $this->data['affected_user'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getAuthor() {
+ return $this->data['author'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getTimestamp() {
+ return $this->data['timestamp'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getSubject() {
+ return $this->data['subject'];
+ }
+
+ /**
+ * @return array
+ */
+ public function getSubjectParameters() {
+ return $this->data['subject_parameters'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getMessage() {
+ return $this->data['message'];
+ }
+
+ /**
+ * @return array
+ */
+ public function getMessageParameters() {
+ return $this->data['message_parameters'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getObjectType() {
+ return $this->data['object_type'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getObjectId() {
+ return $this->data['object_id'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getObjectName() {
+ return $this->data['object_name'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getLink() {
+ return $this->data['link'];
+ }
+}
diff --git a/lib/private/activitymanager.php b/lib/private/activitymanager.php
index 938335a87e1..a973db7206f 100644
--- a/lib/private/activitymanager.php
+++ b/lib/private/activitymanager.php
@@ -24,11 +24,14 @@
namespace OC;
+use OC\Activity\Event;
use OCP\Activity\IConsumer;
+use OCP\Activity\IEvent;
use OCP\Activity\IExtension;
use OCP\Activity\IManager;
use OCP\IConfig;
use OCP\IRequest;
+use OCP\IUser;
use OCP\IUserSession;
class ActivityManager implements IManager {
@@ -124,36 +127,87 @@ class ActivityManager implements IManager {
}
/**
- * @param $app
- * @param $subject
- * @param $subjectParams
- * @param $message
- * @param $messageParams
- * @param $file
- * @param $link
- * @param $affectedUser
- * @param $type
- * @param $priority
- * @return mixed
+ * Generates a new IEvent object
+ *
+ * Make sure to call at least the following methods before sending it to the
+ * app with via the publish() method:
+ * - setApp()
+ * - setType()
+ * - setAffectedUser()
+ * - setSubject()
+ *
+ * @return IEvent
*/
- function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
- foreach($this->getConsumers() as $c) {
- try {
- $c->receive(
- $app,
- $subject,
- $subjectParams,
- $message,
- $messageParams,
- $file,
- $link,
- $affectedUser,
- $type,
- $priority);
- } catch (\Exception $ex) {
- // TODO: log the exception
+ public function generateEvent() {
+ return new Event();
+ }
+
+ /**
+ * Publish an event to the activity consumers
+ *
+ * Make sure to call at least the following methods before sending an Event:
+ * - setApp()
+ * - setType()
+ * - setAffectedUser()
+ * - setSubject()
+ *
+ * @param IEvent $event
+ * @return null
+ * @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) {
+ $event->setAuthor($this->session->getUser()->getUID());
}
}
+
+ if (!$event->getTimestamp()) {
+ $event->setTimestamp(time());
+ }
+
+ foreach ($this->getConsumers() as $c) {
+ $c->receive($event);
+ }
+ }
+
+ /**
+ * @param string $app The app where this event is associated with
+ * @param string $subject A short description of the event
+ * @param array $subjectParams Array with parameters that are filled in the subject
+ * @param string $message A longer description of the event
+ * @param array $messageParams Array with parameters that are filled in the message
+ * @param string $file The file including path where this event is associated with
+ * @param string $link A link where this event is associated with
+ * @param string $affectedUser Recipient of the activity
+ * @param string $type Type of the notification
+ * @param int $priority Priority of the notification
+ * @return null
+ */
+ public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
+ $event = $this->generateEvent();
+ $event->setApp($app)
+ ->setType($type)
+ ->setAffectedUser($affectedUser)
+ ->setSubject($subject, $subjectParams)
+ ->setMessage($message, $messageParams)
+ ->setObject('', 0, $file)
+ ->setLink($link);
+
+ $this->publish($event);
}
/**
@@ -164,7 +218,7 @@ class ActivityManager implements IManager {
*
* @param \Closure $callable
*/
- function registerConsumer(\Closure $callable) {
+ public function registerConsumer(\Closure $callable) {
array_push($this->consumersClosures, $callable);
$this->consumers = [];
}
@@ -178,7 +232,7 @@ class ActivityManager implements IManager {
* @param \Closure $callable
* @return void
*/
- function registerExtension(\Closure $callable) {
+ public function registerExtension(\Closure $callable) {
array_push($this->extensionsClosures, $callable);
$this->extensions = [];
}
@@ -189,7 +243,7 @@ class ActivityManager implements IManager {
* @param string $languageCode
* @return array
*/
- function getNotificationTypes($languageCode) {
+ public function getNotificationTypes($languageCode) {
$notificationTypes = array();
foreach ($this->getExtensions() as $c) {
$result = $c->getNotificationTypes($languageCode);
@@ -205,7 +259,7 @@ class ActivityManager implements IManager {
* @param string $method
* @return array
*/
- function getDefaultTypes($method) {
+ public function getDefaultTypes($method) {
$defaultTypes = array();
foreach ($this->getExtensions() as $c) {
$types = $c->getDefaultTypes($method);
@@ -220,7 +274,7 @@ class ActivityManager implements IManager {
* @param string $type
* @return string
*/
- function getTypeIcon($type) {
+ public function getTypeIcon($type) {
if (isset($this->typeIcons[$type])) {
return $this->typeIcons[$type];
}
@@ -246,7 +300,7 @@ class ActivityManager implements IManager {
* @param string $languageCode
* @return string|false
*/
- function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
+ public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
foreach ($this->getExtensions() as $c) {
$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
if (is_string($translation)) {
@@ -262,7 +316,7 @@ class ActivityManager implements IManager {
* @param string $text
* @return array|false
*/
- function getSpecialParameterList($app, $text) {
+ public function getSpecialParameterList($app, $text) {
if (isset($this->specialParameters[$app][$text])) {
return $this->specialParameters[$app][$text];
}
@@ -287,7 +341,7 @@ class ActivityManager implements IManager {
* @param array $activity
* @return integer|false
*/
- function getGroupParameter($activity) {
+ public function getGroupParameter($activity) {
foreach ($this->getExtensions() as $c) {
$parameter = $c->getGroupParameter($activity);
if ($parameter !== false) {
@@ -301,7 +355,7 @@ class ActivityManager implements IManager {
/**
* @return array
*/
- function getNavigation() {
+ public function getNavigation() {
$entries = array(
'apps' => array(),
'top' => array(),
@@ -321,7 +375,7 @@ class ActivityManager implements IManager {
* @param string $filterValue
* @return boolean
*/
- function isFilterValid($filterValue) {
+ public function isFilterValid($filterValue) {
if (isset($this->validFilters[$filterValue])) {
return $this->validFilters[$filterValue];
}
@@ -342,7 +396,7 @@ class ActivityManager implements IManager {
* @param string $filter
* @return array
*/
- function filterNotificationTypes($types, $filter) {
+ public function filterNotificationTypes($types, $filter) {
if (!$this->isFilterValid($filter)) {
return $types;
}
@@ -360,7 +414,7 @@ class ActivityManager implements IManager {
* @param string $filter
* @return array
*/
- function getQueryForFilter($filter) {
+ public function getQueryForFilter($filter) {
if (!$this->isFilterValid($filter)) {
return [null, null];
}
diff --git a/lib/public/activity/iconsumer.php b/lib/public/activity/iconsumer.php
index a55110ababc..e74884d76c5 100644
--- a/lib/public/activity/iconsumer.php
+++ b/lib/public/activity/iconsumer.php
@@ -37,19 +37,11 @@ namespace OCP\Activity;
*/
interface IConsumer {
/**
- * @param $app
- * @param $subject
- * @param $subjectParams
- * @param $message
- * @param $messageParams
- * @param $file
- * @param $link
- * @param $affectedUser
- * @param $type
- * @param $priority
- * @return mixed
+ * @param IEvent $event
+ * @return null
* @since 6.0.0
+ * @since 8.2.0 Replaced the parameters with an IEvent object
*/
- function receive($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority );
+ public function receive(IEvent $event);
}
diff --git a/lib/public/activity/ievent.php b/lib/public/activity/ievent.php
new file mode 100644
index 00000000000..184c7ae503f
--- /dev/null
+++ b/lib/public/activity/ievent.php
@@ -0,0 +1,200 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Activity/IEvent interface
+ */
+
+// use OCP namespace for all classes that are considered public.
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP\Activity;
+
+/**
+ * Interface IEvent
+ *
+ * @package OCP\Activity
+ * @since 8.2.0
+ */
+interface IEvent {
+ /**
+ * Set the app of the activity
+ *
+ * @param string $app
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setApp($app);
+
+ /**
+ * Set the type of the activity
+ *
+ * @param string $type
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setType($type);
+
+ /**
+ * Set the affected user of the activity
+ *
+ * @param string $user
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setAffectedUser($user);
+
+ /**
+ * Set the author of the activity
+ *
+ * @param string $author
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setAuthor($author);
+
+ /**
+ * Set the author of the activity
+ *
+ * @param int $timestamp
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setTimestamp($timestamp);
+
+ /**
+ * Set the subject of the activity
+ *
+ * @param string $subject
+ * @param array $parameters
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setSubject($subject, array $parameters = []);
+
+ /**
+ * Set the message of the activity
+ *
+ * @param string $message
+ * @param array $parameters
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setMessage($message, array $parameters = []);
+
+ /**
+ * Set the object of the activity
+ *
+ * @param string $objectType
+ * @param int $objectId
+ * @param string $objectName
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setObject($objectType, $objectId, $objectName = '');
+
+ /**
+ * Set the link of the activity
+ *
+ * @param string $link
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function setLink($link);
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getApp();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getType();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getAffectedUser();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getAuthor();
+
+ /**
+ * @return int
+ * @since 8.2.0
+ */
+ public function getTimestamp();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getSubject();
+
+ /**
+ * @return array
+ * @since 8.2.0
+ */
+ public function getSubjectParameters();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getMessage();
+
+ /**
+ * @return array
+ * @since 8.2.0
+ */
+ public function getMessageParameters();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getObjectType();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getObjectId();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getObjectName();
+
+ /**
+ * @return string
+ * @since 8.2.0
+ */
+ public function getLink();
+}
diff --git a/lib/public/activity/imanager.php b/lib/public/activity/imanager.php
index 0f5dccd8ba1..b3a4969fb06 100644
--- a/lib/public/activity/imanager.php
+++ b/lib/public/activity/imanager.php
@@ -38,22 +38,52 @@ namespace OCP\Activity;
* @since 6.0.0
*/
interface IManager {
+ /**
+ * Generates a new IEvent object
+ *
+ * Make sure to call at least the following methods before sending it to the
+ * app with via the publish() method:
+ * - setApp()
+ * - setType()
+ * - setAffectedUser()
+ * - setSubject()
+ *
+ * @return IEvent
+ * @since 8.2.0
+ */
+ public function generateEvent();
+
+ /**
+ * Publish an event to the activity consumers
+ *
+ * Make sure to call at least the following methods before sending an Event:
+ * - setApp()
+ * - setType()
+ * - setAffectedUser()
+ * - setSubject()
+ *
+ * @param IEvent $event
+ * @return null
+ * @since 8.2.0
+ */
+ public function publish(IEvent $event);
/**
- * @param $app
- * @param $subject
- * @param $subjectParams
- * @param $message
- * @param $messageParams
- * @param $file
- * @param $link
- * @param $affectedUser
- * @param $type
- * @param $priority
- * @return mixed
+ * @param string $app The app where this event is associated with
+ * @param string $subject A short description of the event
+ * @param array $subjectParams Array with parameters that are filled in the subject
+ * @param string $message A longer description of the event
+ * @param array $messageParams Array with parameters that are filled in the message
+ * @param string $file The file including path where this event is associated with
+ * @param string $link A link where this event is associated with
+ * @param string $affectedUser Recipient of the activity
+ * @param string $type Type of the notification
+ * @param int $priority Priority of the notification
+ * @return null
* @since 6.0.0
+ * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method
*/
- function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority);
+ public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority);
/**
* In order to improve lazy loading a closure can be registered which will be called in case
@@ -65,7 +95,7 @@ interface IManager {
* @return void
* @since 6.0.0
*/
- function registerConsumer(\Closure $callable);
+ public function registerConsumer(\Closure $callable);
/**
* In order to improve lazy loading a closure can be registered which will be called in case
@@ -77,7 +107,7 @@ interface IManager {
* @return void
* @since 8.0.0
*/
- function registerExtension(\Closure $callable);
+ public function registerExtension(\Closure $callable);
/**
* Will return additional notification types as specified by other apps
@@ -91,21 +121,21 @@ interface IManager {
* @since 8.0.0
* @changed 8.2.0 - Added support to allow limiting notifications to certain methods
*/
- function getNotificationTypes($languageCode);
+ public function getNotificationTypes($languageCode);
/**
* @param string $method
* @return array
* @since 8.0.0
*/
- function getDefaultTypes($method);
+ public function getDefaultTypes($method);
/**
* @param string $type
* @return string
* @since 8.0.0
*/
- function getTypeIcon($type);
+ public function getTypeIcon($type);
/**
* @param string $app
@@ -117,7 +147,7 @@ interface IManager {
* @return string|false
* @since 8.0.0
*/
- function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
+ public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
/**
* @param string $app
@@ -125,27 +155,27 @@ interface IManager {
* @return array|false
* @since 8.0.0
*/
- function getSpecialParameterList($app, $text);
+ public function getSpecialParameterList($app, $text);
/**
* @param array $activity
* @return integer|false
* @since 8.0.0
*/
- function getGroupParameter($activity);
+ public function getGroupParameter($activity);
/**
* @return array
* @since 8.0.0
*/
- function getNavigation();
+ public function getNavigation();
/**
* @param string $filterValue
* @return boolean
* @since 8.0.0
*/
- function isFilterValid($filterValue);
+ public function isFilterValid($filterValue);
/**
* @param array $types
@@ -153,14 +183,14 @@ interface IManager {
* @return array
* @since 8.0.0
*/
- function filterNotificationTypes($types, $filter);
+ public function filterNotificationTypes($types, $filter);
/**
* @param string $filter
* @return array
* @since 8.0.0
*/
- function getQueryForFilter($filter);
+ public function getQueryForFilter($filter);
/**
* Get the user we need to use