Skip to content
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
40 changes: 26 additions & 14 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,7 @@ protected function addNotificationsForFileAction($filePath, $activityType, $subj
$this->generateRemoteActivity($accessList['remotes'], $activityType, time(), $this->currentUser->getCloudId(), $accessList['ownerPath']);
}

if ($this->config->getSystemValueBool('activity_use_cached_mountpoints', false)) {
$mountsForFile = $this->userMountCache->getMountsForFileId($fileId);
$affectedUserIds = array_map(function (ICachedMountInfo $mount) {
return $mount->getUser()->getUID();
}, $mountsForFile);
$affectedPaths = array_map(function (ICachedMountFileInfo $mount) {
return $this->getVisiblePath($mount->getPath());
}, $mountsForFile);
$affectedUsers = array_combine($affectedUserIds, $affectedPaths);
} else {
$affectedUsers = $accessList['users'];
}
$affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId);

[$filteredEmailUsers, $filteredNotificationUsers] = $this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers));

Expand Down Expand Up @@ -361,6 +350,7 @@ public function fileMove($oldPath, $newPath) {
return;
}
$this->oldAccessList = $this->getUserPathsFromPath($this->oldParentPath, $this->oldParentOwner);
$this->oldAccessList['users'] = $this->getAffectedUsers($this->oldAccessList['users'], $this->oldParentId);
}


Expand Down Expand Up @@ -420,7 +410,7 @@ protected function fileRenaming($oldPath, $newPath) {
}
$this->generateRemoteActivity($renameRemotes, Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId());

$affectedUsers = $accessList['users'];
$affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId);
[$filteredEmailUsers, $filteredNotificationUsers] = $this->getFileChangeActivitySettings($fileId, array_keys($affectedUsers));

foreach ($affectedUsers as $user => $path) {
Expand Down Expand Up @@ -467,7 +457,7 @@ protected function fileMoving($oldPath, $newPath) {
return;
}
$accessList = $this->getUserPathsFromPath($parentPath, $parentOwner);
$affectedUsers = $accessList['users'];
$affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId);
$oldUsers = $this->oldAccessList['users'];

$beforeUsers = array_keys($oldUsers);
Expand Down Expand Up @@ -1197,4 +1187,26 @@ protected function addNotificationsForUser($user, $subject, $subjectParams, $fil
$this->activityData->storeMail($event, $latestSend);
}
}

/**
* Gets an array of the users that should be notified for a path
*
* @param $defaultUsers
* @param $fileId
* @return array|mixed
*/
protected function getAffectedUsers($defaultUsers, $fileId) {
if ($this->config->getSystemValueBool('activity_use_cached_mountpoints', false)) {
$mountsForFile = $this->userMountCache->getMountsForFileId($fileId);
$affectedUserIds = array_map(function (ICachedMountInfo $mount) {
return $mount->getUser()->getUID();
}, $mountsForFile);
$affectedPaths = array_map(function (ICachedMountFileInfo $mount) {
return $this->getVisiblePath($mount->getPath());
}, $mountsForFile);
return array_combine($affectedUserIds, $affectedPaths);
}

return $defaultUsers;
}
}