Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark signup notification as read automatically #1354

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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();
}
}
Loading