Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add notifications for users that are added to the group
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Nov 12, 2019
commit 8986910a7d6a0bd7ee08bca68f1f5008612e38dc
6 changes: 6 additions & 0 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\Defaults;
use OCP\Federation\ICloudIdManager;
use \OCP\IContainer;
use OCP\IGroup;
use OCP\IServerContainer;
use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\External\Manager;
Expand Down Expand Up @@ -188,5 +189,10 @@ public function register(): void {
$listener = $this->getContainer()->query(Listener::class);
$listener->shareNotification($event);
});
$dispatcher->addListener(IGroup::class . '::postAddUser', function(GenericEvent $event) {
/** @var Listener $listener */
$listener = $this->getContainer()->query(Listener::class);
$listener->userAddedToGroup($event);
});
}
}
48 changes: 45 additions & 3 deletions apps/files_sharing/lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,31 @@
namespace OCA\Files_Sharing\Notification;

use OC\Share\Share;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\Notification\IManager;
use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {

/** @var IManager */
/** @var INotificationManager */
protected $notificationManager;
/** @var IShareManager */
protected $shareManager;
/** @var IGroupManager */
protected $groupManager;

public function __construct(
IManager $notificationManager,
INotificationManager $notificationManager,
IShareManager $shareManager,
IGroupManager $groupManager
) {
$this->notificationManager = $notificationManager;
$this->shareManager = $shareManager;
$this->groupManager = $groupManager;
}

Expand Down Expand Up @@ -74,6 +81,41 @@ public function shareNotification(GenericEvent $event): void {
}
}

/**
* @param GenericEvent $event
*/
public function userAddedToGroup(GenericEvent $event): void {
/** @var IGroup $group */
$group = $event->getSubject();
/** @var IUser $user */
$user = $event->getArgument('user');

$offset = 0;
while (true) {
$shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, 50, $offset);
if (empty($shares)) {
break;
}

foreach ($shares as $share) {
if ($share->getSharedWith() !== $group->getGID()) {
continue;
}

if ($user->getUID() === $share->getShareOwner() ||
$user->getUID() === $share->getSharedBy()) {
continue;
}

$notification = $this->instantiateNotification($share);
$notification->setSubject('incoming_group_share')
->setUser($user->getUID());
$this->notificationManager->notify($notification);
}
$offset += 50;
}
}

/**
* @param IShare $share
* @return INotification
Expand Down