update Comment Listener

Signed-off-by: Chris Fritsche <chris.fritsche@cunio.de>
This commit is contained in:
Chris Fritsche 2020-09-24 15:49:45 +02:00 committed by Morris Jobke
parent 1e3c071aa5
commit 3a16939f15
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
1 changed files with 33 additions and 4 deletions

View File

@ -25,12 +25,15 @@
namespace OCA\Comments\Activity;
use OC\User\NoUserException;
use OCP\Activity\IManager;
use OCP\App\IAppManager;
use OCP\Comments\CommentsEvent;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotPermittedException;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShareHelper;
@ -40,14 +43,16 @@ class Listener {
protected $activityManager;
/** @var IUserSession */
protected $session;
/** @var \OCP\App\IAppManager */
/** @var IAppManager */
protected $appManager;
/** @var \OCP\Files\Config\IMountProviderCollection */
/** @var IMountProviderCollection */
protected $mountCollection;
/** @var \OCP\Files\IRootFolder */
/** @var IRootFolder */
protected $rootFolder;
/** @var IShareHelper */
protected $shareHelper;
/** @var IConfig */
protected $config;
/**
* Listener constructor.
@ -58,23 +63,28 @@ class Listener {
* @param IMountProviderCollection $mountCollection
* @param IRootFolder $rootFolder
* @param IShareHelper $shareHelper
* @param IConfig $config
*/
public function __construct(IManager $activityManager,
IUserSession $session,
IAppManager $appManager,
IMountProviderCollection $mountCollection,
IRootFolder $rootFolder,
IShareHelper $shareHelper) {
IShareHelper $shareHelper,
IConfig $config) {
$this->activityManager = $activityManager;
$this->session = $session;
$this->appManager = $appManager;
$this->mountCollection = $mountCollection;
$this->rootFolder = $rootFolder;
$this->shareHelper = $shareHelper;
$this->config = $config;
}
/**
* @param CommentsEvent $event
* @throws NotPermittedException
* @throws NoUserException
*/
public function commentEvent(CommentsEvent $event) {
if ($event->getComment()->getObjectType() !== 'files'
@ -102,6 +112,9 @@ class Listener {
$al = $this->shareHelper->getPathsForAccessList($node);
$users += $al['users'];
}
if ($this->config->getSystemValueBool('activity_use_cached_mountpoints', false)) {
$users += [$owner => $this->getVisiblePath($mount->getPath())];
}
}
$actor = $this->session->getUser();
@ -133,4 +146,20 @@ class Listener {
$this->activityManager->publish($activity);
}
}
/**
* @param string $absolutePath
* @return string
*/
protected function getVisiblePath(string $absolutePath): string {
$sections = explode('/', $absolutePath, 4);
$path = '/';
if (isset($sections[3])) {
// Not the case when a file in root is renamed
$path .= $sections[3];
}
return $path;
}
}