Use DI for the objects where possible
This commit is contained in:
parent
dd535968e8
commit
e365ea7ec5
2 changed files with 27 additions and 7 deletions
|
@ -59,6 +59,9 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadshe
|
||||||
\OC::$server->getActivityManager()->registerExtension(function() {
|
\OC::$server->getActivityManager()->registerExtension(function() {
|
||||||
return new \OCA\Files\Activity(
|
return new \OCA\Files\Activity(
|
||||||
\OC::$server->query('L10NFactory'),
|
\OC::$server->query('L10NFactory'),
|
||||||
\OC::$server->getURLGenerator()
|
\OC::$server->getURLGenerator(),
|
||||||
|
\OC::$server->getActivityManager(),
|
||||||
|
\OC::$server->getTagManager(),
|
||||||
|
\OC::$server->getConfig()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,10 @@ namespace OCA\Files;
|
||||||
|
|
||||||
use OC\L10N\Factory;
|
use OC\L10N\Factory;
|
||||||
use OCP\Activity\IExtension;
|
use OCP\Activity\IExtension;
|
||||||
|
use OCP\Activity\IManager;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
use OCP\ITagManager;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
class Activity implements IExtension {
|
class Activity implements IExtension {
|
||||||
|
@ -46,14 +49,29 @@ class Activity implements IExtension {
|
||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
protected $URLGenerator;
|
protected $URLGenerator;
|
||||||
|
|
||||||
|
/** @var \OCP\Activity\IManager */
|
||||||
|
protected $activityManager;
|
||||||
|
|
||||||
|
/** @var \OCP\IConfig */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var \OCP\ITagManager */
|
||||||
|
protected $tagManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Factory $languageFactory
|
* @param Factory $languageFactory
|
||||||
* @param IURLGenerator $URLGenerator
|
* @param IURLGenerator $URLGenerator
|
||||||
|
* @param IManager $activityManager
|
||||||
|
* @param ITagManager $tagManager
|
||||||
|
* @param IConfig $config
|
||||||
*/
|
*/
|
||||||
public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator) {
|
public function __construct(Factory $languageFactory, IURLGenerator $URLGenerator, IManager $activityManager, ITagManager $tagManager, IConfig $config) {
|
||||||
$this->languageFactory = $languageFactory;
|
$this->languageFactory = $languageFactory;
|
||||||
$this->URLGenerator = $URLGenerator;
|
$this->URLGenerator = $URLGenerator;
|
||||||
$this->l = $this->getL10N();
|
$this->l = $this->getL10N();
|
||||||
|
$this->activityManager = $activityManager;
|
||||||
|
$this->tagManager = $tagManager;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -288,7 +306,7 @@ class Activity implements IExtension {
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
public function getQueryForFilter($filter) {
|
public function getQueryForFilter($filter) {
|
||||||
$user = \OC::$server->getActivityManager()->getCurrentUserId();
|
$user = $this->activityManager->getCurrentUserId();
|
||||||
// Display actions from all files
|
// Display actions from all files
|
||||||
if ($filter === self::FILTER_FILES) {
|
if ($filter === self::FILTER_FILES) {
|
||||||
return ['`app` = ?', ['files']];
|
return ['`app` = ?', ['files']];
|
||||||
|
@ -301,9 +319,7 @@ class Activity implements IExtension {
|
||||||
|
|
||||||
// Display actions from favorites only
|
// Display actions from favorites only
|
||||||
if ($filter === self::FILTER_FAVORITES || $filter === 'all' && $this->userSettingFavoritesOnly($user)) {
|
if ($filter === self::FILTER_FAVORITES || $filter === 'all' && $this->userSettingFavoritesOnly($user)) {
|
||||||
$tagManager = \OC::$server->getTagManager();
|
$tags = $this->tagManager->load('files', [], false, $user);
|
||||||
|
|
||||||
$tags = $tagManager->load('files', [], false, $user);
|
|
||||||
$favorites = $tags->getFavorites();
|
$favorites = $tags->getFavorites();
|
||||||
|
|
||||||
if (isset($favorites[50])) {
|
if (isset($favorites[50])) {
|
||||||
|
@ -311,6 +327,7 @@ class Activity implements IExtension {
|
||||||
return ['`app` = ?', ['files']];
|
return ['`app` = ?', ['files']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can not DI because the user is not known on instantiation
|
||||||
$rootFolder = \OC::$server->getUserFolder($user);
|
$rootFolder = \OC::$server->getUserFolder($user);
|
||||||
$parameters = $fileQueryList = [];
|
$parameters = $fileQueryList = [];
|
||||||
foreach ($favorites as $favorite) {
|
foreach ($favorites as $favorite) {
|
||||||
|
@ -350,6 +367,6 @@ class Activity implements IExtension {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function userSettingFavoritesOnly($user) {
|
protected function userSettingFavoritesOnly($user) {
|
||||||
return (bool) \OC::$server->getConfig()->getUserValue($user, 'activity', 'notify_stream_' . self::TYPE_FAVORITES, false);
|
return (bool) $this->config->getUserValue($user, 'activity', 'notify_stream_' . self::TYPE_FAVORITES, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue