diff options
Diffstat (limited to 'apps/files_sharing/lib/Activity/Providers/Downloads.php')
-rw-r--r-- | apps/files_sharing/lib/Activity/Providers/Downloads.php | 108 |
1 files changed, 14 insertions, 94 deletions
diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php index 01012e4785b..eb14c16266c 100644 --- a/apps/files_sharing/lib/Activity/Providers/Downloads.php +++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php @@ -22,25 +22,9 @@ 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\L10N\IFactory; -class Downloads implements IProvider { +class Downloads extends Base { - /** @var IFactory */ - protected $languageFactory; - - /** @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'; @@ -49,43 +33,6 @@ class Downloads implements IProvider { const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; /** - * @param IFactory $languageFactory - * @param IURLGenerator $url - * @param IManager $activityManager - */ - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager) { - $this->languageFactory = $languageFactory; - $this->url = $url; - $this->activityManager = $activityManager; - } - - /** - * @param string $language - * @param IEvent $event - * @param IEvent|null $previousEvent - * @return IEvent - * @throws \InvalidArgumentException - * @since 11.0.0 - */ - public function parse($language, IEvent $event, IEvent $previousEvent = null) { - if ($event->getApp() !== 'files_sharing') { - throw new \InvalidArgumentException(); - } - - $this->l = $this->languageFactory->get('files_sharing', $language); - - 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 @@ -96,19 +43,17 @@ class Downloads implements IProvider { if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_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'))); + $subject = $this->l->t('Downloaded via public link'); } 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'))); + $subject = $this->l->t('Downloaded by {email}'); } else { throw new \InvalidArgumentException(); } + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); + $this->setSubjects($event, $subject, $parsedParameters); + return $event; } @@ -123,34 +68,24 @@ class Downloads implements IProvider { if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_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'))); + $subject = $this->l->t('{file} downloaded via public link'); } 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'))); + $subject = $this->l->t('{email} downloaded {file}'); } else { throw new \InvalidArgumentException(); } + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); + $this->setSubjects($event, $subject, $parsedParameters); + return $event; } /** * @param IEvent $event * @return array + * @throws \InvalidArgumentException */ protected function getParsedParameters(IEvent $event) { $subject = $event->getSubject(); @@ -160,12 +95,12 @@ class Downloads implements IProvider { case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: return [ - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), + 'file' => $this->getFile($parameters[0], $event), ]; case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: return [ - 'file' => $this->generateFileParameter($event->getObjectId(), $parameters[0]), + 'file' => $this->getFile($parameters[0], $event), 'email' => [ 'type' => 'email', 'id' => $parameters[1], @@ -176,19 +111,4 @@ class Downloads implements IProvider { throw new \InvalidArgumentException(); } - - /** - * @param int $id - * @param string $path - * @return array - */ - protected function generateFileParameter($id, $path) { - return [ - 'type' => 'file', - 'id' => $id, - 'name' => basename($path), - 'path' => trim($path, '/'), - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), - ]; - } } |