summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/Activity/Providers
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-11-16 12:09:41 +0100
committerJoas Schilling <coding@schilljs.com>2016-11-16 16:45:08 +0100
commitbdaf334c5359b8e80397d5475f763bb826b274c0 (patch)
tree0c22f7d1258b799765c68f5302487eb5870fcae8 /apps/files_sharing/lib/Activity/Providers
parent81e9836900139d2fda65fa833e735a62e637ab3b (diff)
downloadnextcloud-server-bdaf334c5359b8e80397d5475f763bb826b274c0.tar.gz
nextcloud-server-bdaf334c5359b8e80397d5475f763bb826b274c0.zip
Move file sharing activities to the new API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing/lib/Activity/Providers')
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Downloads.php181
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Groups.php261
-rw-r--r--apps/files_sharing/lib/Activity/Providers/PublicLinks.php268
-rw-r--r--apps/files_sharing/lib/Activity/Providers/RemoteShares.php208
-rw-r--r--apps/files_sharing/lib/Activity/Providers/Users.php289
5 files changed, 1207 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Activity/Providers/Downloads.php b/apps/files_sharing/lib/Activity/Providers/Downloads.php
new file mode 100644
index 00000000000..84ef5895dde
--- /dev/null
+++ b/apps/files_sharing/lib/Activity/Providers/Downloads.php
@@ -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
index 00000000000..50b3df785e5
--- /dev/null
+++ b/apps/files_sharing/lib/Activity/Providers/Groups.php
@@ -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
index 00000000000..1b15520c70d
--- /dev/null
+++ b/apps/files_sharing/lib/Activity/Providers/PublicLinks.php
@@ -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
index 00000000000..c7906b84970
--- /dev/null
+++ b/apps/files_sharing/lib/Activity/Providers/RemoteShares.php
@@ -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
index 00000000000..915dbcf225a
--- /dev/null
+++ b/apps/files_sharing/lib/Activity/Providers/Users.php
@@ -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;
+ }
+ }
+}