Skip to content

Commit

Permalink
Move code for getting affected users to separate function
Browse files Browse the repository at this point in the history
This is only preparation for implementing notifications for group members
in case of moving, renaming and sharing which is currently missing. This
doesn't include any changes to the logic.

Signed-off-by: Chris Fritsche <chris.fritsche@cunio.de>
Signed-off-by: Frieder Schrempf <frieder@fris.de>
  • Loading branch information
Chris Fritsche authored and fschrempf committed Jan 4, 2022
1 parent cd29d87 commit 1d0fba9
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 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 @@ -1197,4 +1186,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;
}
}

0 comments on commit 1d0fba9

Please sign in to comment.