const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired';
const SUBJECT_SHARED_EMAIL = 'shared_with_email';
+ 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';
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 public shared file or folder was <strong>downloaded</strong>'),
+ self::TYPE_PUBLIC_LINKS => (string) $l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>'),
);
}
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_EMAIL:
return (string) $l->t('You shared %1$s with %2$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;
case self::SUBJECT_SHARED_WITH_BY:
return (string) $l->t('Shared by %2$s', $params);
+
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('Shared with %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;
* 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
1 => 'username',
2 => '',
];
- case self::SUBJECT_SHARED_EMAIL:
+ case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED:
+ case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED:
return array(
0 => 'file',
- 1 => '',// 'email' is neither supported nor planned for now
+ 1 => 'email',
);
case self::SUBJECT_SHARED_USER_SELF:
namespace OCA\Files_Sharing\Controller;
+use OC\Files\Node\Folder;
use OC_Files;
use OC_Util;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\IUserManager;
use OCP\ISession;
use OCP\IPreview;
-use OCP\Util;
use OCA\Files_Sharing\Activity;
use \OCP\Files\NotFoundException;
use OCP\Files\IRootFolder;
// Single file share
if ($share->getNode() instanceof \OCP\Files\File) {
// Single file download
- $event = $this->activityManager->generateEvent();
- $event->setApp('files_sharing')
- ->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())])
- ->setAffectedUser($share->getShareOwner())
- ->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath()));
- $this->activityManager->publish($event);
+ $this->singleFileDownloaded($share, $share->getNode());
}
// Directory share
else {
if ($node instanceof \OCP\Files\File) {
// Single file download
- $event = $this->activityManager->generateEvent();
- $event->setApp('files_sharing')
- ->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])
- ->setAffectedUser($share->getShareOwner())
- ->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
- $this->activityManager->publish($event);
+ $this->singleFileDownloaded($share, $share->getNode());
} else if (!empty($files_list)) {
- /** @var \OCP\Files\Folder $node */
-
- // Subset of files is downloaded
- foreach ($files_list as $file) {
- $subNode = $node->get($file);
-
- $event = $this->activityManager->generateEvent();
- $event->setApp('files_sharing')
- ->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setAffectedUser($share->getShareOwner())
- ->setObject('files', $subNode->getId(), $userFolder->getRelativePath($subNode->getPath()));
-
- if ($subNode instanceof \OCP\Files\File) {
- $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]);
- } else {
- $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]);
- }
-
- $this->activityManager->publish($event);
- }
+ $this->fileListDownloaded($share, $files_list);
} else {
// The folder is downloaded
- $event = $this->activityManager->generateEvent();
- $event->setApp('files_sharing')
- ->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])
- ->setAffectedUser($share->getShareOwner())
- ->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
- $this->activityManager->publish($event);
+ $this->singleFileDownloaded($share, $share->getNode());
}
}
exit();
}
}
+
+ /**
+ * create activity for every downloaded file
+ *
+ * @param Share\IShare $share
+ * @param array $files_list
+ */
+ protected function fileListDownloaded(Share\IShare $share, array $files_list) {
+ foreach ($files_list as $file) {
+ $subNode = $share->getNode()->get($file);
+ $this->singleFileDownloaded($share, $subNode);
+ }
+
+ }
+
+ /**
+ * create activity if a single file was downloaded from a link share
+ *
+ * @param Share\IShare $share
+ */
+ protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) {
+
+ $fileId = $node->getId();
+
+ $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
+ $userNodeList = $userFolder->getById($fileId);
+ $userNode = $userNodeList[0];
+ $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
+ $userPath = $userFolder->getRelativePath($userNode->getPath());
+ $ownerPath = $ownerFolder->getRelativePath($node->getPath());
+
+ $parameters = [$userPath];
+
+ if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
+ if ($node instanceof \OCP\Files\File) {
+ $subject = Activity::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED;
+ } else {
+ $subject = Activity::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED;
+ }
+ $parameters[] = $share->getSharedWith();
+ } else {
+ if ($node instanceof \OCP\Files\File) {
+ $subject = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED;
+ } else {
+ $subject = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED;
+ }
+ }
+
+ $this->publishActivity($subject, $parameters, $share->getSharedBy(), $fileId, $userPath);
+
+ if ($share->getShareOwner() !== $share->getSharedBy()) {
+ $parameters[0] = $ownerPath;
+ $this->publishActivity($subject, $parameters, $share->getShareOwner(), $fileId, $ownerPath);
+ }
+ }
+
+ /**
+ * publish activity
+ *
+ * @param string $subject
+ * @param array $parameters
+ * @param string $affectedUser
+ * @param int $fileId
+ * @param string $filePath
+ */
+ protected function publishActivity($subject,
+ array $parameters,
+ $affectedUser,
+ $fileId,
+ $filePath) {
+
+ $event = $this->activityManager->generateEvent();
+ $event->setApp('files_sharing')
+ ->setType(Activity::TYPE_PUBLIC_LINKS)
+ ->setSubject($subject, $parameters)
+ ->setAffectedUser($affectedUser)
+ ->setObject('files', $fileId, $filePath);
+ $this->activityManager->publish($event);
+ }
+
+
}