Skip to content
Draft
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
177 changes: 101 additions & 76 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,26 +489,31 @@ protected function generateDeleteActivities($users, $pathMap, $fileId, $oldFileN
}

$shouldFlush = $this->startActivityTransaction();
foreach ($users as $user) {
$path = $pathMap[$user];
try {
foreach ($users as $user) {
$path = $pathMap[$user];

if ($user === $this->currentUser->getUID()) {
$userSubject = 'deleted_self';
$userParams = [[$fileId => $path . '/' . $oldFileName]];
} else {
$userSubject = 'deleted_by';
$userParams = [[$fileId => $path . '/' . $oldFileName], $this->currentUser->getUserIdentifier()];
}
if ($user === $this->currentUser->getUID()) {
$userSubject = 'deleted_self';
$userParams = [[$fileId => $path . '/' . $oldFileName]];
} else {
$userSubject = 'deleted_by';
$userParams = [[$fileId => $path . '/' . $oldFileName], $this->currentUser->getUserIdentifier()];
}

$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $path . '/' . $oldFileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_SHARE_DELETED,
);
$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $path . '/' . $oldFileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_SHARE_DELETED,
);
}
$this->commitActivityTransaction($shouldFlush);
} catch (\Throwable $e) {
$this->rollbackActivityTransaction($shouldFlush);
throw $e;
}
$this->commitActivityTransaction($shouldFlush);
}

/**
Expand All @@ -525,26 +530,31 @@ protected function generateAddActivities($users, $pathMap, $fileId, $fileName, a
}

$shouldFlush = $this->startActivityTransaction();
foreach ($users as $user) {
$path = $pathMap[$user];
try {
foreach ($users as $user) {
$path = $pathMap[$user];

if ($user === $this->currentUser->getUID()) {
$userSubject = 'created_self';
$userParams = [[$fileId => $path . '/' . $fileName]];
} else {
$userSubject = 'created_by';
$userParams = [[$fileId => $path . '/' . $fileName], $this->currentUser->getUserIdentifier()];
}
if ($user === $this->currentUser->getUID()) {
$userSubject = 'created_self';
$userParams = [[$fileId => $path . '/' . $fileName]];
} else {
$userSubject = 'created_by';
$userParams = [[$fileId => $path . '/' . $fileName], $this->currentUser->getUserIdentifier()];
}

$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $path . '/' . $fileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED,
);
$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $path . '/' . $fileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED,
);
}
$this->commitActivityTransaction($shouldFlush);
} catch (\Throwable $e) {
$this->rollbackActivityTransaction($shouldFlush);
throw $e;
}
$this->commitActivityTransaction($shouldFlush);
}

/**
Expand All @@ -564,30 +574,35 @@ protected function generateMoveActivities($users, $beforePathMap, $afterPathMap,
}

$shouldFlush = $this->startActivityTransaction();
foreach ($users as $user) {
if ($oldFileName === $fileName) {
$userParams = [[$newParentId => $afterPathMap[$user] . '/']];
} else {
$userParams = [[$fileId => $afterPathMap[$user] . '/' . $fileName]];
}
try {
foreach ($users as $user) {
if ($oldFileName === $fileName) {
$userParams = [[$newParentId => $afterPathMap[$user] . '/']];
} else {
$userParams = [[$fileId => $afterPathMap[$user] . '/' . $fileName]];
}

if ($user === $this->currentUser->getUID()) {
$userSubject = 'moved_self';
} else {
$userSubject = 'moved_by';
$userParams[] = $this->currentUser->getUserIdentifier();
}
$userParams[] = [$fileId => $beforePathMap[$user] . '/' . $oldFileName];
if ($user === $this->currentUser->getUID()) {
$userSubject = 'moved_self';
} else {
$userSubject = 'moved_by';
$userParams[] = $this->currentUser->getUserIdentifier();
}
$userParams[] = [$fileId => $beforePathMap[$user] . '/' . $oldFileName];

$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $afterPathMap[$user] . '/' . $fileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED,
);
$this->addNotificationsForUser(
$user, $userSubject, $userParams,
$fileId, $afterPathMap[$user] . '/' . $fileName, true,
$filteredEmailUsers[$user] ?? false,
$filteredNotificationUsers[$user] ?? false,
Files::TYPE_FILE_CHANGED,
);
}
$this->commitActivityTransaction($shouldFlush);
} catch (\Throwable $e) {
$this->rollbackActivityTransaction($shouldFlush);
throw $e;
}
$this->commitActivityTransaction($shouldFlush);
}

/**
Expand Down Expand Up @@ -949,13 +964,18 @@ protected function unshareFromGroup(IShare $share) {
$offset = 0;
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
$shouldFlush = $this->startActivityTransaction();
while (!empty($users)) {
$userIds = \array_map(fn (IUser $user) => $user->getUID(), $users);
$this->addNotificationsForUsers($userIds, $actionUser, $share->getNode(), $share->getTarget(), (int)$share->getId());
$offset += self::USER_BATCH_SIZE;
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
try {
while (!empty($users)) {
$userIds = \array_map(fn (IUser $user) => $user->getUID(), $users);
$this->addNotificationsForUsers($userIds, $actionUser, $share->getNode(), $share->getTarget(), (int)$share->getId());
$offset += self::USER_BATCH_SIZE;
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
}
$this->commitActivityTransaction($shouldFlush);
} catch (\Throwable $e) {
$this->rollbackActivityTransaction($shouldFlush);
throw $e;
}
$this->commitActivityTransaction($shouldFlush);
}

/**
Expand Down Expand Up @@ -1037,23 +1057,28 @@ protected function addNotificationsForUsers(array $usersIds, string $actionUser,

$affectedUsers = $this->fixPathsForShareExceptions($affectedUsers, $shareId);
$shouldFlush = $this->startActivityTransaction();
foreach ($affectedUsers as $user => $path) {
$emailSetting = $filteredEmailUsersInGroup[$user] ?? false;
$notificationSetting = $filteredNotificationUsers[$user] ?? false;
if ($emailSetting || $notificationSetting) {
$this->addNotificationsForUser(
$user,
$actionUser,
[[$fileSource->getId() => $path], $this->currentUser->getUserIdentifier()],
$fileSource->getId(),
$path,
$fileSource instanceof File,
$emailSetting,
$notificationSetting,
);
try {
foreach ($affectedUsers as $user => $path) {
$emailSetting = $filteredEmailUsersInGroup[$user] ?? false;
$notificationSetting = $filteredNotificationUsers[$user] ?? false;
if ($emailSetting || $notificationSetting) {
$this->addNotificationsForUser(
$user,
$actionUser,
[[$fileSource->getId() => $path], $this->currentUser->getUserIdentifier()],
$fileSource->getId(),
$path,
$fileSource instanceof File,
$emailSetting,
$notificationSetting,
);
}
}
$this->commitActivityTransaction($shouldFlush);
} catch (\Throwable $e) {
$this->rollbackActivityTransaction($shouldFlush);
throw $e;
}
$this->commitActivityTransaction($shouldFlush);
}

/**
Expand Down