From 462def53c50c84b09bad355e8459c16aa1741d81 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Tue, 7 Jan 2025 12:35:06 +0100 Subject: [PATCH] Mark signup notifications as read when visiting the user page --- src/Controller/User/UserFrontController.php | 11 +++++++++-- src/Repository/NotificationRepository.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Controller/User/UserFrontController.php b/src/Controller/User/UserFrontController.php index ab2783007..17cbe7c4c 100644 --- a/src/Controller/User/UserFrontController.php +++ b/src/Controller/User/UserFrontController.php @@ -16,6 +16,7 @@ use App\Repository\EntryCommentRepository; use App\Repository\EntryRepository; use App\Repository\MagazineRepository; +use App\Repository\NotificationRepository; use App\Repository\PostCommentRepository; use App\Repository\PostRepository; use App\Repository\SearchRepository; @@ -27,8 +28,10 @@ class UserFrontController extends AbstractController { - public function __construct(private readonly SubjectOverviewManager $overviewManager) - { + public function __construct( + private readonly SubjectOverviewManager $overviewManager, + private readonly NotificationRepository $notificationRepository, + ) { } public function front(User $user, Request $request, UserRepository $repository): Response @@ -49,6 +52,10 @@ public function front(User $user, Request $request, UserRepository $repository): throw $this->createNotFoundException(); } + if ($loggedInUser = $this->getUser()) { + $this->notificationRepository->markUserSignupNotificationsAsRead($loggedInUser, $user); + } + $activity = $repository->findPublicActivity($this->getPageNb($request), $user, $hideAdult); return $this->render( diff --git a/src/Repository/NotificationRepository.php b/src/Repository/NotificationRepository.php index aa2778856..0b471b2b7 100644 --- a/src/Repository/NotificationRepository.php +++ b/src/Repository/NotificationRepository.php @@ -196,4 +196,17 @@ public function markOwnReportNotificationsAsRead(User $user): void $stmt->bindValue('uId', $user->getId()); $stmt->executeQuery(); } + + public function markUserSignupNotificationsAsRead(User $user, User $signedUpUser): void + { + $conn = $this->getEntityManager()->getConnection(); + $sql = 'UPDATE notification n SET status = :s + WHERE n.user_id = :uId + AND n.new_user_id = :newUserId'; + $stmt = $conn->prepare($sql); + $stmt->bindValue('s', Notification::STATUS_READ); + $stmt->bindValue('uId', $user->getId()); + $stmt->bindValue('newUserId', $signedUpUser->getId()); + $stmt->executeQuery(); + } }