summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/appinfo/info.xml4
-rw-r--r--apps/files/img/add-color.svg6
-rw-r--r--apps/files/img/change.svg5
-rw-r--r--apps/files/img/delete-color.svg4
-rw-r--r--apps/files/lib/Activity/Provider.php207
5 files changed, 226 insertions, 0 deletions
diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml
index 53452f4b071..1992b94a03c 100644
--- a/apps/files/appinfo/info.xml
+++ b/apps/files/appinfo/info.xml
@@ -30,6 +30,10 @@
<filter>OCA\Files\Activity\Filter\FileChanges</filter>
<filter>OCA\Files\Activity\Filter\Favorites</filter>
</filters>
+
+ <providers>
+ <provider>OCA\Files\Activity\Provider</provider>
+ </providers>
</activity>
<background-jobs>
diff --git a/apps/files/img/add-color.svg b/apps/files/img/add-color.svg
new file mode 100644
index 00000000000..acf5543c43f
--- /dev/null
+++ b/apps/files/img/add-color.svg
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1">
+ <g transform="matrix(-.70711 -.70711 .70711 -.70711 -724.85 753.16)" fill="#00d400">
+ <path d="m3.7547 1041.6 1.4142-1.4142 3.5355 3.5355 3.5355-3.5355 1.4142 1.4142-3.5355 3.5355 3.5355 3.5356-1.4142 1.4142-3.5355-3.5356-3.5164 3.5547-1.4333-1.4333 3.5355-3.5356z" fill="#00d400"/>
+ </g>
+</svg>
diff --git a/apps/files/img/change.svg b/apps/files/img/change.svg
new file mode 100644
index 00000000000..cbc5d982b30
--- /dev/null
+++ b/apps/files/img/change.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1">
+ <path d="m7.9375 0c-3.1175 0.023214-6.0756 1.876-7.3438 4.9375l2.7812 1.1563c1.0568-2.5513 3.98-3.7756 6.5312-2.7188 0.8628 0.3573 1.5738 0.9274 2.0938 1.625l-2 2h6v-6l-1.875 1.875c-0.802-0.9616-1.825-1.7688-3.063-2.2812-1.02-0.4227-2.0853-0.60149-3.1245-0.59375z"/>
+ <path d="m0 9.5v6l2.0938-2.094c0.7676 0.843 1.7205 1.535 2.8437 2 4.082 1.691 8.7775-0.262 10.468-4.344l-2.781-1.1558c-1.057 2.5508-3.98 3.7758-6.5312 2.7188-0.7435-0.308-1.3509-0.805-1.8438-1.375l1.75-1.75h-6z"/>
+</svg>
diff --git a/apps/files/img/delete-color.svg b/apps/files/img/delete-color.svg
new file mode 100644
index 00000000000..810c63e811b
--- /dev/null
+++ b/apps/files/img/delete-color.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1">
+ <path d="m12.95 11.536-1.414 1.414-3.536-3.5358-3.5355 3.5358-1.4142-1.414 3.5355-3.536-3.5355-3.5356 1.4142-1.4142 3.5355 3.5356 3.516-3.5547 1.434 1.4333-3.5357 3.5356z" fill="#d40000"/>
+</svg>
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php
new file mode 100644
index 00000000000..ee7030ce546
--- /dev/null
+++ b/apps/files/lib/Activity/Provider.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @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\Activity;
+
+use OCP\Activity\IEvent;
+use OCP\Activity\IProvider;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+
+class Provider implements IProvider {
+
+ /** @var IL10N */
+ protected $l;
+
+ /** @var IURLGenerator */
+ protected $url;
+
+ /**
+ * @param IL10N $l
+ * @param IURLGenerator $url
+ */
+ public function __construct(IL10N $l, IURLGenerator $url) {
+ $this->l = $l;
+ $this->url = $url;
+ }
+
+ /**
+ * @param IEvent $event
+ * @param IEvent|null $previousEvent
+ * @return IEvent
+ * @throws \InvalidArgumentException
+ * @since 9.2.0
+ */
+ public function parse(IEvent $event, IEvent $previousEvent = null) {
+ if ($event->getApp() !== 'files') {
+ throw new \InvalidArgumentException();
+ }
+
+ $parsedParameters = $this->getParsedParameters($event->getSubject(), $event->getSubjectParameters());
+ $richParameters = $this->getRichParameters($event->getSubject(), $event->getSubjectParameters());
+
+ if ($event->getSubject() === 'created_self') {
+ $event->setParsedSubject($this->l->t('You created %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You created {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
+ } else if ($event->getSubject() === 'created_by') {
+ $event->setParsedSubject($this->l->t('%2$s created %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} created {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
+ } else if ($event->getSubject() === 'created_public') {
+ $event->setParsedSubject($this->l->t('%1$s was created in a public folder', $parsedParameters))
+ ->setRichSubject($this->l->t('{file1} was created in a public folder'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'add-color.svg')));
+ } else if ($event->getSubject() === 'changed_self') {
+ $event->setParsedSubject($this->l->t('You changed %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You changed {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else if ($event->getSubject() === 'changed_by') {
+ $event->setParsedSubject($this->l->t('%2$s changed %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} changed {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else if ($event->getSubject() === 'deleted_self') {
+ $event->setParsedSubject($this->l->t('You deleted %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You deleted {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg')));
+ } else if ($event->getSubject() === 'deleted_by') {
+ $event->setParsedSubject($this->l->t('%2$s deleted %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} deleted {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'delete-color.svg')));
+ } else if ($event->getSubject() === 'restored_self') {
+ $event->setParsedSubject($this->l->t('You restored %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You restored {file1}'), $richParameters);
+ } else if ($event->getSubject() === 'restored_by') {
+ $event->setParsedSubject($this->l->t('%2$s restored %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} restored {file1}'), $richParameters);
+ } else if ($event->getSubject() === 'renamed_self') {
+ $event->setParsedSubject($this->l->t('You renamed %2$s to %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You renamed {file2} to {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else if ($event->getSubject() === 'renamed_by') {
+ $event->setParsedSubject($this->l->t('%2$s renamed %3$s to %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} renamed {file2} to {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else if ($event->getSubject() === 'moved_self') {
+ $event->setParsedSubject($this->l->t('You moved %2$s to %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('You moved {file2} to {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else if ($event->getSubject() === 'moved_by') {
+ $event->setParsedSubject($this->l->t('%2$s moved %3$s to %1$s', $parsedParameters))
+ ->setRichSubject($this->l->t('{user1} moved {file2} to {file1}'), $richParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('files', 'change.svg')));
+ } else {
+ throw new \InvalidArgumentException();
+ }
+
+ return $event;
+ }
+
+ protected function getParsedParameters($subject, array $parameters) {
+ switch ($subject) {
+ case 'created_self':
+ case 'created_public':
+ case 'changed_self':
+ case 'deleted_self':
+ case 'restored_self':
+ return [
+ array_shift($parameters[0]),
+ ];
+ case 'created_by':
+ case 'changed_by':
+ case 'deleted_by':
+ case 'restored_by':
+ return [
+ array_shift($parameters[0]),
+ $parameters[1],
+ ];
+ case 'renamed_self':
+ case 'moved_self':
+ return [
+ array_shift($parameters[0]),
+ array_shift($parameters[1]),
+ ];
+ case 'renamed_by':
+ case 'moved_by':
+ return [
+ array_shift($parameters[0]),
+ $parameters[1],
+ array_shift($parameters[2]),
+ ];
+ }
+ return [];
+ }
+
+ protected function getRichParameters($subject, array $parameters) {
+ switch ($subject) {
+ case 'created_self':
+ case 'created_public':
+ case 'changed_self':
+ case 'deleted_self':
+ case 'restored_self':
+ return [
+ 'file1' => $this->getRichFileParameter($parameters[0]),
+ ];
+ case 'created_by':
+ case 'changed_by':
+ case 'deleted_by':
+ case 'restored_by':
+ return [
+ 'file1' => $this->getRichFileParameter($parameters[0]),
+ 'user1' => $this->getRichUserParameter($parameters[1]),
+ ];
+ case 'renamed_self':
+ case 'moved_self':
+ return [
+ 'file1' => $this->getRichFileParameter($parameters[0]),
+ 'file2' => $this->getRichFileParameter($parameters[1]),
+ ];
+ case 'renamed_by':
+ case 'moved_by':
+ return [
+ 'file1' => $this->getRichFileParameter($parameters[0]),
+ 'user1' => $this->getRichUserParameter($parameters[1]),
+ 'file2' => $this->getRichFileParameter($parameters[2]),
+ ];
+ }
+ return [];
+ }
+
+ protected function getRichFileParameter($parameter) {
+ $path = reset($parameter);
+ $id = key($parameter);
+ return [
+ 'type' => 'file',
+ 'id' => $id,
+ 'name' => basename($path),
+ 'path' => $path,
+ ];
+ }
+
+ protected function getRichUserParameter($parameter) {
+ return [
+ 'type' => 'user',
+ 'id' => $parameter,
+ 'name' => $parameter,// FIXME Use display name
+ ];
+ }
+}