summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-10-02 09:54:35 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-10-02 10:01:33 +0200
commit17ab8e6c397011059b589da72a5d59cce8b65c7d (patch)
treea05d8b73b7d88952bc6c337d2bf2543cce8ed0b2 /apps
parentf3864c5444a7e56602d25d82ad13c0d79522c97d (diff)
downloadnextcloud-server-17ab8e6c397011059b589da72a5d59cce8b65c7d.tar.gz
nextcloud-server-17ab8e6c397011059b589da72a5d59cce8b65c7d.zip
Use shorter text on the sidebar for files_sharing activities
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/appinfo/app.php3
-rw-r--r--apps/files_sharing/lib/activity.php66
-rw-r--r--apps/files_sharing/tests/activity.php5
3 files changed, 69 insertions, 5 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 15c0b864b08..1417dd6214b 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -70,7 +70,8 @@ $eventDispatcher->addListener(
\OC::$server->getActivityManager()->registerExtension(function() {
return new \OCA\Files_Sharing\Activity(
\OC::$server->query('L10NFactory'),
- \OC::$server->getURLGenerator()
+ \OC::$server->getURLGenerator(),
+ \OC::$server->getActivityManager()
);
});
diff --git a/apps/files_sharing/lib/activity.php b/apps/files_sharing/lib/activity.php
index 63ac2e90b2a..6f0294bcb71 100644
--- a/apps/files_sharing/lib/activity.php
+++ b/apps/files_sharing/lib/activity.php
@@ -24,6 +24,8 @@
namespace OCA\Files_Sharing;
use OCP\Activity\IExtension;
+use OCP\Activity\IManager;
+use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
@@ -67,13 +69,18 @@ class Activity implements IExtension {
/** @var IURLGenerator */
protected $URLGenerator;
+ /** @var IManager */
+ protected $activityManager;
+
/**
* @param IFactory $languageFactory
* @param IURLGenerator $URLGenerator
+ * @param IManager $activityManager
*/
- public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator) {
+ public function __construct(IFactory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager) {
$this->languageFactory = $languageFactory;
$this->URLGenerator = $URLGenerator;
+ $this->activityManager = $activityManager;
}
protected function getL10N($languageCode = null) {
@@ -149,9 +156,30 @@ class Activity implements IExtension {
* @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 ($app === self::FILES_SHARING_APP) {
+ 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) {
@@ -186,12 +214,44 @@ class Activity implements IExtension {
case self::SUBJECT_SHARED_EMAIL:
return (string) $l->t('You shared %1$s with %2$s', $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_SHARED_GROUP_SELF:
+ return (string) $l->t('Shared with group %2$s', $params);
+ case self::SUBJECT_RESHARED_USER_BY:
+ return (string) $l->t('Shared with %3$s by %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_RESHARED_LINK_BY:
+ return (string) $l->t('Shared via link by %2$s', $params);
+ case self::SUBJECT_SHARED_WITH_BY:
+ return (string) $l->t('Shared by %2$s', $params);
+ case self::SUBJECT_SHARED_LINK_SELF:
+ return (string) $l->t('Shared via public link');
+ case self::SUBJECT_SHARED_EMAIL:
+ return (string) $l->t('Shared with %2$s', $params);
+
+ default:
+ return false;
+ }
+ }
+
+ /**
* The extension can define the type of parameters for translation
*
* Currently known types are:
diff --git a/apps/files_sharing/tests/activity.php b/apps/files_sharing/tests/activity.php
index 53a306b70f7..f7f324cdfc3 100644
--- a/apps/files_sharing/tests/activity.php
+++ b/apps/files_sharing/tests/activity.php
@@ -36,7 +36,10 @@ class Activity extends \OCA\Files_Sharing\Tests\TestCase{
parent::setUp();
$this->activity = new \OCA\Files_Sharing\Activity(
$this->getMock('\OC\L10N\Factory'),
- $this->getMockBuilder('\OC\URLGenerator')
+ $this->getMockBuilder('\OCP\IURLGenerator')
+ ->disableOriginalConstructor()
+ ->getMock(),
+ $this->getMockBuilder('\OCP\Activity\IManager')
->disableOriginalConstructor()
->getMock()
);