diff options
author | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-03-27 17:18:56 +0300 |
---|---|---|
committer | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-03-27 17:48:50 +0300 |
commit | d3ba33b644b5d098090ad2d9cd48ad1a28878ba2 (patch) | |
tree | f5bb4b3465d9379a788e330d43bdd816c140bcf8 /lib | |
parent | 25688c584d7c0ec73411e80a6e8ed7c3ee053bc3 (diff) |
Move ShareController::sendInvitation() logic to ShareService
Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ShareController.php | 24 | ||||
-rw-r--r-- | lib/Service/ShareService.php | 27 |
2 files changed, 29 insertions, 22 deletions
diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php index 684f9a33..18624f71 100644 --- a/lib/Controller/ShareController.php +++ b/lib/Controller/ShareController.php @@ -32,7 +32,6 @@ use OCP\AppFramework\Http\DataResponse; use OCA\Polls\Db\Share; use OCA\Polls\Service\MailService; -use OCA\Polls\Service\NotificationService; use OCA\Polls\Service\ShareService; use OCA\Polls\Service\SystemService; use OCA\Polls\Model\User; @@ -51,22 +50,17 @@ class ShareController extends Controller { /** @var SystemService */ private $systemService; - /** @var NotificationService */ - private $notificationService; - public function __construct( string $appName, IRequest $request, MailService $mailService, ShareService $shareService, - SystemService $systemService, - NotificationService $notificationService + SystemService $systemService ) { parent::__construct($appName, $request); $this->mailService = $mailService; $this->shareService = $shareService; $this->systemService = $systemService; - $this->notificationService = $notificationService; } /** @@ -144,21 +138,9 @@ class ShareController extends Controller { */ public function sendInvitation($token): DataResponse { return $this->response(function () use ($token) { - $share = $this->shareService->get($token); - if ($share->getType() === Share::TYPE_USER) { - $this->notificationService->sendInvitation($share->getPollId(), $share->getUserId()); - // TODO: skip this atm, to send invitations as mail too, if user is a site user - // $sentResult = ['sentMails' => [new User($share->getuserId())]]; - // $this->shareService->setInvitationSent($token); - } elseif ($share->getType() === Share::TYPE_GROUP) { - foreach ($share->getMembers() as $member) { - $this->notificationService->sendInvitation($share->getPollId(), $member->getId()); - } - } - $sentResult = $this->mailService->sendInvitation($token); return [ - 'share' => $share, - 'sentResult' => $sentResult + 'share' => $this->shareService->get($token), + 'sentResult' => $this->shareService->sendInvitation($token), ]; }); } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index c1cf37f6..4d576687 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -67,6 +67,9 @@ class ShareService { /** @var Acl */ private $acl; + /** @var NotificationService */ + private $notificationService; + public function __construct( string $AppName, LoggerInterface $logger, @@ -76,7 +79,8 @@ class ShareService { ShareMapper $shareMapper, Share $share, MailService $mailService, - Acl $acl + Acl $acl, + NotificationService $notificationService ) { $this->appName = $AppName; $this->logger = $logger; @@ -87,6 +91,7 @@ class ShareService { $this->share = $share; $this->mailService = $mailService; $this->acl = $acl; + $this->notificationService = $notificationService; } /** @@ -347,4 +352,24 @@ class ShareService { } return $token; } + + /** + * Sent invitation mails for a share + * Additionally send notification via notifications + */ + public function sendInvitation(string $token): array { + $share = $this->get($token); + if ($share->getType() === Share::TYPE_USER) { + $this->notificationService->sendInvitation($share->getPollId(), $share->getUserId()); + // TODO: skip this atm, to send invitations as mail too, if user is a site user + // $sentResult = ['sentMails' => [new User($share->getuserId())]]; + // $this->shareService->setInvitationSent($token); + } elseif ($share->getType() === Share::TYPE_GROUP) { + foreach ($share->getMembers() as $member) { + $this->notificationService->sendInvitation($share->getPollId(), $member->getId()); + } + } + + return $this->mailService->sendInvitation($token); + } } |