From 7cecde2c77c4d12519b262fa7a5c9deeca52e467 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 26 Jul 2024 18:35:17 +0200 Subject: [PATCH] feat: dismiss notification when accepting an invitation Signed-off-by: Daniel Kesselberg --- lib/AppInfo/Application.php | 1 + lib/Listeners/Notifications/RequestingMember.php | 6 +++++- lib/Service/NotificationService.php | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 74d34c97a..e33147dcc 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -129,6 +129,7 @@ public function register(IRegistrationContext $context): void { $context->registerEventListener(LoadAdditionalScriptsEvent::class, ListenerFilesLoadScripts::class); $context->registerEventListener(PreparingCircleMemberEvent::class, ListenerFilesPreparingMemberSendMail::class); $context->registerEventListener(AddingCircleMemberEvent::class, ListenerFilesAddingMemberSendMail::class); + $context->registerEventListener(AddingCircleMemberEvent::class, ListenerNotificationsRequestingMember::class); $context->registerEventListener(CircleMemberAddedEvent::class, ListenerFilesMemberAddedSendMail::class); $context->registerEventListener(PreparingFileShareEvent::class, ListenerFilesPreparingShareSendMail::class); $context->registerEventListener(CreatingFileShareEvent::class, ListenerFilesCreatingShareSendMail::class); diff --git a/lib/Listeners/Notifications/RequestingMember.php b/lib/Listeners/Notifications/RequestingMember.php index cb654e313..6cd1ec03d 100644 --- a/lib/Listeners/Notifications/RequestingMember.php +++ b/lib/Listeners/Notifications/RequestingMember.php @@ -28,8 +28,10 @@ namespace OCA\Circles\Listeners\Notifications; +use OCA\Circles\Events\AddingCircleMemberEvent; use OCA\Circles\Events\CircleGenericEvent; use OCA\Circles\Events\RequestingCircleMemberEvent; +use OCA\Circles\Model\Circle; use OCA\Circles\Service\NotificationService; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -42,13 +44,15 @@ public function __construct( } public function handle(Event $event): void { - if (!$event instanceof RequestingCircleMemberEvent) { + if (!$event instanceof RequestingCircleMemberEvent && !$event instanceof AddingCircleMemberEvent) { return; } $member = $event->getMember(); if ($event->getType() === CircleGenericEvent::REQUESTED) { $this->notificationService->notificationRequested($member); + } elseif ($event->getType() === CircleGenericEvent::JOINED && $event->getCircle()->isConfig(Circle::CFG_INVITE)) { + $this->notificationService->markInvitationAsProcessed($member); } else { $this->notificationService->notificationInvited($member); } diff --git a/lib/Service/NotificationService.php b/lib/Service/NotificationService.php index a9342311f..ef0551a5e 100644 --- a/lib/Service/NotificationService.php +++ b/lib/Service/NotificationService.php @@ -228,4 +228,18 @@ private function linkToOCS(string $route, array $params = []): string { return parse_url($absolute, PHP_URL_PATH); } + + public function markInvitationAsProcessed(Member $member): void { + if ($member->getUserType() !== Member::TYPE_USER || !$member->isLocal()) { + return; + } + + $notification = $this->notificationManager->createNotification(); + $notification->setApp('circles') + ->setUser($member->getUserId()) + ->setObject('member', $member->getId()) + ->setSubject('invitation'); + + $this->notificationManager->markProcessed($notification); + } }