Skip to content
Merged
Show file tree
Hide file tree
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: 22 additions & 15 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public function fileCreate($path) {
}

if ($this->currentUser->getUserIdentifier() !== '') {
$this->addNotificationsForFileAction($path, 'created_self', 'created_by');
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by');
} else {
$this->addNotificationsForFileAction($path, '', 'created_public');
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, '', 'created_public');
}
}

Expand All @@ -165,7 +165,7 @@ public function fileCreate($path) {
* @param string $path Path of the file that has been modified
*/
public function fileUpdate($path) {
$this->addNotificationsForFileAction($path, 'changed_self', 'changed_by');
$this->addNotificationsForFileAction($path, Files::TYPE_FILE_CHANGED, 'changed_self', 'changed_by');
}

/**
Expand All @@ -174,7 +174,7 @@ public function fileUpdate($path) {
* @param string $path Path of the file that has been deleted
*/
public function fileDelete($path) {
$this->addNotificationsForFileAction($path, 'deleted_self', 'deleted_by');
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_DELETED, 'deleted_self', 'deleted_by');
}

/**
Expand All @@ -183,14 +183,21 @@ public function fileDelete($path) {
* @param string $path Path of the file that has been restored
*/
public function fileRestore($path) {
$this->addNotificationsForFileAction($path, 'restored_self', 'restored_by');
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_RESTORED, 'restored_self', 'restored_by');
}

private function getFileChangeActivitySettings(int $fileId, array $users): array {
$filteredEmailUsers = $this->userSettings->filterUsersBySetting($users, 'email', Files::TYPE_FILE_CHANGED);
$filteredNotificationUsers = $this->userSettings->filterUsersBySetting($users, 'notification', Files::TYPE_FILE_CHANGED);

$favoriteUsers = $this->tagManager->getUsersFavoritingObject($fileId);
$users = array_intersect($users, $favoriteUsers);
$filteredEmailUsers = $this->userSettings->filterUsersBySetting($users, 'email', Files::TYPE_FAVORITE_CHANGED);
$filteredNotificationUsers = $this->userSettings->filterUsersBySetting($users, 'notification', Files::TYPE_FAVORITE_CHANGED);
if (!empty($favoriteUsers)) {
$favoriteUsers = array_intersect($users, $favoriteUsers);
if (!empty($favoriteUsers)) {
$filteredEmailUsers = array_merge($filteredEmailUsers, $this->userSettings->filterUsersBySetting($users, 'email', Files::TYPE_FAVORITE_CHANGED));
$filteredNotificationUsers = array_merge($filteredNotificationUsers, $this->userSettings->filterUsersBySetting($users, 'notification', Files::TYPE_FAVORITE_CHANGED));
}
}

return [$filteredEmailUsers, $filteredNotificationUsers];
}
Expand All @@ -199,11 +206,11 @@ private function getFileChangeActivitySettings(int $fileId, array $users): array
* Creates the entries for file actions on $file_path
*
* @param string $filePath The file that is being changed
* @param int $activityType The activity type
* @param string $activityType The activity type
* @param string $subject The subject for the actor
* @param string $subjectBy The subject for other users (with "by $actor")
*/
protected function addNotificationsForFileAction($filePath, $subject, $subjectBy) {
protected function addNotificationsForFileAction($filePath, $activityType, $subject, $subjectBy) {
// Do not add activities for .part-files
if (substr($filePath, -5) === '.part') {
return;
Expand All @@ -217,7 +224,7 @@ protected function addNotificationsForFileAction($filePath, $subject, $subjectBy

$accessList = $this->getUserPathsFromPath($filePath, $uidOwner);

$this->generateRemoteActivity($accessList['remotes'], Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId(), $accessList['ownerPath']);
$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);
Expand Down Expand Up @@ -250,7 +257,7 @@ protected function addNotificationsForFileAction($filePath, $subject, $subjectBy
$fileId, $path, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED
$activityType
);
}
}
Expand Down Expand Up @@ -492,8 +499,8 @@ protected function fileMoving($oldPath, $newPath) {
}
}

$this->generateRemoteActivity($deleteRemotes, Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId());
$this->generateRemoteActivity($addRemotes, Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId());
$this->generateRemoteActivity($deleteRemotes, Files::TYPE_SHARE_DELETED, time(), $this->currentUser->getCloudId());
$this->generateRemoteActivity($addRemotes, Files::TYPE_SHARE_CREATED, time(), $this->currentUser->getCloudId());
$this->generateRemoteActivity($moveRemotes, Files::TYPE_FILE_CHANGED, time(), $this->currentUser->getCloudId());
}

Expand Down Expand Up @@ -526,7 +533,7 @@ protected function generateDeleteActivities($users, $pathMap, $fileId, $oldFileN
$fileId, $path . '/' . $oldFileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED
Files::TYPE_SHARE_DELETED
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function getNotificationTypes() {
* @param array $users
* @param string $method
* @param string $type
* @return array Returns a "username => b:true" Map for method = stream
* @return array Returns a "username => b:true" Map for method = notification
* Returns a "username => i:batchtime" Map for method = email
*/
public function filterUsersBySetting($users, $method, $type) {
Expand Down Expand Up @@ -202,7 +202,7 @@ public function filterUsersBySetting($users, $method, $type) {
// we add all users that didn't set the preference yet.
if ($this->getDefaultFromSetting($method, $type)) {
foreach ($users as $user) {
if ($method === 'stream') {
if ($method === 'notification') {
$filteredUsers[$user] = true;
} else {
$filteredUsers[$user] = $this->getDefaultFromSetting('setting', 'batchtime');
Expand Down
12 changes: 6 additions & 6 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testFileCreate(string $currentUser, string $selfSubject, string

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
->with('path', $selfSubject, $othersSubject);
->with('path', Files::TYPE_SHARE_CREATED, $selfSubject, $othersSubject);

$filesHooks->fileCreate('path');
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testFileUpdate(): void {

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
->with('path', 'changed_self', 'changed_by');
->with('path', Files::TYPE_FILE_CHANGED, 'changed_self', 'changed_by');

$filesHooks->fileUpdate('path');
}
Expand All @@ -235,7 +235,7 @@ public function testFileDelete(): void {

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
->with('path', 'deleted_self', 'deleted_by');
->with('path', Files::TYPE_SHARE_DELETED, 'deleted_self', 'deleted_by');

$filesHooks->fileDelete('path');
}
Expand All @@ -247,7 +247,7 @@ public function testFileRestore(): void {

$filesHooks->expects($this->once())
->method('addNotificationsForFileAction')
->with('path', 'restored_self', 'restored_by');
->with('path', Files::TYPE_SHARE_RESTORED, 'restored_self', 'restored_by');

$filesHooks->fileRestore('path');
}
Expand Down Expand Up @@ -462,12 +462,12 @@ public function testAddNotificationsForFileAction(array $filterUsers, bool $moun
true,
$arguments['email'],
$arguments['notification'],
Files::TYPE_FILE_CHANGED
Files::TYPE_SHARE_RESTORED
);
$i++;
}

self::invokePrivate($filesHooks, 'addNotificationsForFileAction', ['path', 'restored_self', 'restored_by']);
self::invokePrivate($filesHooks, 'addNotificationsForFileAction', ['path', Files::TYPE_SHARE_RESTORED, 'restored_self', 'restored_by']);
}

public function testHookShareWithUser(): void {
Expand Down