Skip to content

Commit

Permalink
Mark signup notifications as read when visiting the user page
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich committed Jan 7, 2025
1 parent 07d0603 commit 462def5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Controller/User/UserFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions src/Repository/NotificationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 462def5

Please sign in to comment.