Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity notifications for groupmates by Comments (when using Group Folder app) #23036

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions apps/comments/lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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'
Expand Down Expand Up @@ -102,6 +112,9 @@ public function commentEvent(CommentsEvent $event) {
$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();
Expand Down Expand Up @@ -133,4 +146,20 @@ public function commentEvent(CommentsEvent $event) {
$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;
}
}