Skip to content

Commit ff77ceb

Browse files
committed
fix(shares): Don't notify users that "Unshared" a calendar
Signed-off-by: Joas Schilling <[email protected]>
1 parent b3c2cd2 commit ff77ceb

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lib/EventListener.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array
139139
'hasTime' => $hasTime,
140140
]);
141141

142-
$users = $this->getUsersForShares($shares, $owner);
142+
$users = $this->getUsersForShares($shares, $owner, $calendarData['id']);
143143

144144
foreach ($users as $user) {
145145
if ($user === $currentUser) {
@@ -210,7 +210,7 @@ protected function getObjectNameAndType(array $objectData) {
210210
* @param string $owner
211211
* @return string[]
212212
*/
213-
protected function getUsersForShares(array $shares, string $owner): array {
213+
protected function getUsersForShares(array $shares, string $owner, int $calendarId): array {
214214
$users = [$owner];
215215
$groups = [];
216216
foreach ($shares as $share) {
@@ -222,18 +222,44 @@ protected function getUsersForShares(array $shares, string $owner): array {
222222
}
223223
}
224224

225+
$groupAddedUsers = false;
225226
if (!empty($groups)) {
226227
foreach ($groups as $gid) {
227228
$group = $this->groupManager->get($gid);
228229
if ($group instanceof IGroup) {
229230
foreach ($group->getUsers() as $user) {
231+
$groupAddedUsers = true;
230232
$users[] = $user->getUID();
231233
}
232234
}
233235
}
234236
}
235237

236-
return array_unique($users);
238+
$users = array_unique($users);
239+
240+
if (!$groupAddedUsers) {
241+
return $users;
242+
}
243+
244+
/** @var \OCA\DAV\CalDAV\Sharing\Service $service */
245+
$service = \OCP\Server::get(\OCA\DAV\CalDAV\Sharing\Service::class);
246+
if (!method_exists($service, 'getUnshares')) {
247+
return $users;
248+
}
249+
250+
$unshares = $service->getUnshares($calendarId);
251+
$usersToRemove = [];
252+
foreach ($unshares as $unshare) {
253+
254+
$prinical = explode('/', $unshare['principaluri']);
255+
if ($prinical[1] === 'users') {
256+
$usersToRemove[] = $prinical[2];
257+
}
258+
}
259+
260+
$users = array_diff($users, $usersToRemove);
261+
262+
return $users;
237263
}
238264

239265
/**

0 commit comments

Comments
 (0)