Skip to content

Commit

Permalink
fix: split link upload activity type
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Aug 7, 2024
1 parent 4d8ae09 commit 7d045b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/Extension/Files_Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

class Files_Sharing {
public const TYPE_SHARED = 'shared';
public const TYPE_PUBLIC_UPLOAD = 'public_links_upload';
}
10 changes: 5 additions & 5 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function fileCreate($path) {
if ($this->currentUser->getUserIdentifier() !== '') {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, 'created_self', 'created_by');
} else {
$this->addNotificationsForFileAction($path, Files::TYPE_SHARE_CREATED, '', 'created_public');
$this->addNotificationsForFileAction($path, Files_Sharing::TYPE_PUBLIC_UPLOAD, '', 'created_public');
}
}

Expand Down Expand Up @@ -108,9 +108,9 @@ public function fileRestore($path) {
$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);
private function getFileChangeActivitySettings(int $fileId, array $users, $type = Files::TYPE_FILE_CHANGED): array {
$filteredEmailUsers = $this->userSettings->filterUsersBySetting($users, 'email', $type);
$filteredNotificationUsers = $this->userSettings->filterUsersBySetting($users, 'notification', $type);

/** @psalm-suppress UndefinedMethod */
$favoriteUsers = $this->tagManager->getUsersFavoritingObject('files', $fileId);
Expand Down Expand Up @@ -159,7 +159,7 @@ protected function addNotificationsForFileAction($filePath, $activityType, $subj
}

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

foreach ($affectedUsers as $user => $path) {
$user = (string)$user;
Expand Down
8 changes: 4 additions & 4 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ protected function getUserMock(string $uid): IUser {

public function dataFileCreate(): array {
return [
['user', 'created_self', 'created_by'],
['', '', 'created_public'],
['user', 'created_self', 'created_by', Files::TYPE_SHARE_CREATED],
['', '', 'created_public', Files_Sharing::TYPE_PUBLIC_UPLOAD],
];
}

Expand All @@ -190,14 +190,14 @@ public function dataFileCreate(): array {
* @param string $selfSubject
* @param string $othersSubject
*/
public function testFileCreate(string $currentUser, string $selfSubject, string $othersSubject): void {
public function testFileCreate(string $currentUser, string $selfSubject, string $othersSubject, string $type): void {
$filesHooks = $this->getFilesHooks([
'addNotificationsForFileAction',
], $currentUser);

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

$filesHooks->fileCreate('path');
}
Expand Down

0 comments on commit 7d045b8

Please sign in to comment.