Skip to content

Commit

Permalink
update FilesHooks class
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Fritsche <chris.fritsche@cunio.de>
  • Loading branch information
Chris Fritsche committed Sep 23, 2020
1 parent 1334dc5 commit 843f830
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,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 @@ -413,7 +402,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 @@ -461,8 +450,8 @@ protected function fileMoving($oldPath, $newPath) {
return;
}
$accessList = $this->getUserPathsFromPath($parentPath, $parentOwner);
$affectedUsers = $accessList['users'];
$oldUsers = $this->oldAccessList['users'];
$affectedUsers = $this->getAffectedUsers($accessList['users'], $fileId);
$oldUsers = $this->getAffectedUsers($this->oldAccessList['users'], $fileId);

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

/**
* @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);
$affectedUsers = array_combine($affectedUserIds, $affectedPaths);
} else {
$affectedUsers = $defaultUsers;
}

return $affectedUsers;
}
}

0 comments on commit 843f830

Please sign in to comment.