]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move file sharing activities to the new API 2165/head
authorJoas Schilling <coding@schilljs.com>
Wed, 16 Nov 2016 11:09:41 +0000 (12:09 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 16 Nov 2016 15:45:08 +0000 (16:45 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
16 files changed:
apps/federatedfilesharing/lib/Controller/RequestHandlerController.php
apps/files_sharing/appinfo/app.php
apps/files_sharing/appinfo/info.xml
apps/files_sharing/lib/Activity.php [deleted file]
apps/files_sharing/lib/Activity/Filter.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Providers/Downloads.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Providers/Groups.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Providers/PublicLinks.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Providers/RemoteShares.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Providers/Users.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Settings/PublicLinks.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Settings/RemoteShare.php [new file with mode: 0644]
apps/files_sharing/lib/Activity/Settings/Shared.php [new file with mode: 0644]
apps/files_sharing/lib/Controller/ShareController.php
apps/files_sharing/tests/ActivityTest.php [deleted file]
lib/private/Activity/Manager.php

index 9a41962ee3aaeb9cee7cde1ac200ca276ea4047f..750415077a8eeb0be41bd316563c87c6eb8364c5 100644 (file)
@@ -27,7 +27,7 @@
 namespace OCA\FederatedFileSharing\Controller;
 
 use OCA\FederatedFileSharing\DiscoveryManager;
-use OCA\Files_Sharing\Activity;
+use OCA\Files_Sharing\Activity\Providers\RemoteShares;
 use OCA\FederatedFileSharing\AddressHandler;
 use OCA\FederatedFileSharing\FederatedShareProvider;
 use OCA\FederatedFileSharing\Notifications;
@@ -172,9 +172,13 @@ class RequestHandlerController extends OCSController {
                                        $sharedByFederatedId = $ownerFederatedId;
                                }
 
-                               \OC::$server->getActivityManager()->publishActivity(
-                                       Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($ownerFederatedId, trim($name, '/')), '', array(),
-                                       '', '', $shareWith, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_LOW);
+                               $event = \OC::$server->getActivityManager()->generateEvent();
+                               $event->setApp('files_sharing')
+                                       ->setType('remote_share')
+                                       ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
+                                       ->setAffectedUser($shareWith)
+                                       ->setObject('remote_share', (int) $shareId, $name);
+                               \OC::$server->getActivityManager()->publish($event);
 
                                $urlGenerator = \OC::$server->getURLGenerator();
 
@@ -315,11 +319,11 @@ class RequestHandlerController extends OCSController {
                list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId());
 
                $event = \OC::$server->getActivityManager()->generateEvent();
-               $event->setApp(Activity::FILES_SHARING_APP)
-                       ->setType(Activity::TYPE_REMOTE_SHARE)
+               $event->setApp('files_sharing')
+                       ->setType('remote_share')
                        ->setAffectedUser($this->getCorrectUid($share))
-                       ->setSubject(Activity::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), basename($file)])
-                       ->setObject('files', $share->getNode()->getId(), $file)
+                       ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), $file])
+                       ->setObject('files', (int) $share->getNode()->getId(), $file)
                        ->setLink($link);
                \OC::$server->getActivityManager()->publish($event);
        }
@@ -370,11 +374,11 @@ class RequestHandlerController extends OCSController {
                list($file, $link) = $this->getFile($this->getCorrectUid($share), $share->getNode()->getId());
 
                $event = \OC::$server->getActivityManager()->generateEvent();
-               $event->setApp(Activity::FILES_SHARING_APP)
-                       ->setType(Activity::TYPE_REMOTE_SHARE)
+               $event->setApp('files_sharing')
+                       ->setType('remote_share')
                        ->setAffectedUser($this->getCorrectUid($share))
-                       ->setSubject(Activity::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), basename($file)])
-                       ->setObject('files', $share->getNode()->getId(), $file)
+                       ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), $file])
+                       ->setObject('files', (int) $share->getNode()->getId(), $file)
                        ->setLink($link);
                \OC::$server->getActivityManager()->publish($event);
 
@@ -440,9 +444,13 @@ class RequestHandlerController extends OCSController {
                                ->setObject('remote_share', (int) $share['id']);
                        $notificationManager->markProcessed($notification);
 
-                       \OC::$server->getActivityManager()->publishActivity(
-                               Activity::FILES_SHARING_APP, Activity::SUBJECT_REMOTE_SHARE_UNSHARED, array($owner, $path), '', array(),
-                               '', '', $user, Activity::TYPE_REMOTE_SHARE, Activity::PRIORITY_MEDIUM);
+                       $event = \OC::$server->getActivityManager()->generateEvent();
+                       $event->setApp('files_sharing')
+                               ->setType('remote_share')
+                               ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner, $path])
+                               ->setAffectedUser($user)
+                               ->setObject('remote_share', (int) $share['id'], $path);
+                       \OC::$server->getActivityManager()->publish($event);
                }
 
                return new Http\DataResponse();
index 850c2c059771cf5983f30cb8432a5092d373e70e..4fed51b11946844f7e76519a1259f9534023f59c 100644 (file)
@@ -50,14 +50,6 @@ $eventDispatcher->addListener(
 
 // \OCP\Util::addStyle('files_sharing', 'sharetabview');
 
-\OC::$server->getActivityManager()->registerExtension(function() {
-               return new \OCA\Files_Sharing\Activity(
-                       \OC::$server->query('L10NFactory'),
-                       \OC::$server->getURLGenerator(),
-                       \OC::$server->getActivityManager()
-               );
-});
-
 $config = \OC::$server->getConfig();
 if ($config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes') {
 
index 65b8d4af5d1d381a3aa5bb8a5f8e9ff1c7f08535..cff424d223a512a2e904d9f8de35c17bd703a16d 100644 (file)
@@ -23,6 +23,26 @@ Turning the feature off removes shared files and folders on the server for all s
 
        <namespace>Files_Sharing</namespace>
 
+       <activity>
+               <settings>
+                       <setting>OCA\Files_Sharing\Activity\Settings\Shared</setting>
+                       <setting>OCA\Files_Sharing\Activity\Settings\RemoteShare</setting>
+                       <setting>OCA\Files_Sharing\Activity\Settings\PublicLinks</setting>
+               </settings>
+
+               <filters>
+                       <filter>OCA\Files_Sharing\Activity\Filter</filter>
+               </filters>
+
+               <providers>
+                       <provider>OCA\Files_Sharing\Activity\Providers\Downloads</provider>
+                       <provider>OCA\Files_Sharing\Activity\Providers\Groups</provider>
+                       <provider>OCA\Files_Sharing\Activity\Providers\PublicLinks</provider>
+                       <provider>OCA\Files_Sharing\Activity\Providers\RemoteShares</provider>
+                       <provider>OCA\Files_Sharing\Activity\Providers\Users</provider>
+               </providers>
+       </activity>
+
        <background-jobs>
                <job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
                <job>OCA\Files_Sharing\ExpireSharesJob</job>
diff --git a/apps/files_sharing/lib/Activity.php b/apps/files_sharing/lib/Activity.php
deleted file mode 100644 (file)
index 5960437..0000000
+++ /dev/null
@@ -1,494 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @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 OCA\Files_Sharing;
-
-use OCP\Activity\IExtension;
-use OCP\Activity\IManager;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use OCP\L10N\IFactory;
-
-class Activity implements IExtension {
-       const FILES_SHARING_APP = 'files_sharing';
-       /**
-        * Filter with all sharing related activities
-        */
-       const FILTER_SHARES = 'shares';
-
-       /**
-        * Activity types known to this extension
-        */
-       const TYPE_PUBLIC_LINKS = 'public_links';
-       const TYPE_REMOTE_SHARE = 'remote_share';
-       const TYPE_SHARED = 'shared';
-
-       /**
-        * Subject keys for translation of the subjections
-        */
-       const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded';
-       const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded';
-
-       const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted';
-       const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined';
-       const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received';
-       const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared';
-
-       const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
-       const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
-       const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self';
-       const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by';
-
-       const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
-       const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
-       const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
-       const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
-
-       const SUBJECT_SHARED_LINK_SELF = 'shared_link_self';
-       const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by';
-       const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self';
-       const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by';
-       const SUBJECT_LINK_EXPIRED = 'link_expired';
-       const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired';
-
-       const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded';
-       const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded';
-
-       const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
-       const SUBJECT_UNSHARED_BY = 'unshared_by';
-
-       /** @var IFactory */
-       protected $languageFactory;
-
-       /** @var IURLGenerator */
-       protected $URLGenerator;
-
-       /** @var IManager */
-       protected $activityManager;
-
-       /**
-        * @param IFactory $languageFactory
-        * @param IURLGenerator $URLGenerator
-        * @param IManager $activityManager
-        */
-       public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager) {
-               $this->languageFactory = $languageFactory;
-               $this->URLGenerator = $URLGenerator;
-               $this->activityManager = $activityManager;
-       }
-
-       protected function getL10N($languageCode = null) {
-               return $this->languageFactory->get(self::FILES_SHARING_APP, $languageCode);
-       }
-
-       /**
-        * The extension can return an array of additional notification types.
-        * If no additional types are to be added false is to be returned
-        *
-        * @param string $languageCode
-        * @return array|false
-        */
-       public function getNotificationTypes($languageCode) {
-               $l = $this->getL10N($languageCode);
-
-               return array(
-                       self::TYPE_SHARED => (string) $l->t('A file or folder has been <strong>shared</strong>'),
-                       self::TYPE_REMOTE_SHARE => (string) $l->t('A file or folder was shared from <strong>another server</strong>'),
-                       self::TYPE_PUBLIC_LINKS => (string) $l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>'),
-               );
-       }
-
-       /**
-        * For a given method additional types to be displayed in the settings can be returned.
-        * In case no additional types are to be added false is to be returned.
-        *
-        * @param string $method
-        * @return array|false
-        */
-       public function getDefaultTypes($method) {
-               $defaultTypes = [
-                       self::TYPE_SHARED,
-                       self::TYPE_REMOTE_SHARE,
-               ];
-
-               if ($method === self::METHOD_STREAM) {
-                       $defaultTypes[] = self::TYPE_PUBLIC_LINKS;
-               }
-
-               return $defaultTypes;
-       }
-
-       /**
-        * A string naming the css class for the icon to be used can be returned.
-        * If no icon is known for the given type false is to be returned.
-        *
-        * @param string $type
-        * @return string|false
-        */
-       public function getTypeIcon($type) {
-               switch ($type) {
-                       case self::TYPE_SHARED:
-                       case self::TYPE_REMOTE_SHARE:
-                               return 'icon-share';
-                       case self::TYPE_PUBLIC_LINKS:
-                               return 'icon-download';
-               }
-
-               return false;
-       }
-
-       /**
-        * The extension can translate a given message to the requested languages.
-        * If no translation is available false is to be returned.
-        *
-        * @param string $app
-        * @param string $text
-        * @param array $params
-        * @param boolean $stripPath
-        * @param boolean $highlightParams
-        * @param string $languageCode
-        * @return string|false
-        */
-       public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
-               if ($app !== self::FILES_SHARING_APP) {
-                       return false;
-               }
-
-               $l = $this->getL10N($languageCode);
-
-               if ($this->activityManager->isFormattingFilteredObject()) {
-                       $translation = $this->translateShort($text, $l, $params);
-                       if ($translation !== false) {
-                               return $translation;
-                       }
-               }
-
-               return $this->translateLong($text, $l, $params);
-       }
-
-       /**
-        * @param string $text
-        * @param IL10N $l
-        * @param array $params
-        * @return bool|string
-        */
-       protected function translateLong($text, IL10N $l, array $params) {
-
-               switch ($text) {
-                       case self::SUBJECT_REMOTE_SHARE_RECEIVED:
-                               if (sizeof($params) === 2) {
-                                       // New activity ownCloud 8.2+
-                                       return (string) $l->t('You received a new remote share %2$s from %1$s', $params);
-                               }
-                               return (string) $l->t('You received a new remote share from %s', $params);
-                       case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
-                               return (string) $l->t('%1$s accepted remote share %2$s', $params);
-                       case self::SUBJECT_REMOTE_SHARE_DECLINED:
-                               return (string) $l->t('%1$s declined remote share %2$s', $params);
-                       case self::SUBJECT_REMOTE_SHARE_UNSHARED:
-                               return (string) $l->t('%1$s unshared %2$s from you', $params);
-                       case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
-                               return (string) $l->t('Public shared folder %1$s was downloaded', $params);
-                       case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
-                               return (string) $l->t('Public shared file %1$s was downloaded', $params);
-
-                       case self::SUBJECT_SHARED_USER_SELF:
-                               return (string) $l->t('You shared %1$s with %2$s', $params);
-                       case self::SUBJECT_RESHARED_USER_BY:
-                               return (string) $l->t('%2$s shared %1$s with %3$s', $params);
-                       case self::SUBJECT_UNSHARED_USER_SELF:
-                               return (string) $l->t('You removed the share of %2$s for %1$s', $params);
-                       case self::SUBJECT_UNSHARED_USER_BY:
-                               return (string) $l->t('%2$s removed the share of %3$s for %1$s', $params);
-
-                       case self::SUBJECT_SHARED_GROUP_SELF:
-                               return (string) $l->t('You shared %1$s with group %2$s', $params);
-                       case self::SUBJECT_RESHARED_GROUP_BY:
-                               return (string) $l->t('%2$s shared %1$s with group %3$s', $params);
-                       case self::SUBJECT_UNSHARED_GROUP_SELF:
-                               return (string) $l->t('You removed the share of group %2$s for %1$s', $params);
-                       case self::SUBJECT_UNSHARED_GROUP_BY:
-                               return (string) $l->t('%2$s removed the share of group %3$s for %1$s', $params);
-
-                       case self::SUBJECT_RESHARED_LINK_BY:
-                               return (string) $l->t('%2$s shared %1$s via link', $params);
-                       case self::SUBJECT_SHARED_LINK_SELF:
-                               return (string) $l->t('You shared %1$s via link', $params);
-                       case self::SUBJECT_UNSHARED_LINK_SELF:
-                               return (string) $l->t('You removed the public link for %1$s', $params);
-                       case self::SUBJECT_UNSHARED_LINK_BY:
-                               return (string) $l->t('%2$s removed the public link for %1$s', $params);
-                       case self::SUBJECT_LINK_EXPIRED:
-                               return (string) $l->t('Your public link for %1$s expired', $params);
-                       case self::SUBJECT_LINK_BY_EXPIRED:
-                               return (string) $l->t('The public link of %2$s for %1$s expired', $params);
-
-                       case self::SUBJECT_SHARED_WITH_BY:
-                               return (string) $l->t('%2$s shared %1$s with you', $params);
-                       case self::SUBJECT_UNSHARED_BY:
-                               return (string) $l->t('%2$s removed the share for %1$s', $params);
-
-                       case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED:
-                               return (string) $l->t('File %1$s shared by email with %2$s was downloaded', $params);
-                       case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED:
-                               return (string) $l->t('Folder %1$s shared by email with %2$s was downloaded', $params);
-               }
-
-               return false;
-       }
-
-       /**
-        * @param string $text
-        * @param IL10N $l
-        * @param array $params
-        * @return bool|string
-        */
-       protected function translateShort($text, IL10N $l, array $params) {
-               switch ($text) {
-                       case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
-                       case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
-                               return (string) $l->t('Downloaded via public link');
-
-                       case self::SUBJECT_SHARED_USER_SELF:
-                               return (string) $l->t('Shared with %2$s', $params);
-                       case self::SUBJECT_RESHARED_USER_BY:
-                               return (string) $l->t('Shared with %3$s by %2$s', $params);
-                       case self::SUBJECT_UNSHARED_USER_SELF:
-                               return (string) $l->t('Removed share for %2$s', $params);
-                       case self::SUBJECT_UNSHARED_USER_BY:
-                               return (string) $l->t('%2$s removed share for %3$s', $params);
-
-                       case self::SUBJECT_SHARED_GROUP_SELF:
-                               return (string) $l->t('Shared with group %2$s', $params);
-                       case self::SUBJECT_RESHARED_GROUP_BY:
-                               return (string) $l->t('Shared with group %3$s by %2$s', $params);
-                       case self::SUBJECT_UNSHARED_GROUP_SELF:
-                               return (string) $l->t('Removed share of group %2$s', $params);
-                       case self::SUBJECT_UNSHARED_GROUP_BY:
-                               return (string) $l->t('%2$s removed share of group %3$s', $params);
-
-                       case self::SUBJECT_RESHARED_LINK_BY:
-                               return (string) $l->t('Shared via link by %2$s', $params);
-                       case self::SUBJECT_SHARED_LINK_SELF:
-                               return (string) $l->t('Shared via public link');
-                       case self::SUBJECT_UNSHARED_LINK_SELF:
-                               return (string) $l->t('Removed public link');
-                       case self::SUBJECT_UNSHARED_LINK_BY:
-                               return (string) $l->t('%2$s removed public link');
-                       case self::SUBJECT_LINK_EXPIRED:
-                               return (string) $l->t('Public link expired', $params);
-                       case self::SUBJECT_LINK_BY_EXPIRED:
-                               return (string) $l->t('Public link of %2$s expired', $params);
-
-                       case self::SUBJECT_SHARED_WITH_BY:
-                               return (string) $l->t('Shared by %2$s', $params);
-
-                       case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED:
-                       case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED:
-                               return (string) $l->t('Downloaded by %2$s', $params);
-
-                       default:
-                               return false;
-               }
-       }
-
-       /**
-        * The extension can define the type of parameters for translation
-        *
-        * Currently known types are:
-        * * file               => will strip away the path of the file and add a tooltip with it
-        * * username   => will add the avatar of the user
-        * * email          => will add a mailto link
-        *
-        * @param string $app
-        * @param string $text
-        * @return array|false
-        */
-       public function getSpecialParameterList($app, $text) {
-               if ($app === self::FILES_SHARING_APP) {
-                       switch ($text) {
-                               case self::SUBJECT_REMOTE_SHARE_RECEIVED:
-                               case self::SUBJECT_REMOTE_SHARE_UNSHARED:
-                                       return array(
-                                               0 => 'federated_cloud_id',
-                                               //1 => 'file', in theory its a file, but it does not exist yet/anymore
-                                       );
-                               case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
-                               case self::SUBJECT_REMOTE_SHARE_DECLINED:
-                                       return array(
-                                               0 => 'federated_cloud_id',
-                                               1 => 'file',
-                                       );
-                               case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED:
-                               case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED:
-                                       return array(
-                                               0 => 'file',
-                                       );
-                               case self::SUBJECT_SHARED_LINK_SELF:
-                               case self::SUBJECT_UNSHARED_LINK_SELF:
-                               case self::SUBJECT_LINK_EXPIRED:
-                                       return [0 => 'file'];
-                               case self::SUBJECT_RESHARED_LINK_BY:
-                                       return [
-                                               0 => 'file',
-                                               1 => 'username',
-                                               2 => '',
-                                       ];
-                               case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED:
-                               case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED:
-                                       return array(
-                                               0 => 'file',
-                                               1 => 'email',
-                                       );
-
-                               case self::SUBJECT_SHARED_USER_SELF:
-                               case self::SUBJECT_SHARED_WITH_BY:
-                               case self::SUBJECT_UNSHARED_BY:
-                               case self::SUBJECT_UNSHARED_LINK_BY:
-                               case self::SUBJECT_LINK_BY_EXPIRED:
-                               case self::SUBJECT_UNSHARED_USER_SELF:
-                                       return [0 => 'file', 1 => 'username'];
-                               case self::SUBJECT_RESHARED_USER_BY:
-                               case self::SUBJECT_UNSHARED_USER_BY:
-                                       return [
-                                               0 => 'file',
-                                               1 => 'username',
-                                               2 => 'username',
-                                       ];
-
-                               case self::SUBJECT_SHARED_GROUP_SELF:
-                               case self::SUBJECT_UNSHARED_GROUP_SELF:
-                                       return [
-                                               0 => 'file',
-                                               1 => 'group',
-                                       ];
-
-                               case self::SUBJECT_RESHARED_GROUP_BY:
-                               case self::SUBJECT_UNSHARED_GROUP_BY:
-                                       return [
-                                               0 => 'file',
-                                               1 => 'username',
-                                               2 => 'group',
-                                       ];
-                       }
-               }
-
-               return false;
-       }
-
-       /**
-        * The extension can define the parameter grouping by returning the index as integer.
-        * In case no grouping is required false is to be returned.
-        *
-        * @param array $activity
-        * @return integer|false
-        */
-       public function getGroupParameter($activity) {
-               if ($activity['app'] === self::FILES_SHARING_APP) {
-                       switch ($activity['subject']) {
-                               case self::SUBJECT_SHARED_LINK_SELF:
-                               case self::SUBJECT_UNSHARED_LINK_SELF:
-                               case self::SUBJECT_LINK_EXPIRED:
-                               case self::SUBJECT_SHARED_WITH_BY:
-                               case self::SUBJECT_UNSHARED_BY:
-                                       // Group by file name
-                                       return 0;
-                               case self::SUBJECT_SHARED_USER_SELF:
-                               case self::SUBJECT_SHARED_GROUP_SELF:
-                                       // Group by user/group
-                                       return 1;
-                       }
-               }
-
-               return false;
-       }
-
-       /**
-        * The extension can define additional navigation entries. The array returned has to contain two keys 'top'
-        * and 'apps' which hold arrays with the relevant entries.
-        * If no further entries are to be added false is no be returned.
-        *
-        * @return array|false
-        */
-       public function getNavigation() {
-               $l = $this->getL10N();
-               return [
-                       'apps' => [],
-                       'top' => [
-                               self::FILTER_SHARES => [
-                                       'id' => self::FILTER_SHARES,
-                                       'icon' => 'icon-share',
-                                       'name' => (string) $l->t('File shares'),
-                                       'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_SHARES]),
-                               ],
-                       ],
-               ];
-       }
-
-       /**
-        * The extension can check if a custom filter (given by a query string like filter=abc) is valid or not.
-        *
-        * @param string $filterValue
-        * @return boolean
-        */
-       public function isFilterValid($filterValue) {
-               return $filterValue === self::FILTER_SHARES;
-       }
-
-       /**
-        * The extension can filter the types based on the filter if required.
-        * In case no filter is to be applied false is to be returned unchanged.
-        *
-        * @param array $types
-        * @param string $filter
-        * @return array|false
-        */
-       public function filterNotificationTypes($types, $filter) {
-               switch ($filter) {
-                       case self::FILTER_SHARES:
-                               return array_intersect([self::TYPE_SHARED, self::TYPE_REMOTE_SHARE], $types);
-               }
-               return false;
-       }
-
-       /**
-        * For a given filter the extension can specify the sql query conditions including parameters for that query.
-        * In case the extension does not know the filter false is to be returned.
-        * The query condition and the parameters are to be returned as array with two elements.
-        * E.g. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
-        *
-        * @param string $filter
-        * @return array|false
-        */
-       public function getQueryForFilter($filter) {
-               if ($filter === self::FILTER_SHARES) {
-                       return [
-                               '`app` = ?',
-                               [self::FILES_SHARING_APP,],
-                       ];
-               }
-               return false;
-       }
-
-}
diff --git a/apps/files_sharing/lib/Activity/Filter.php b/apps/files_sharing/lib/Activity/Filter.php
new file mode 100644 (file)
index 0000000..66ba7f1
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity;
+
+
+use OCP\Activity\IFilter;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+
+class Filter implements IFilter {
+       const TYPE_REMOTE_SHARE = 'remote_share';
+       const TYPE_SHARED = 'shared';
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       public function __construct(IL10N $l, IURLGenerator $url) {
+               $this->l = $l;
+               $this->url = $url;
+       }
+
+       /**
+        * @return string Lowercase a-z only identifier
+        * @since 11.0.0
+        */
+       public function getIdentifier() {
+               return 'files_sharing';
+       }
+
+       /**
+        * @return string A translated string
+        * @since 11.0.0
+        */
+       public function getName() {
+               return $this->l->t('File shares');
+       }
+
+       /**
+        * @return int
+        * @since 11.0.0
+        */
+       public function getPriority() {
+               return 31;
+       }
+
+       /**
+        * @return string Full URL to an icon, empty string when none is given
+        * @since 11.0.0
+        */
+       public function getIcon() {
+               return $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'));
+       }
+
+       /**
+        * @param string[] $types
+        * @return string[] An array of allowed apps from which activities should be displayed
+        * @since 11.0.0
+        */
+       public function filterTypes(array $types) {
+               return array_intersect([
+                       self::TYPE_SHARED,
+                       self::TYPE_REMOTE_SHARE
+               ], $types);
+       }
+
+       /**
+        * @return string[] An array of allowed apps from which activities should be displayed
+        * @since 11.0.0
+        */
+       public function allowedApps() {
+               return ['files_sharing'];
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php
new file mode 100644 (file)
index 0000000..84ef589
--- /dev/null
@@ -0,0 +1,181 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Providers;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+
+class Downloads implements IProvider {
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       /** @var IManager */
+       protected $activityManager;
+
+       const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded';
+       const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded';
+
+       const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded';
+       const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded';
+
+       /**
+        * @param IL10N $l
+        * @param IURLGenerator $url
+        * @param IManager $activityManager
+        */
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager) {
+               $this->l = $l;
+               $this->url = $url;
+               $this->activityManager = $activityManager;
+       }
+
+       /**
+        * @param IEvent $event
+        * @param IEvent|null $previousEvent
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parse(IEvent $event, IEvent $previousEvent = null) {
+               if ($event->getApp() !== 'files_sharing') {
+                       throw new \InvalidArgumentException();
+               }
+
+               if ($this->activityManager->isFormattingFilteredObject()) {
+                       try {
+                               return $this->parseShortVersion($event);
+                       } catch (\InvalidArgumentException $e) {
+                               // Ignore and simply use the long version...
+                       }
+               }
+
+               return $this->parseLongVersion($event);
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseShortVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED ||
+                       $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) {
+                       $event->setParsedSubject($this->l->t('Downloaded via public link'))
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED ||
+                       $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) {
+                       $event->setParsedSubject($this->l->t('Downloaded by %1$s', $parsedParameters['email']['name']))
+                               ->setRichSubject($this->l->t('Downloaded by {email}'), [
+                                       'email' => $parsedParameters['email'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg')));
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseLongVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED ||
+                       $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) {
+                       $event->setParsedSubject($this->l->t('%1$s downloaded via public link', [
+                                       $parsedParameters['file']['path'],
+                               ]))
+                               ->setRichSubject($this->l->t('{file} downloaded via public link'), [
+                                       'file' => $parsedParameters['file'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED ||
+                       $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) {
+                       $event->setParsedSubject($this->l->t('%1$s downloaded %2$s', [
+                                       $parsedParameters['email']['name'],
+                                       $parsedParameters['file']['path'],
+                               ]))
+                               ->setRichSubject($this->l->t('{email} downloaded {file}'), [
+                                       'email' => $parsedParameters['email'],
+                                       'file' => $parsedParameters['file'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg')));
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return array
+        */
+       protected function getParsedParameters(IEvent $event) {
+               $subject = $event->getSubject();
+               $parameters = $event->getSubjectParameters();
+
+               switch ($subject) {
+                       case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED:
+                       case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED:
+                               return [
+                                       'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]),
+                                       'email' => [
+                                               'type' => 'email',
+                                               'id' => $parameters[1],
+                                               'name' => $parameters[1],
+                                       ],
+                               ];
+               }
+               return [];
+       }
+
+       /**
+        * @param int $id
+        * @param string $path
+        * @return array
+        */
+       protected function generateFileParameter($id, $path) {
+               return [
+                       'type' => 'file',
+                       'id' => $id,
+                       'name' => basename($path),
+                       'path' => $path,
+                       'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
+               ];
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Providers/Groups.php b/apps/files_sharing/lib/Activity/Providers/Groups.php
new file mode 100644 (file)
index 0000000..50b3df7
--- /dev/null
@@ -0,0 +1,261 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Providers;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class Groups implements IProvider {
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       /** @var IManager */
+       protected $activityManager;
+
+       /** @var IUserManager */
+       protected $userManager;
+
+       /** @var array */
+       protected $displayNames = [];
+
+       const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
+       const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
+       const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
+       const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
+
+
+       /**
+        * @param IL10N $l
+        * @param IURLGenerator $url
+        * @param IManager $activityManager
+        * @param IUserManager $userManager
+        */
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
+               $this->l = $l;
+               $this->url = $url;
+               $this->activityManager = $activityManager;
+               $this->userManager = $userManager;
+       }
+
+       /**
+        * @param IEvent $event
+        * @param IEvent|null $previousEvent
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parse(IEvent $event, IEvent $previousEvent = null) {
+               if ($event->getApp() !== 'files_sharing') {
+                       throw new \InvalidArgumentException();
+               }
+
+               if ($this->activityManager->isFormattingFilteredObject()) {
+                       try {
+                               return $this->parseShortVersion($event);
+                       } catch (\InvalidArgumentException $e) {
+                               // Ignore and simply use the long version...
+                       }
+               }
+
+               return $this->parseLongVersion($event);
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseShortVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) {
+                       $event->setParsedSubject($this->l->t('Shared with group %1$s', [$parsedParameters['group']['name']]))
+                               ->setRichSubject($this->l->t('Shared with group {group}'), [
+                                       'group' => $parsedParameters['group'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) {
+                       $event->setParsedSubject($this->l->t('Removed share for group %1$s', [$parsedParameters['group']['name']]))
+                               ->setRichSubject($this->l->t('Removed share for group {group}'), [
+                                       'group' => $parsedParameters['group'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s shared with %1$s by', [
+                                       $parsedParameters['group']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared with {group}'), [
+                                       'group' => $parsedParameters['group'],
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s removed share for %1$s', [
+                                       $parsedParameters['group']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed share for group {group}'), [
+                                       'group' => $parsedParameters['group'],
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseLongVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) {
+                       $event->setParsedSubject($this->l->t('You shared %1$s with group %2$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['group']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('You shared {file} with group {group}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) {
+                       $event->setParsedSubject($this->l->t('You removed group %2$s from %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['group']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('You removed group {group} from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) {
+                       $event->setParsedSubject($this->l->t('%3$s shared %1$s with group %2$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['group']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared {file} with group {group}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
+                       $event->setParsedSubject($this->l->t('%3$s removed group %2$s from %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['group']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed group {group} from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       protected function getParsedParameters(IEvent $event) {
+               $subject = $event->getSubject();
+               $parameters = $event->getSubjectParameters();
+
+               switch ($subject) {
+                       case self::SUBJECT_RESHARED_GROUP_BY:
+                       case self::SUBJECT_UNSHARED_GROUP_BY:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'group' => [
+                                               'type' => 'group',
+                                               'id' => $parameters[2],
+                                               'name' => $parameters[2],
+                                       ],
+                                       'actor' => $this->generateUserParameter($parameters[1]),
+                               ];
+                       case self::SUBJECT_SHARED_GROUP_SELF:
+                       case self::SUBJECT_UNSHARED_GROUP_SELF:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'group' => [
+                                               'type' => 'group',
+                                               'id' => $parameters[1],
+                                               'name' => $parameters[1],
+                                       ],
+                               ];
+               }
+               return [];
+       }
+
+       /**
+        * @param int $id
+        * @param string $path
+        * @return array
+        */
+       protected function generateFileParameter($id, $path) {
+               return [
+                       'type' => 'file',
+                       'id' => $id,
+                       'name' => basename($path),
+                       'path' => $path,
+                       'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return array
+        */
+       protected function generateUserParameter($uid) {
+               if (!isset($this->displayNames[$uid])) {
+                       $this->displayNames[$uid] = $this->getDisplayName($uid);
+               }
+
+               return [
+                       'type' => 'user',
+                       'id' => $uid,
+                       'name' => $this->displayNames[$uid],
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return string
+        */
+       protected function getDisplayName($uid) {
+               $user = $this->userManager->get($uid);
+               if ($user instanceof IUser) {
+                       return $user->getDisplayName();
+               } else {
+                       return $uid;
+               }
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Providers/PublicLinks.php b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php
new file mode 100644 (file)
index 0000000..1b15520
--- /dev/null
@@ -0,0 +1,268 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Providers;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class PublicLinks implements IProvider {
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       /** @var IManager */
+       protected $activityManager;
+
+       /** @var IUserManager */
+       protected $userManager;
+
+       /** @var array */
+       protected $displayNames = [];
+
+       const SUBJECT_SHARED_LINK_SELF = 'shared_link_self';
+       const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by';
+       const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self';
+       const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by';
+       const SUBJECT_LINK_EXPIRED = 'link_expired';
+       const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired';
+
+
+       /**
+        * @param IL10N $l
+        * @param IURLGenerator $url
+        * @param IManager $activityManager
+        * @param IUserManager $userManager
+        */
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
+               $this->l = $l;
+               $this->url = $url;
+               $this->activityManager = $activityManager;
+               $this->userManager = $userManager;
+       }
+
+       /**
+        * @param IEvent $event
+        * @param IEvent|null $previousEvent
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parse(IEvent $event, IEvent $previousEvent = null) {
+               if ($event->getApp() !== 'files_sharing') {
+                       throw new \InvalidArgumentException();
+               }
+
+               if ($this->activityManager->isFormattingFilteredObject()) {
+                       try {
+                               return $this->parseShortVersion($event);
+                       } catch (\InvalidArgumentException $e) {
+                               // Ignore and simply use the long version...
+                       }
+               }
+
+               return $this->parseLongVersion($event);
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseShortVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
+                       $event->setParsedSubject($this->l->t('Shared as public link'))
+                               ->setRichSubject($this->l->t('Shared as public link'))
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
+                       $event->setParsedSubject($this->l->t('Removed public link'))
+                               ->setRichSubject($this->l->t('Removed public link'))
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+//             } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
+//                     $event->setParsedSubject($this->l->t('Public link expired'))
+//                             ->setRichSubject($this->l->t('Public link expired'))
+//                             ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
+                       $event->setParsedSubject($this->l->t('%1$s shared as public link', [
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared as public link'), [
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
+                       $event->setParsedSubject($this->l->t('%1$s removed public link', [
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed public link'), [
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+//             } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
+//                     $event->setParsedSubject($this->l->t('Public link of %1$s expired', [
+//                                     $parsedParameters['actor']['name'],
+//                             ]))
+//                             ->setRichSubject($this->l->t('Public link of {actor} expired',[
+//                                     'actor' => $parsedParameters['actor'],
+//                             ]))
+//                             ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseLongVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) {
+                       $event->setParsedSubject($this->l->t('You shared %1$s as public link', [
+                                       $parsedParameters['file']['path'],
+                               ]))
+                               ->setRichSubject($this->l->t('You shared {file} as public link'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) {
+                       $event->setParsedSubject($this->l->t('You removed public link for %1$s', [
+                                       $parsedParameters['file']['path'],
+                               ]))
+                               ->setRichSubject($this->l->t('You removed public link for {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+//             } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) {
+//                     $event->setParsedSubject($this->l->t('Public link expired'))
+//                             ->setRichSubject($this->l->t('Public link expired'))
+//                             ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s shared %1$s as public link', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared {file} as public link'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) {
+                       $event->setParsedSubject($this->l->t('%1$s removed public link for %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed public link for {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+//             } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) {
+//                     $event->setParsedSubject($this->l->t('Public link of %1$s expired', [
+//                                     $parsedParameters['actor']['name'],
+//                             ]))
+//                             ->setRichSubject($this->l->t('Public link of {actor} expired',[
+//                                     'actor' => $parsedParameters['actor'],
+//                             ]))
+//                             ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       protected function getParsedParameters(IEvent $event) {
+               $subject = $event->getSubject();
+               $parameters = $event->getSubjectParameters();
+
+               switch ($subject) {
+                       case self::SUBJECT_SHARED_LINK_SELF:
+                       case self::SUBJECT_UNSHARED_LINK_SELF:
+                       case self::SUBJECT_LINK_EXPIRED:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                               ];
+                       case self::SUBJECT_RESHARED_LINK_BY:
+                       case self::SUBJECT_UNSHARED_LINK_BY:
+                       case self::SUBJECT_LINK_BY_EXPIRED:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'actor' => $this->generateUserParameter($parameters[1]),
+                               ];
+               }
+               return [];
+       }
+
+       /**
+        * @param int $id
+        * @param string $path
+        * @return array
+        */
+       protected function generateFileParameter($id, $path) {
+               return [
+                       'type' => 'file',
+                       'id' => $id,
+                       'name' => basename($path),
+                       'path' => $path,
+                       'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return array
+        */
+       protected function generateUserParameter($uid) {
+               if (!isset($this->displayNames[$uid])) {
+                       $this->displayNames[$uid] = $this->getDisplayName($uid);
+               }
+
+               return [
+                       'type' => 'user',
+                       'id' => $uid,
+                       'name' => $this->displayNames[$uid],
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return string
+        */
+       protected function getDisplayName($uid) {
+               $user = $this->userManager->get($uid);
+               if ($user instanceof IUser) {
+                       return $user->getDisplayName();
+               } else {
+                       return $uid;
+               }
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Providers/RemoteShares.php b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php
new file mode 100644 (file)
index 0000000..c7906b8
--- /dev/null
@@ -0,0 +1,208 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Providers;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class RemoteShares implements IProvider {
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       /** @var IManager */
+       protected $activityManager;
+
+       const SUBJECT_REMOTE_SHARE_ACCEPTED = 'remote_share_accepted';
+       const SUBJECT_REMOTE_SHARE_DECLINED = 'remote_share_declined';
+       const SUBJECT_REMOTE_SHARE_RECEIVED = 'remote_share_received';
+       const SUBJECT_REMOTE_SHARE_UNSHARED = 'remote_share_unshared';
+
+       /**
+        * @param IL10N $l
+        * @param IURLGenerator $url
+        * @param IManager $activityManager
+        */
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager) {
+               $this->l = $l;
+               $this->url = $url;
+               $this->activityManager = $activityManager;
+       }
+
+       /**
+        * @param IEvent $event
+        * @param IEvent|null $previousEvent
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parse(IEvent $event, IEvent $previousEvent = null) {
+               if ($event->getApp() !== 'files_sharing') {
+                       throw new \InvalidArgumentException();
+               }
+
+               if ($this->activityManager->isFormattingFilteredObject()) {
+                       try {
+                               return $this->parseShortVersion($event);
+                       } catch (\InvalidArgumentException $e) {
+                               // Ignore and simply use the long version...
+                       }
+               }
+
+               return $this->parseLongVersion($event);
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseShortVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) {
+                       $event->setParsedSubject($this->l->t('%1$s accepted the remote share', [
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{user} accepted the remote share'), [
+                                       'user' => $parsedParameters['user']
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) {
+                       $event->setParsedSubject($this->l->t('%1$s declined the remote share', [
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{user} declined the remote share'), [
+                                       'user' => $parsedParameters['user']
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseLongVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_RECEIVED) {
+                               $event->setParsedSubject($this->l->t('You received a new remote share %1$s from %2$s', [
+                                       $parsedParameters['file']['name'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('You received a new remote share {file} from {user}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_ACCEPTED) {
+                               $event->setParsedSubject($this->l->t('%2$s accepted the remote share of %1$s', [
+                                       $parsedParameters['file']['name'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{user} accepted the remote share of {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_DECLINED) {
+                               $event->setParsedSubject($this->l->t('%2$s declined the remote share of %1$s', [
+                                       $parsedParameters['file']['name'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{user} declined the remote share of {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_REMOTE_SHARE_UNSHARED) {
+                               $event->setParsedSubject($this->l->t('%2$s unshared %1$s from you', [
+                                       $parsedParameters['file']['name'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{user} unshared {file} from you'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       protected function getParsedParameters(IEvent $event) {
+               $subject = $event->getSubject();
+               $parameters = $event->getSubjectParameters();
+
+               $remoteUser = explode('@', $parameters[0], 2);
+               switch ($subject) {
+                       case self::SUBJECT_REMOTE_SHARE_RECEIVED:
+                       case self::SUBJECT_REMOTE_SHARE_UNSHARED:
+                               return [
+                                       'file' => [
+                                               'type' => 'pending-federated-share',
+                                               'id' => $parameters[1],
+                                               'name' => $parameters[1],
+                                       ],
+                                       'user' => [
+                                               'type' => 'user',
+                                               'id' => $remoteUser[0],
+                                               'name' => $parameters[0],// Todo display name from contacts
+                                               'server' => $remoteUser[1],
+                                       ],
+                               ];
+                       case self::SUBJECT_REMOTE_SHARE_ACCEPTED:
+                       case self::SUBJECT_REMOTE_SHARE_DECLINED:
+                               return [
+                                       'file' => $this->generateFileParameter($event->getObjectId(), $event->getObjectName()),
+                                       'user' => [
+                                               'type' => 'user',
+                                               'id' => $remoteUser[0],
+                                               'name' => $parameters[0],// Todo display name from contacts
+                                               'server' => $remoteUser[1],
+                                       ],
+                               ];
+               }
+               return [];
+       }
+
+       /**
+        * @param int $id
+        * @param string $path
+        * @return array
+        */
+       protected function generateFileParameter($id, $path) {
+               return [
+                       'type' => 'file',
+                       'id' => $id,
+                       'name' => basename($path),
+                       'path' => $path,
+                       'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
+               ];
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Providers/Users.php b/apps/files_sharing/lib/Activity/Providers/Users.php
new file mode 100644 (file)
index 0000000..915dbcf
--- /dev/null
@@ -0,0 +1,289 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Providers;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class Users implements IProvider {
+
+       /** @var IL10N */
+       protected $l;
+
+       /** @var IURLGenerator */
+       protected $url;
+
+       /** @var IManager */
+       protected $activityManager;
+
+       /** @var IUserManager */
+       protected $userManager;
+
+       /** @var array */
+       protected $displayNames = [];
+
+       const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
+       const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
+       const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self';
+       const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by';
+
+       const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
+       const SUBJECT_UNSHARED_BY = 'unshared_by';
+
+       /**
+        * @param IL10N $l
+        * @param IURLGenerator $url
+        * @param IManager $activityManager
+        * @param IUserManager $userManager
+        */
+       public function __construct(IL10N $l, IURLGenerator $url, IManager $activityManager, IUserManager $userManager) {
+               $this->l = $l;
+               $this->url = $url;
+               $this->activityManager = $activityManager;
+               $this->userManager = $userManager;
+       }
+
+       /**
+        * @param IEvent $event
+        * @param IEvent|null $previousEvent
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parse(IEvent $event, IEvent $previousEvent = null) {
+               if ($event->getApp() !== 'files_sharing') {
+                       throw new \InvalidArgumentException();
+               }
+
+               if ($this->activityManager->isFormattingFilteredObject()) {
+                       try {
+                               return $this->parseShortVersion($event);
+                       } catch (\InvalidArgumentException $e) {
+                               // Ignore and simply use the long version...
+                       }
+               }
+
+               return $this->parseLongVersion($event);
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseShortVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
+                       $event->setParsedSubject($this->l->t('Shared with %1$s', [$parsedParameters['user']['name']]))
+                               ->setRichSubject($this->l->t('Shared with {user}'), [
+                                       'user' => $parsedParameters['user'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
+                       $event->setParsedSubject($this->l->t('Removed share for %1$s', [$parsedParameters['user']['name']]))
+                               ->setRichSubject($this->l->t('Removed share for {user}'), [
+                                       'user' => $parsedParameters['user'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s shared with %1$s by', [
+                                       $parsedParameters['user']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared with {user}'), [
+                                       'user' => $parsedParameters['user'],
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s removed share for %1$s', [
+                                       $parsedParameters['user']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed share for {user}'), [
+                                       'user' => $parsedParameters['user'],
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
+                       $event->setParsedSubject($this->l->t('Shared by %1$s', [$parsedParameters['actor']['name']]))
+                               ->setRichSubject($this->l->t('Shared by {actor}'), [
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
+                       $event->setParsedSubject($this->l->t('%1$s removed share', [$parsedParameters['actor']['name']]))
+                               ->setRichSubject($this->l->t('{actor} removed share'), [
+                                       'actor' => $parsedParameters['actor'],
+                               ])
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       /**
+        * @param IEvent $event
+        * @return IEvent
+        * @throws \InvalidArgumentException
+        * @since 11.0.0
+        */
+       public function parseLongVersion(IEvent $event) {
+               $parsedParameters = $this->getParsedParameters($event);
+
+               if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
+                               $event->setParsedSubject($this->l->t('You shared %1$s with %2$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('You shared {file} with {user}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
+                       $event->setParsedSubject($this->l->t('You removed %2$s from %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['user']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('You removed {user} from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
+                       $event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['user']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed {user} from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
+                       $event->setParsedSubject($this->l->t('%3$s removed %2$s from %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['user']['name'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed {user} from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s shared %1$s with you', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} shared {file} with you'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+               } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
+                       $event->setParsedSubject($this->l->t('%2$s removed you from %1$s', [
+                                       $parsedParameters['file']['path'],
+                                       $parsedParameters['actor']['name'],
+                               ]))
+                               ->setRichSubject($this->l->t('{actor} removed you from {file}'), $parsedParameters)
+                               ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+               } else {
+                       throw new \InvalidArgumentException();
+               }
+
+               return $event;
+       }
+
+       protected function getParsedParameters(IEvent $event) {
+               $subject = $event->getSubject();
+               $parameters = $event->getSubjectParameters();
+
+               switch ($subject) {
+                       case self::SUBJECT_SHARED_USER_SELF:
+                       case self::SUBJECT_UNSHARED_USER_SELF:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'user' => $this->generateUserParameter($parameters[1]),
+                               ];
+                       case self::SUBJECT_SHARED_WITH_BY:
+                       case self::SUBJECT_UNSHARED_BY:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'actor' => $this->generateUserParameter($parameters[1]),
+                               ];
+                       case self::SUBJECT_RESHARED_USER_BY:
+                       case self::SUBJECT_UNSHARED_USER_BY:
+                               $id = key($parameters[0]);
+                               return [
+                                       'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+                                       'user' => $this->generateUserParameter($parameters[2]),
+                                       'actor' => $this->generateUserParameter($parameters[1]),
+                               ];
+               }
+               return [];
+       }
+
+       /**
+        * @param int $id
+        * @param string $path
+        * @return array
+        */
+       protected function generateFileParameter($id, $path) {
+               return [
+                       'type' => 'file',
+                       'id' => $id,
+                       'name' => basename($path),
+                       'path' => $path,
+                       'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]),
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return array
+        */
+       protected function generateUserParameter($uid) {
+               if (!isset($this->displayNames[$uid])) {
+                       $this->displayNames[$uid] = $this->getDisplayName($uid);
+               }
+
+               return [
+                       'type' => 'user',
+                       'id' => $uid,
+                       'name' => $this->displayNames[$uid],
+               ];
+       }
+
+       /**
+        * @param string $uid
+        * @return string
+        */
+       protected function getDisplayName($uid) {
+               $user = $this->userManager->get($uid);
+               if ($user instanceof IUser) {
+                       return $user->getDisplayName();
+               } else {
+                       return $uid;
+               }
+       }
+}
diff --git a/apps/files_sharing/lib/Activity/Settings/PublicLinks.php b/apps/files_sharing/lib/Activity/Settings/PublicLinks.php
new file mode 100644 (file)
index 0000000..04fd5e2
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Settings;
+
+
+use OCP\Activity\ISetting;
+use OCP\IL10N;
+
+class PublicLinks implements ISetting {
+
+       /** @var IL10N */
+       protected $l;
+
+       /**
+        * @param IL10N $l
+        */
+       public function __construct(IL10N $l) {
+               $this->l = $l;
+       }
+
+       /**
+        * @return string Lowercase a-z and underscore only identifier
+        * @since 11.0.0
+        */
+       public function getIdentifier() {
+               return 'public_links';
+       }
+
+       /**
+        * @return string A translated string
+        * @since 11.0.0
+        */
+       public function getName() {
+               return $this->l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>');
+       }
+
+       /**
+        * @return int whether the filter should be rather on the top or bottom of
+        * the admin section. The filters are arranged in ascending order of the
+        * priority values. It is required to return a value between 0 and 100.
+        * @since 11.0.0
+        */
+       public function getPriority() {
+               return 20;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function canChangeStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the mail
+        * @since 11.0.0
+        */
+       public function canChangeMail() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledMail() {
+               return false;
+       }
+}
+
diff --git a/apps/files_sharing/lib/Activity/Settings/RemoteShare.php b/apps/files_sharing/lib/Activity/Settings/RemoteShare.php
new file mode 100644 (file)
index 0000000..ef50699
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Settings;
+
+
+use OCP\Activity\ISetting;
+use OCP\IL10N;
+
+class RemoteShare implements ISetting {
+
+       /** @var IL10N */
+       protected $l;
+
+       /**
+        * @param IL10N $l
+        */
+       public function __construct(IL10N $l) {
+               $this->l = $l;
+       }
+
+       /**
+        * @return string Lowercase a-z and underscore only identifier
+        * @since 11.0.0
+        */
+       public function getIdentifier() {
+               return 'remote_share';
+       }
+
+       /**
+        * @return string A translated string
+        * @since 11.0.0
+        */
+       public function getName() {
+               return $this->l->t('A file or folder was shared from <strong>another server</strong>');
+       }
+
+       /**
+        * @return int whether the filter should be rather on the top or bottom of
+        * the admin section. The filters are arranged in ascending order of the
+        * priority values. It is required to return a value between 0 and 100.
+        * @since 11.0.0
+        */
+       public function getPriority() {
+               return 11;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function canChangeStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the mail
+        * @since 11.0.0
+        */
+       public function canChangeMail() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledMail() {
+               return true;
+       }
+}
+
diff --git a/apps/files_sharing/lib/Activity/Settings/Shared.php b/apps/files_sharing/lib/Activity/Settings/Shared.php
new file mode 100644 (file)
index 0000000..847469d
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Activity\Settings;
+
+
+use OCP\Activity\ISetting;
+use OCP\IL10N;
+
+class Shared implements ISetting {
+
+       /** @var IL10N */
+       protected $l;
+
+       /**
+        * @param IL10N $l
+        */
+       public function __construct(IL10N $l) {
+               $this->l = $l;
+       }
+
+       /**
+        * @return string Lowercase a-z and underscore only identifier
+        * @since 11.0.0
+        */
+       public function getIdentifier() {
+               return 'shared';
+       }
+
+       /**
+        * @return string A translated string
+        * @since 11.0.0
+        */
+       public function getName() {
+               return $this->l->t('A file or folder has been <strong>shared</strong>');
+       }
+
+       /**
+        * @return int whether the filter should be rather on the top or bottom of
+        * the admin section. The filters are arranged in ascending order of the
+        * priority values. It is required to return a value between 0 and 100.
+        * @since 11.0.0
+        */
+       public function getPriority() {
+               return 10;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function canChangeStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledStream() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the mail
+        * @since 11.0.0
+        */
+       public function canChangeMail() {
+               return true;
+       }
+
+       /**
+        * @return bool True when the option can be changed for the stream
+        * @since 11.0.0
+        */
+       public function isDefaultEnabledMail() {
+               return true;
+       }
+}
+
index 910cbbdf39724820e582eb0ac3cc69bb1f81308e..c02f0396868181a5a448929868d3a689fe21cf20 100644 (file)
@@ -51,7 +51,7 @@ use OCP\ILogger;
 use OCP\IUserManager;
 use OCP\ISession;
 use OCP\IPreview;
-use OCA\Files_Sharing\Activity;
+use OCA\Files_Sharing\Activity\Providers\Downloads;
 use \OCP\Files\NotFoundException;
 use OCP\Files\IRootFolder;
 use OCP\Share\Exceptions\ShareNotFound;
@@ -570,16 +570,16 @@ class ShareController extends Controller {
 
                if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
                        if ($node instanceof \OCP\Files\File) {
-                               $subject = Activity::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
+                               $subject = Downloads::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
                        } else {
-                               $subject = Activity::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
+                               $subject = Downloads::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
                        }
                        $parameters[] = $share->getSharedWith();
                } else {
                        if ($node instanceof \OCP\Files\File) {
-                               $subject = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
+                               $subject = Downloads::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
                        } else {
-                               $subject = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
+                               $subject = Downloads::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
                        }
                }
 
@@ -608,7 +608,7 @@ class ShareController extends Controller {
 
                $event = $this->activityManager->generateEvent();
                $event->setApp('files_sharing')
-                       ->setType(Activity::TYPE_PUBLIC_LINKS)
+                       ->setType('public_links')
                        ->setSubject($subject, $parameters)
                        ->setAffectedUser($affectedUser)
                        ->setObject('files', $fileId, $filePath);
diff --git a/apps/files_sharing/tests/ActivityTest.php b/apps/files_sharing/tests/ActivityTest.php
deleted file mode 100644 (file)
index 8acf199..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 OCA\Files_Sharing\Tests;
-
-/**
- * Class ActivityTest
- *
- * @group DB
- *
- * @package OCA\Files_Sharing\Tests
- */
-class ActivityTest extends TestCase {
-
-       /**
-        * @var \OCA\Files_Sharing\Activity
-        */
-       private $activity;
-
-       protected function setUp() {
-               parent::setUp();
-               $this->activity = new \OCA\Files_Sharing\Activity(
-                       $this->getMockBuilder('OCP\L10N\IFactory')
-                               ->disableOriginalConstructor()
-                               ->getMock(),
-                       $this->getMockBuilder('OCP\IURLGenerator')
-                               ->disableOriginalConstructor()
-                               ->getMock(),
-                       $this->getMockBuilder('OCP\Activity\IManager')
-                               ->disableOriginalConstructor()
-                               ->getMock()
-               );
-       }
-
-       /**
-        * @dataProvider dataTestGetDefaultType
-        */
-       public function testGetDefaultTypes($method, $expectedResult) {
-               $result = $this->activity->getDefaultTypes($method);
-
-               if (is_array($expectedResult)) {
-                       $this->assertSame(count($expectedResult), count($result));
-                       foreach ($expectedResult as $key => $expected) {
-                               $this->assertSame($expected, $result[$key]);
-                       }
-               } else {
-                       $this->assertSame($expectedResult, $result);
-               }
-
-       }
-
-       public function dataTestGetDefaultType() {
-               return array(
-                       array('email', array(\OCA\Files_Sharing\Activity::TYPE_SHARED, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE)),
-                       array('stream', array(\OCA\Files_Sharing\Activity::TYPE_SHARED, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::TYPE_PUBLIC_LINKS)),
-               );
-       }
-
-}
index 805124dc6027bf4b2ed89e217e942b452a1819ac..f102d2576fdba5137903f6c28d6b7cde7b45c36f 100644 (file)
@@ -683,11 +683,6 @@ class Manager implements IManager {
                foreach ($this->getExtensions() as $c) {
                        $result = $c->getNotificationTypes($languageCode);
                        if (is_array($result)) {
-                               if (class_exists('\OCA\Files_Sharing\Activity', false) && $c instanceof \OCA\Files_Sharing\Activity) {
-                                       $sharingNotificationTypes = $result;
-                                       continue;
-                               }
-
                                $notificationTypes = array_merge($notificationTypes, $result);
                        }
                }