diff --git a/lib/activitymanager.php b/lib/activitymanager.php new file mode 100755 index 0000000000000000000000000000000000000000..c1338d873fa827d35a322ce196fdc0dea38a1236 --- /dev/null +++ b/lib/activitymanager.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2013 Thomas Müller thomas.mueller@tmit.eu + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ +namespace OC; + + +use OCP\Activity\IConsumer; + +class ActivityManager implements \OCP\Activity\IManager { + + private $consumers = array(); + + /** + * @param $app + * @param $subject + * @param $message + * @param $file + * @param $link + * @return mixed + */ + function publishActivity($app, $subject, $message, $file, $link) { + foreach($this->consumers as $consumer) { + $c = $consumer(); + if ($c instanceof IConsumer) { + $c->receive($app, $subject, $message, $file, $link); + } + + } + } + + /** + * In order to improve lazy loading a closure can be registered which will be called in case + * activity consumers are actually requested + * + * $callable has to return an instance of OCA\Activity\IConsumer + * + * @param string $key + * @param \Closure $callable + */ + function registerConsumer(\Closure $callable) { + array_push($this->consumers, $callable); + } +} diff --git a/lib/public/activity/imanager.php b/lib/public/activity/imanager.php index da7e9d4b662af19a72881ac7bd9d56a9a4775914..9cba2db7e7f7f927852953cc4083c7b229a22bbb 100644 --- a/lib/public/activity/imanager.php +++ b/lib/public/activity/imanager.php @@ -25,6 +25,14 @@ namespace OCP\Activity; interface IManager { + /** + * @param $app + * @param $subject + * @param $message + * @param $file + * @param $link + * @return mixed + */ function publishActivity($app, $subject, $message, $file, $link); /** diff --git a/lib/public/share.php b/lib/public/share.php index 6c5783f1179014c8897514a5df4c3008d2d25171..ff11aad1a123005bb6a97a401dbef8c2299da4bc 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1400,6 +1400,11 @@ class Share { 'id' => $parent, 'token' => $token )); + + // hook up activity manager + $subject = 'Something has been shared'; + \OC::$server->getActivityManager()->publishActivity('files_sharing', $subject, '', '', ''); + if ($parentFolder === true) { // Return parent folders to preserve file target paths for potential children return $parentFolders; diff --git a/lib/server.php b/lib/server.php index cabb15324ec36169ff0d950211bf95af008ae3a4..b14b2e17d0320f08813f70e313f162d01d9ec215 100644 --- a/lib/server.php +++ b/lib/server.php @@ -114,6 +114,9 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('UserCache', function($c) { return new UserCache(); }); + $this->registerService('ActivityManager', function($c) { + return new ActivityManager(); + }); } /** @@ -252,4 +255,13 @@ class Server extends SimpleContainer implements IServerContainer { function getDatabaseConnection() { return \OC_DB::getConnection(); } + + /** + * Returns the activity manager + * + * @return \OCP\Activity\IManager + */ + function getActivityManager() { + return $this->query('ActivityManager'); + } }