summaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-03-25 15:19:25 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-03-30 15:23:09 +0200
commit17f882c3cf2d99a786daff56df5da8280746affb (patch)
treed1ed15835696a1680da84b9746cf0ae971c35611 /apps/files/lib
parentb95d12700ccd5987e580ee30efc50c76019de97a (diff)
downloadnextcloud-server-17f882c3cf2d99a786daff56df5da8280746affb.tar.gz
nextcloud-server-17f882c3cf2d99a786daff56df5da8280746affb.zip
Add a filter for favorites and allow limiting the all-list to favorites
WARNING: do not use this, when you have a lot of favorites, ~50 should be the limit
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/activity.php71
1 files changed, 69 insertions, 2 deletions
diff --git a/apps/files/lib/activity.php b/apps/files/lib/activity.php
index c376dc7b147..c613a074722 100644
--- a/apps/files/lib/activity.php
+++ b/apps/files/lib/activity.php
@@ -29,11 +29,13 @@ use OCP\IURLGenerator;
class Activity implements IExtension {
const FILTER_FILES = 'files';
+ const FILTER_FAVORITES = 'files_favorites';
const TYPE_SHARE_CREATED = 'file_created';
const TYPE_SHARE_CHANGED = 'file_changed';
const TYPE_SHARE_DELETED = 'file_deleted';
const TYPE_SHARE_RESTORED = 'file_restored';
+ const TYPE_FAVORITES = 'files_favorites';
/** @var IL10N */
protected $l;
@@ -74,6 +76,7 @@ class Activity implements IExtension {
return [
self::TYPE_SHARE_CREATED => (string) $l->t('A new file or folder has been <strong>created</strong>'),
self::TYPE_SHARE_CHANGED => (string) $l->t('A file or folder has been <strong>changed</strong>'),
+ self::TYPE_FAVORITES => (string) $l->t('Limit notifications about creation and changes to your <strong>favorite files</strong>'),
self::TYPE_SHARE_DELETED => (string) $l->t('A file or folder has been <strong>deleted</strong>'),
self::TYPE_SHARE_RESTORED => (string) $l->t('A file or folder has been <strong>restored</strong>'),
];
@@ -230,6 +233,11 @@ class Activity implements IExtension {
public function getNavigation() {
return [
'apps' => [
+ self::FILTER_FAVORITES => [
+ 'id' => self::FILTER_FAVORITES,
+ 'name' => (string) $this->l->t('Favorites'),
+ 'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', ['filter' => self::FILTER_FAVORITES]),
+ ],
self::FILTER_FILES => [
'id' => self::FILTER_FILES,
'name' => (string) $this->l->t('Files'),
@@ -247,7 +255,7 @@ class Activity implements IExtension {
* @return boolean
*/
public function isFilterValid($filterValue) {
- return $filterValue === self::FILTER_FILES;
+ return $filterValue === self::FILTER_FILES || $filterValue === self::FILTER_FAVORITES;
}
/**
@@ -259,7 +267,7 @@ class Activity implements IExtension {
* @return array|false
*/
public function filterNotificationTypes($types, $filter) {
- if ($filter === self::FILTER_FILES) {
+ if ($filter === self::FILTER_FILES || $filter === self::FILTER_FAVORITES) {
return array_intersect([
self::TYPE_SHARE_CREATED,
self::TYPE_SHARE_CHANGED,
@@ -280,9 +288,68 @@ class Activity implements IExtension {
* @return array|false
*/
public function getQueryForFilter($filter) {
+ $user = \OC::$server->getActivityManager()->getCurrentUserId();
+ // Display actions from all files
if ($filter === self::FILTER_FILES) {
return ['`app` = ?', ['files']];
}
+
+ if (!$user) {
+ // Remaining filters only work with a user/token
+ return false;
+ }
+
+ // Display actions from favorites only
+ if ($filter === self::FILTER_FAVORITES || $filter === 'all' && $this->userSettingFavoritesOnly($user)) {
+ $tagManager = \OC::$server->getTagManager();
+
+ $tags = $tagManager->load('files', [], false, $user);
+ $favorites = $tags->getFavorites();
+
+ if (isset($favorites[50])) {
+ // Too many favorites, can not put them into one query anymore...
+ return ['`app` = ?', ['files']];
+ }
+
+ $rootFolder = \OC::$server->getUserFolder($user);
+ $parameters = $fileQueryList = [];
+ foreach ($favorites as $favorite) {
+ $nodes = $rootFolder->getById($favorite);
+ if ($nodes) {
+ /** @var \OCP\Files\Node $node */
+ $node = array_shift($nodes);
+
+ $fileQueryList[] = '`file` = ?';
+ $parameters[] = substr($node->getPath(), strlen($user . '/files/'));
+
+ if ($node instanceof \OCP\Files\Folder) {
+ // Also look for subfolders and files
+ $fileQueryList[] = '`file` LIKE ?';
+ $parameters[] = substr($node->getPath(), strlen($user . '/files/')) . '/%';
+ }
+ }
+ }
+
+ if (empty($fileQueryList)) {
+ // No favorites...
+ return ['`app` = ?', ['files']];
+ }
+
+ return [
+ ' CASE WHEN `app` = \'files\' THEN (' . implode(' OR ', $fileQueryList) . ') ELSE `app` <> \'files\' END ',
+ $parameters,
+ ];
+ }
return false;
}
+
+ /**
+ * Is the file actions favorite limitation enabled?
+ *
+ * @param string $user
+ * @return bool
+ */
+ protected function userSettingFavoritesOnly($user) {
+ return (bool) \OC::$server->getConfig()->getUserValue($user, 'activity', 'notify_stream_' . self::TYPE_FAVORITES, false);
+ }
}